Pages

Tuesday, September 27, 2011

Base64 encoding in Oracle BPEL 11g

Sometimes in SOA Suite 11g you need to pass binary data to a web service reference. In SOA Suite 11g there is no standard XSLT or XPATH function which you can use. But in BEPL you can use embedded java, like Sudheer already blogged about. He used the com.collaxa.common.util.Base64Encoder class which does not exists in 11g so I will use the new oracle.soa.common.util.Base64Encoder class.

As input I will retrieve some xml from the inputVariable, get the xml as a string, encode this and set the value to a base64Binary variable.

16 comments:

  1. Would a custom XPath function also be possible? In this case you can implement it at one place and use it everywhere !

    ReplyDelete
  2. Hi,

    That should be possible only you need to find out what the input is like a string , xml or binary.

    and need to deploy it on the soa server and to every developer pc. Sometimes this is too much

    thanks

    ReplyDelete
  3. Thank you for this useful post. What other imports are required besides oracle.soa.common.util.Base64Encoder class. I get failure in compile execlets of bpel process.

    ReplyDelete
  4. Hi,

    I use the full path and don't use imports.

    You can check my code for all the classes.

    thanks

    ReplyDelete
    Replies
    1. I tried similar code which you used but no luck. I am using Jdev 11.1.1.6.

      I am getting below error. Could you please throw some light on it.

      Error deploying archive sca_SOA-BENMessageProcessor_rev1.0.jar to partition "default" on server AdminServer [http://VWI1LA01:10005]
      [02:02:56 PM] HTTP error code returned [500]
      [02:02:56 PM] Error message from server:
      There was an error deploying the composite on AdminServer: Error occurred during deployment of component: BENMessageProcessor to service engine: implementation.bpel, for composite: SOA-BENMessageProcessor: ORABPEL-05250

      Error deploying BPEL suitcase.
      error while attempting to deploy the BPEL component file "E:\Oracle\Middleware\user_projects\domains\soadomain\servers\AdminServer\dc\soa_89e88ee7-ff81-44e8-b8e5-64ac1a91b973"; the exception reported is: java.lang.RuntimeException: failed to compile execlets of BENMessageProcessor

      This error contained an exception thrown by the underlying deployment module.
      Verify the exception trace in the log (with logging level set to debug mode).
      .

      [02:02:56 PM] Check server log for more details.
      [02:02:56 PM] Error deploying archive sca_SOA-BENMessageProcessor_rev1.0.jar to partition "default" on server AdminServer [http://VWI1LA01:10005]
      [02:02:56 PM] #### Deployment incomplete. ####
      [02:02:56 PM] Error deploying archive file:/C:/JDeveloper/SOA-BENMessageProcessor/SOA-BENMessageProcessor/deploy/sca_SOA-BENMessageProcessor_rev1.0.jar
      (oracle.tip.tools.ide.fabric.deploy.common.SOARemoteDeployer)

      Delete
  5. Right, it works now. Thank you for your suggestion.

    ReplyDelete
  6. Hello Edwin,

    nice article which help me to decode base64 in Oracle BPEL. At the moment I have problem to access the right Part of Variable. It seems that the XPath is not relevant. I got no more information in Oracle Support Web, may be you have an idea:
    getVariableData("inputVariable", "payload", "//ns1:document/ns1:Metadata");

    System print output:


    ?
    ?
    ?
    ?
    ?
    ?
    ?
    ?
    ?


    ?
    ?

    Thanks
    Marcel

    ReplyDelete
  7. Hello Edwin,

    it's me once again. I do some research and an output via convertDomNodeToString and the result shows that getVariableData works fine.
    The problem is the getDocument function. It seems that this get the whole variable data. I hope to find a solution.

    Thanks
    Marcel

    ReplyDelete
  8. Hi,

    Can you test getVariableData in bpel first, there must somewhere a mistake.

    thanks

    ReplyDelete
  9. Hi Edwin,

    getVariableData seems to work fine. I print out the data with convertDomNodeToString and it looks good. After "getDocument" the variable contains the whole variable data.

    Regards
    Marcel

    ReplyDelete
  10. String System_base64string = ((oracle.xml.parser.v2.XMLElement)getVariableData("InvokeSyncReadFile_SynchRead_OutputVariable","opaque","/ns3:opaqueElement")).getFirstChild().getNodeValue();

    This is returning XML document from First node. But my requirement is to extract the
    XML document from second child element.

    For Ex:





    Then I need output from tag.
    Please help me on this.

    ReplyDelete
  11. Are there plans to put the SOA component into JDeveloper 11.1.2?

    Thanks!

    ReplyDelete
    Replies
    1. hi,

      No. you need to wait at least a year for 12c , 11gR2 is an ADF patch release which stills run on wls 10.3.5. Oracle uses this to test JSF2.0.

      thanks

      Delete
  12. Hi Edwin Biemond,

    When I try to decode with following code snippet:








    I am getting class cast exception.

    ReplyDelete
    Replies
    1. Hi

      Can you escape your xml code, so I can see what your are doing.

      thanks

      Delete
  13. In 11g, one needs to use oracle.soa.common.util.Base64Encoder instead of com.collaxa.common.util.Base64Encoder, and similarly Base64Decoder.

    Make sure you import the required classes before using in BPEL.
    e.g.


    ReplyDelete