« Interesting XSLT Recipe - Computing line totals | Main | An attempt on 8 Queens Problem »

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.


  1. Create a new BPEL empty process project.
  2. Open up the New Gallery and choose to create a new EJB session bean.



  3. Choose the option for creating EJB 2.1 session bean. Give the Bean the name"HelloWorld", accept the remaining defaults and finish the wizard.
  4. 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



  5. 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".




    1. <?xml version = '1.0' encoding = 'windows-1252'?>  
    2. <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    3.   xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd"  
    4.     schema-major-version="10" schema-minor-version="0">  
    5.     <enterprise-beans>  
    6.         <session-deployment name="HelloWorld" location="ejb/session/HelloWorld"/>  
    7.     </enterprise-beans>  
    8. </orion-ejb-jar>

  6. Your bean is now ready for deployment. Build the project and deploy to an OC4J container.

Step 2: Build the BPEL Process




  1. Create a new BPEL Process project.
  2. Create a new WSDL document in the project directory and name it HelloWorldEJB.wsdl.
  3. 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.






      1. <?xml version="1.0" ?>  
      2. <definitions targetNamespace="http://samples.otn.com/"  
      3.              xmlns:tns="http://samples.otn.com/"  
      4.              xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
      5.              xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/"  
      6.              xmlns:ejb="http://schemas.xmlsoap.org/wsdl/ejb/"  
      7.              xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"  
      8.              xmlns="http://schemas.xmlsoap.org/wsdl/">  
      9.   <!-- message declns -->  
      10.   <message name="HelloWorldRequestMessage">  
      11.     <part name="userName" type="xsd:string"/>  
      12.   </message>  
      13.   <message name="HelloWorldResponseMessage">  
      14.     <part name="message" type="xsd:string"/>  
      15.   </message>  
      16.   <!-- port type declns -->  
      17.   <portType name="HelloWorldPT">  
      18.     <operation name="greetUser">  
      19.       <input name="HelloWorldRequest" message="tns:HelloWorldRequestMessage"/>  
      20.       <output name="HelloWorldResponse"  
      21.               message="tns:HelloWorldResponseMessage"/>  
      22.     </operation>  
      23.   </portType>  
      24.   <!-- binding declns -->  
      25.   <binding name="EJBBinding" type="tns:HelloWorldPT">  
      26.     <ejb:binding/>  
      27.     <format:typeMapping encoding="Java" style="Java">  
      28.       <format:typeMap typeName="xsd:string" formatType="java.lang.String"/>  
      29.     </format:typeMapping>  
      30.     <operation name="greetUser">  
      31.       <ejb:operation methodName="greetUser" parameterOrder="userName"  
      32.                      interface="remote" returnPart="message"/>  
      33.       <input name="HelloWorldRequest"/>  
      34.       <output name="HelloWorldResponse"/>  
      35.     </operation>  
      36.   </binding>  
      37.   
      38.   <!-- service decln -->  
      39.   <service name="HelloWorldService">  
      40.     <port name="EJBPort" binding="tns:EJBBinding">  
      41.       <!-- Put vendor-specific deployment information here -->  
      42.       <ejb:address className="helloworldbean.HelloWorldHome"  
      43.            jndiName="ejb/session/HelloWorld"  
      44.            initialContextFactory="com.evermind.server.rmi.RMIInitialContextFactory"  
      45.    jndiProviderURL="opmn:ormi://serverHost:opmnRequestPort:oc4jInstanceName/ejbName"/>  
      46.     </port>  
      47.   </service>  
      48.   
      49.   <plnk:partnerLinkType name="HelloWorldService">  
      50.     <plnk:role name="HelloWorldServiceProvider">  
      51.       <plnk:portType name="tns:HelloWorldPT"/>  
      52.     </plnk:role>  
      53.   </plnk:partnerLinkType>  
      54. </definitions>  
      55.       

    1. Create a partnerlink for the WSDL that you just created and an invoke activity that can be used to invoke the plnk.
    2. 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.




      1.   
      2. <?xml version = '1.0' encoding = 'UTF-8'?>  
      3. <BPELSuitcase>  
      4.    <BPELProcess id="HelloWorldBPELClient" src="HelloWorldBPELClient.bpel">  
      5.       <partnerLinkBindings>  
      6.          <partnerLinkBinding name="client">  
      7.             <property name="wsdlLocation">HelloWorldBPELClient.wsdl</property>  
      8.          </partnerLinkBinding>  
      9.          <partnerLinkBinding name="HelloWorld_plt">  
      10.             <property name="wsdlLocation">HelloWorldEJB.wsdl</property>  
      11.             <property name="java.naming.security.principal">oc4jadmin</property>  
      12.             <property name="java.naming.security.credentials">welcome1</property>  
      13.          </partnerLinkBinding>  
      14.       </partnerLinkBindings>  
      15.    </BPELProcess>
      16. </BPELSuitcase>

    3. 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.
    4. Deploy the BPEL Process and see the results for yourself

    The demo EJB and BPEL Client project can be downloaded from this link.

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mte1521/mt-tb.cgi/2637

Comments (3)

Great job but screenshots seem to be screwed a bit.

Did you try the same for Oracle ESB as well.

Ronen:

If you choose EJB 3.0 and not 2.1, you don't have to edit the WSDL manually. You simply add a WSIF annotation to the service interface... It works pretty well.

Ramkumar Menon:

thanks for the comment Ronen.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on May 16, 2008 3:30 PM.

The previous post in this blog was Interesting XSLT Recipe - Computing line totals.

The next post in this blog is An attempt on 8 Queens Problem.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle