Saturday, December 10, 2011

Base64 Encoding/Decoding in Oracle BPEL 11g


Base64 Encoding/Decoding in Oracle BPEL 11g:

Sometimes we may need to send the binary data to the reference services or decode the binary data received from the services in BPEL. The Java Embedding activity can be used to Encode/Decode the binary data.

Encoding the XML data:

The below Java Embedding Code snippet will retrieve the XML data and encode the same to the binary format and assign the encoded data to the BPEL variable.


oracle.xml.parser.v2.XMLElement inputPayload = (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:process");
oracle.xml.parser.v2.XMLDocument xmlPayload = inputPayload.getDocument();
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
try {
xmlPayload.print(outputStream );
java.lang.String xml_output = outputStream.toString();
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
java.lang.String encodedString = null;
encodedString = encoder.encode(xml_output);
setVariableData("base64EncodedString",encodedString);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}

Decoding the Binary Data:

The below Java Embedding Code snippet will retrieve the binary data and decode the same to the XML format and assign the decoded data to the BPEL variable.


String input = (String)getVariableData("base64EncodedString");Base64Decoder Decoder = new Base64Decoder();
try
{
String decodedString = Base64Decoder.decode(input);
setVariableData("decodedString",decodedString );
}
catch(Exception e)
{
e.printStackTrace();
}

Before deploying the Composites, make sure the oracle.soa.common.util.Base64Decoder/ oracle.soa.common.util.Base64Encoder classes has been imported in the bpel file.



O/P


DOWNLOAD SAMPLE


1 comment: