X

Invoking an EJB Session Bean from a BPEL Process

Ramkumar Menon
Director, Product Strategy

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.

Join the discussion

Comments ( 7 )
  • Rakesh Friday, May 16, 2008
    Great job but screenshots seem to be screwed a bit.
    Did you try the same for Oracle ESB as well.
  • Ronen Saturday, May 17, 2008
    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 Saturday, May 17, 2008
    thanks for the comment Ronen.
  • guest Friday, November 21, 2008
    What If both BPEL Process and EJB are deployed on different server ?
  • Stanley Monday, February 2, 2009
    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.
  • Pratyush Wednesday, July 8, 2009
    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.
  • Fort Worth Mortgage Tuesday, April 26, 2011
    I agree with your details , great post.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha