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.
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.
To add the code for the third-party library from the Java Embedding activity, we perform the following steps:
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"/>
The Java code is embedded in the XML form of the BPEL process. The same code gets deployed to the 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.