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

    <?xml version = '1.0' encoding = 'windows-1252'?> 


    <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd"
        schema-major-version="10" schema-minor-version="0"> 
        <enterprise-beans> 
            <session-deployment name="HelloWorld" location="ejb/session/HelloWorld"/> 
        </enterprise-beans> 
    </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.

      <?xml version="1.0" ?>  
      <definitions targetNamespace="http://samples.otn.com/"
                   xmlns:tns="http://samples.otn.com/"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/"
                   xmlns:ejb="http://schemas.xmlsoap.org/wsdl/ejb/"
                   xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
                   xmlns="http://schemas.xmlsoap.org/wsdl/">  
        <!-- message declns -->  
        <message name="HelloWorldRequestMessage">  
          <part name="userName" type="xsd:string"/>  
        </message>  
        <message name="HelloWorldResponseMessage">  
          <part name="message" type="xsd:string"/>  
        </message>  
        <!-- port type declns -->  
        <portType name="HelloWorldPT">  
          <operation name="greetUser">  
            <input name="HelloWorldRequest" message="tns:HelloWorldRequestMessage"/>  
            <output name="HelloWorldResponse"  
                    message="tns:HelloWorldResponseMessage"/>  
          </operation>  
        </portType>  
        <!-- binding declns -->  
        <binding name="EJBBinding" type="tns:HelloWorldPT">  
          <ejb:binding/>  
          <format:typeMapping encoding="Java" style="Java">  
            <format:typeMap typeName="xsd:string" formatType="java.lang.String"/>  
          </format:typeMapping>  
          <operation name="greetUser">  
            <ejb:operation methodName="greetUser" parameterOrder="userName"  
                           interface="remote" returnPart="message"/>  
            <input name="HelloWorldRequest"/>  
            <output name="HelloWorldResponse"/>  
          </operation>  
        </binding>  
        <!-- service decln -->  
        <service name="HelloWorldService">  
          <port name="EJBPort" binding="tns:EJBBinding">  
            <!-- Put vendor-specific deployment information here -->  
            <ejb:address className="helloworldbean.HelloWorldHome"  
                 jndiName="ejb/session/HelloWorld"  
                 initialContextFactory="com.evermind.server.rmi.RMIInitialContextFactory"  
         jndiProviderURL="opmn:ormi://serverHost:opmnRequestPort:oc4jInstanceName/ejbName"/>  
          </port>  
        </service>  
        <plnk:partnerLinkType name="HelloWorldService">  
          <plnk:role name="HelloWorldServiceProvider">  
            <plnk:portType name="tns:HelloWorldPT"/>  
          </plnk:role>  
        </plnk:partnerLinkType>  
      </definitions>  

    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.


    <?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>

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

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

Comments:

Great job but screenshots seem to be screwed a bit. Did you try the same for Oracle ESB as well.

Posted by Rakesh on May 16, 2008 at 12:09 PM PDT #

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.

Posted by Ronen on May 17, 2008 at 06:58 AM PDT #

thanks for the comment Ronen.

Posted by Ramkumar Menon on May 17, 2008 at 09:59 AM PDT #

What If both BPEL Process and EJB are deployed on different server ?

Posted by guest on November 21, 2008 at 03:20 AM PST #

Hi Menon, I am having a java class where i used PrintWriter object to write into a file.Its working fine(it creates a file and writes into that) But, the same jave class i loaded into oracle and i have given the server output path for the creating the file its not working. Can anyone reply me asap.

Posted by Stanley on February 01, 2009 at 08:53 PM PST #

Hi Menon, I tried this approach but I am getting error Failed to lookup EJB home using JNDI name 'ejb/session/HelloWorld'; nested exception is: java.lang.NullPointerException. Do we need to set jndi somewhere else also other mentioned in this tutorial.

Posted by Pratyush on July 07, 2009 at 09:16 PM PDT #

I agree with your details , great post.

Posted by Fort Worth Mortgage on April 26, 2011 at 10:59 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Principal Product Manager

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today