Tuesday, June 02, 2009

Base64 enconding

Updated for SOA 11g

Within the SOA suite you can handle binary data. Sometime you need this data passed through the system for notification. For example sending the data as an attachment via mail.

Within BPEL you can call the notification system and create your attachments. But before that this binary data should be decoded to an ascii format of the mail server can handle this.

The data needs to be Base 64 encoded. There are no default BPEL functions to decode or encode data. We can solve this by creating our own embedded Java function in the BPEL process.

This java function will pickup XML data and encode this into Base64 format. The Java code to to this is here:

New 11g:
String base64 = ((oracle.xml.parser.v2.XMLElement)getVariableData("declaratieBase64Binary ")).getFirstChild().getNodeValue();
String decodedData = oracle.soa.common.util.Base64Decoder.decode(base64);
Old 10g:
<bpelx:exec name="Java_EncodeStringtoBase64" language="java" version="1.5">
<![CDATA[
String input = (String)getVariableData("resultString");    
String encoded;
try    
{   
  addAuditTrailEntry("BPEL Inline JAVA/INPUT: \n" + input);
  com.collaxa.common.util.Base64Encoder Encoder = new  com.collaxa.common.util.Base64Encoder();
  encoded = Encoder.encode(input);
  addAuditTrailEntry("BPEL Inline JAVA/INPUT: \n" + encoded);
  setVariableData("resultString64", encoded);    
}    
catch(Exception e)   
{   
e.printStackTrace();    
}]]>
</bpelx:exec>
In this example two BPEL variables are used.
  • resultString - type string, contains the input string
  • resultString64 - type string, contains the encode Base64 string

Post a Comment