Friday, August 27, 2010

Dealing with Opaque messages in 11g BPEL - Part1

This article is dedicated to the dealing of opaque payloads in Oracle SOA Suite 11g.

In some of the real world scenarios where the message format is not predictable from a resource adapter we have to go for Opaque Schema definition . In the BPEL 10g implementation we have to use the java class Base64Decoder in a java embedding activity to decode the opaque payloads , in 11g eventhough the implementation is same , the class that we have to import for this purpose differs from that of 10g.

In 10g we have to import the class com.collaxa.common.util.Base64Decoder to decode a given Opaque message in Base64 format . However in 11g SOA Suite , we have to go for the class oracle.soa.common.util.Base64Decoder to acheive the desired functionality . Same is the case with the class Base64Encoder.

Here is the snippet of the jave embedding code used in our 11g BPEL project..

<bpelx:exec import="java.util.*"/>
<bpelx:exec import="java.lang.*"/>
<bpelx:exec import="java.math.*"/>
<bpelx:exec import="java.io.*"/>
<bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
<bpelx:exec name="DecodeBase64InputToString" language="java" version="1.5">
<![CDATA[
                     try
                        {
                        String input = ((oracle.xml.parser.v2.XMLElement)getVariableData("RcvInput_Read_InputVariable","opaque","/ns2:opaqueElement")).getFirstChild().getNodeValue();
                        Base64Decoder Decoder = new Base64Decoder();
                        String decodedMessage = Base64Decoder.decode(input).replaceAll("&", "&amp;");
                        setVariableData("decodedInputVariable",decodedMessage);                        
                        }
                     catch(Exception e)
                       {
                          e.printStackTrace();
                        }
                         ]]>

</bpelx:exec>
 
where RcvInput_Read_InputVariable is the BPEL variable holding the Opaque message and decodedInputVariable is the BPEL Variable which contains the final decoded string .

In the second part of this post , I will explain you the way the decoded string is used in XML transformations.

Hope this post would be of some help to you.
 
Have a nice day...

2 comments:

  1. Hi Surya,

    Nice post.But what I want to know here is that, I'm taking the encoded payload from XML_DOCUMENT and using the decode function to decode it but I'm getting some special characters.So, Can you please tell me how can I convert it into valid xml format.

    Thanks
    -Ashwini

    ReplyDelete