« May 7, 2008 | Main | June 30, 2008 »

May 16, 2008 Archives

May 16, 2008

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.

About May 2008

This page contains all entries posted to Ramkumar Menon's Blog in May 2008. They are listed from oldest to newest.

May 7, 2008 is the previous archive.

June 30, 2008 is the next archive.

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

Powered by
Movable Type and Oracle