Thursday, July 4, 2013

Base64 Binary Encoding and Decoding - BPEL 11G

Hi Guys,

Sometimes there are requirements where we receives request from consumer in opaque/binary format or we may have to interact with applications using binary format.To facilitate this requirement Java embedding activity is used in BPEL.I will be demonstrating how to convert string to binary format and vice verse.

For this use case I have already created a BPEL process that will receive string in string format.In the BPEL code I have added 2 java embedding activities one for encoding and one for decoding the data.

Firstly, I will encode the payload received in binary format using below code:

addAuditTrailEntry("Encoding started");     
try {     
oracle.xml.parser.v2.XMLElement input = (oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input");     
java.lang.String input_str = input.getTextContent();     
addAuditTrailEntry("Input String = "+input_str);     
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();         
java.lang.String encoded = null;        
encoded = encoder.encode(input_str);     
addAuditTrailEntry("encoded string = "+encoded);     
} catch (Exception e) {     
  addAuditTrailEntry("Exception: "+e.getMessage());     
addAuditTrailEntry("Encoded ended");

Pass the input variable name in the input string and create one more variable of 64binary format that will store the encoded string.
Now, we will decode the string that we encoded in previous step using below code:

 addAuditTrailEntry("decoding started");
String encodedString = (String)getVariableData("InputVar");
Base64Decoder Decoder = new Base64Decoder();
addAuditTrailEntry("encoded String = "+encodedString);
String decoded = Base64Decoder.decode(encodedString);
addAuditTrailEntry("decoded string = "+decoded);  
catch(Exception e)
  addAuditTrailEntry("Exception: "+e.getMessage());

Create one more variable of string type that will contain the decoded string.In this case we will pass the variable we created in previous step as input.Decoded string will be stored in variable we created for storing decoded string.
Now, we will test our composite to verify the changes we have made.String passed is encoded using 1st java embedding activity and decoded using second java embedding java activity.
Make sure you imported below mentioned classes in your BPEL source:

    <bpelx:exec import="oracle.soa.common.util.Base64Encoder"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>

Otherwise your compilation will fail.
In this way you can achieve encoding and decoding functionality in BPEL.Hope this post is useful to you.

Happy Learning,
Cheers !!!


  1. Hi,
    I'm using the Encoding code but i'm getting SCAC-50012 error every time i rebuild the project

  2. This comment has been removed by the author.

  3. have u added oracle.soa.common.util.Base64Encoder in your BPEL source file

  4. hi,
    After decoding the encoded data, we are parsing it to an XML Structure. But after doing so the value for each of the child elements is coming Empty. Would you happen to know a reason for this behavior.