Invoking an EJB Session Bean from a BPEL Process
EJB session beans can be invoked from a BPEL process through WSIF. Oracle BPEL PM ships with a WSIF provider for invoking EJBs.
For demonstrating this, lets create a new EJB session bean. The session bean shall have one single business method namely "greetUser" that takes in a string argument userName, and returns a string value "Hello <USERNAME>".
Step 1: Creating the HelloWorld Session Bean.
- Create a new BPEL empty process project.
- Open up the New Gallery and choose to create a new EJB session bean.
- Choose the option for creating EJB 2.1 session bean. Give the Bean the name"HelloWorld", accept the remaining defaults and finish the wizard.
- Double click on the EJB in the Applications Navigator to bring up the EJB Module Editor". Specify the new business method in the "Methods" tab. Type in the parameter name and type manually in the text editor
- CLick ok to accept the changes. Click on the "orion-ejb-jar.xml" in the Applications Navigator. Here you need to provide the JNDI locaiton of the session bean. For this, add a "location" attribute on the <SESSION-DEPLOYMENT>to provide the JNDI "ejb/session/HelloWorld".
- Your bean is now ready for deployment. Build the project and deploy to an OC4J container.
Step 2: Build the BPEL Process
- Create a new BPEL Process project.
- Create a new WSDL document in the project directory and name it HelloWorldEJB.wsdl.
- Add the bindings section that allow the process to invoke the EJB through WSIF. The salient portion of the bindings section is the jndiProviderURL. For an Application Server install, use the opmn ormi jndi provider URL. For standalone installations,use plain ormi provider URLs. The ejbName in the provider URL is the ejbName value in the ejb-jar.xml that was created as a part of the EJB session bean creation.
- Create a partnerlink for the WSDL that you just created and an invoke activity that can be used to invoke the plnk.
- Provide the username/password for connecting to the OC4J Instance that hosts the EJB within the bpel.xml deployment descriptor. This is typically the oc4jadmin user.
<?xml version = '1.0' encoding = 'UTF-8'?>
<BPELSuitcase>
<BPELProcess id="HelloWorldBPELClient" src="HelloWorldBPELClient.bpel">
<partnerLinkBindings>
<partnerLinkBinding name="client">
<property name="wsdlLocation">HelloWorldBPELClient.wsdl</property>
</partnerLinkBinding>
<partnerLinkBinding name="HelloWorld_plt">
<property name="wsdlLocation">HelloWorldEJB.wsdl</property>
<property name="java.naming.security.principal">oc4jadmin</property>
<property name="java.naming.security.credentials">welcome1</property>
</partnerLinkBinding>
</partnerLinkBindings>
</BPELProcess>
</BPELSuitcase>- Copy the EJB compiled classes from the EJB project created earlier into the $ORACLE_HOME/bpel/system/classes directory and restart the BPEL runtime. These classes are required for BPEL to get a hold on the home interface of the EJB to create an invoke the business method.
- Deploy the BPEL Process and see the results for yourself
The demo EJB and BPEL Client project can be downloaded from this link.