Invoking third-party libraries from BPEL 2.0 process

This recipe explains how to use third-party libraries from a BPEL 2.0 process. We achieve this by using the Java Embedding activity in the BPEL editor. In general, putting a lot of business processing code into the BPEL process does not represent a good practice. Rather, the third-party libraries should be implemented through web services or EJBs. Those web services and EJBs can then be referenced from the BPEL process.

Getting ready

We will amend the JDeveloper project from the Adding third-party libraries to JDeveloper projects recipe. We create an empty BPEL 2.0 process and leave the request and response messages unchanged.

How to do it…

To add the code for the third-party library from the Java Embedding activity, we perform the following steps:

  1. Open the BPEL process in JDeveloper. To execute the third-party library class, select the Java Embedding activity from the Oracle Extensions section of Component Palette as shown in the following screenshot:
    How to do it…
  2. When you double-click on the Java Embedding activity, a new dialog opens where we have to enter the code. We finish configuring the Java Embedding activity by clicking on the OK button as shown in the following screenshot:
    How to do it…
  3. One additional step we need to perform is to import the org.apache.commons.codec.digest.DigestUtils class (contained in the third-party library) in the BPEL process. We do this by switching to the Source view. Immediately after the <process> tag, add the import statement for the class used in the Java code as follows:
      <import location="org.apache.commons.codec.digest.DigestUtils" importType="http://schemas.oracle.com/bpel/extension/java"/>
      <import location="oracle.xml.parser.v2.XMLElement" importType="http://schemas.oracle.com/bpel/extension/java"/>

How it works…

The Java code is embedded in the XML form of the BPEL process. The same code gets deployed to the Oracle SOA Suite server.

Tip

JDeveloper will not notify us in case there is any error in the code. So, it is advisable to test the deployment of the BPEL process in the integrated SOA server of JDeveloper prior to deploying it to the real Oracle SOA Suite server.

During the preparation of the deployment package, the Java code is packed into a package in a raw format that is not compiled. When the package is deployed onto the Oracle SOA Suite server, all the dependencies (imports) are checked and the code is compiled.

If there is an error in the code, we get an exception in the console similar to the following code:

Error deploying BPEL suitcase.
error while attempting to deploy the BPEL component file "C:ProgramsOracleMiddlewareuser_projectsdomainsSOA_DevserversAdminServerdcsoa_8606ace0-2193-4
719-8cd7-08b2f0d57a04"; the exception reported is: java.lang.RuntimeException: failed to compile execlets of BPELProcess2_0

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).

        at com.collaxa.cube.engine.deployment.DeploymentManager.deployComponent(DeploymentManager.java:200)
        at com.collaxa.cube.ejb.impl.CubeServerManagerBean._deployOrLoadComponent(CubeServerManagerBean.java:874)
        at com.collaxa.cube.ejb.impl.CubeServerManagerBean.deployComponent(CubeServerManagerBean.java:122)
        at com.collaxa.cube.ejb.impl.bpel.BPELServerManagerBean.deployComponent(BPELServerManagerBean.java:87)
        at sun.reflect.GeneratedMethodAccessor4365.invoke(Unknown Source)
        Truncated. see log file for complete stacktrace
>
<7.4.2013 14:24:57 CEST> <Error> <oracle.integration.platform.blocks.deploy.servlet> <SOA-21537> <Sending back error message: There was an error deploying the composite on AdminServer: Error occurred during deployment of component: BPELProcess2_0 to service engine: implementation.bpel, for composite: LibsAndClasses: OR
ABPEL-05250

Error deploying BPEL suitcase.
error while attempting to deploy the BPEL component file "C:ProgramsOracleMiddlewareuser_projectsdomainsSOA_DevserversAdminServerdcsoa_8606ace0-2193-4
719-8cd7-08b2f0d57a04"; the exception reported is: java.lang.RuntimeException: failed to compile execlets of BPELProcess2_0

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).
..>

The following is the code in the BPEL process:

  <extensionActivity>
    <bpelx:exec name="Java_Embedding1" xml:id="id_12" language="java">
      <![CDATA[XMLElement input = (XMLElement) getVariableData( 
        "inputVariable", "payload", "/client:process/client:input");
String name = input.getTextContent();
addAuditTrailEntry("before "+ name);
String hash= DigestUtils.md5Hexa( name );
addAuditTrailEntry("after "+ hash);
setVariableData("outputVariable", "payload", "/client:processResponse/client:result", hash);]]>
    </bpelx:exec>
  </extensionActivity>

In the preceding code, the <bpelx:exec> tag is embedded into the <extensionActivity> tag. We can also spot that addAuditTrail(), getVariableData(), and setVariableData() do not need any imports since they are a part of a standard set in the <bpelx:exec> package.

Note

The code described in this recipe is valid for BPEL 2.0 processes. We will address the <bpelx:exec> tag in BPEL 1.1 processes in the next recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset