Using BPEL and EJBs with WebSphere Process Server and WebSphere Integration Developer

This article examines how Enterprise JavaBeans (EJBs) and Java™ code can act as clients and services in relation to Business Process Execution Language (BPEL) business processes. In this article, you learn how to invoke a BPEL business process from an EJB and how to use a BPEL business process to invoke an EJB.

Mannie Kagan, Consulting I/T Specialist, IBM

Mannie Kagan is a Consulting I/T Specialist with IBM Software Services for WebSphere (ISSW) in Toronto Canada. Mannie provides consulting services, skills transfer, and mentoring focused around SOA, WebSphere middleware, performance management, and security. You can reach Mannie at kagan@ca.ibm.com.



09 August 2006

Introduction

IBM® WebSphere® Process Server for Multiplatforms Version 6.0 (hereafter referred to as WebSphere Process Server), the next generation of business integration software from IBM, is based on service-oriented architecture (SOA) and embraces open standards.

This article uses an end-to-end example to demonstrate how EJBs can act as clients and services in relation to BPEL business processes. You will learn how to invoke a BPEL business process from an EJB using a stand-alone reference, and in turn, how a BPEL business process can invoke an EJB using a W-Type to J-Type bridging component.

The example shows you how to develop code in IBM WebSphere Integration Developer Version 6.0.1 (hereafter referred to as WebSphere Integration Developer). The example consists of two sections:

  • Invoking a business process from a Java session EJB
  • Invoking a stateless session EJB as a service from a BPEL business process

Exploring the temperature converter example

Let's focus on a few concerns before delving into our example. In this example, you need a portlet or other client code to invoke a business process. We can use a Web services interface or an RMI-IIOP via an EJB call to accomplish this. In the EJB case, the question is: how do you go about setting up the incoming EJB call in WebSphere Process Server? Conversely, imagine a business process that needs to call out to an already existing EJB service. One option is to wrap the EJB service in a Web service. Another option is to invoke the EJB directly. Again, a similar question occurs when calling the EJB directly, how does one set up the outgoing EJB invocation?

In this example, a temperature converter converts Fahrenheit to Centigrade. We provide the Project Interchange solution code, thus allowing you to load the solution into a WebSphere Integration Developer environment and refer to aspects of it while reading through the document. For that reason, not all views and steps are shown.

As an aside, the example demonstrates the entire end-to-end operation. It concludes with a test whereby a request is made from the Java client EJB to the business process, which in turn invokes an EJB as a service, and then returns the response all the way back to the client.

The stateless session EJB client invokes the business process using a WebSphere Process Server stand-alone reference. The business process, in turn, invokes the EJB service via a bridging component, see Figure 1 below. Since it is not possible to wire a BPEL component (W-Type) directly to an EJB import (J-Type), you need to provide a bridging component between the two to convert from W-Type to J-Type. The example demonstrates how you can do this.

Figure 1. Temperature Converter Client and Service EJBs
Temperature Converter Client and Service EJBs

Invoking a business process from a Java session EJB

You can use these steps to create a business process and stand-alone reference, and wire the two together.

  1. From the WebSphere Integration Developer, select the Business Integration perspective, create a module called MyBusinessProcess, and then create a business process called MBP inside the module.
  2. Select generate a new interface to generate the interface MBP. Select convert (an operation), input degF, and output degC, both of type float to create the business process, as in Figure 2.
    Figure 2. Assembly Diagram: Select the convert operation (input and output) to create a business process
    Assembly Diagram: Select the convert operation (input and output) to create a business process
  3. In the MBP business process, delete variable Input1, and create two new variables, degC, and degF, both of type float.
    Figure 3. Business Process Editor
    Business Process Editor
  4. Associate the Receive with degF, and Reply with degC, see Figure 4.
    Figure 4. Business Process Editor -- Receive properties
    Business Process Editor -- Receive properties
  5. Add an Assign task between Receive and Reply for test purposes, and assign the variables DegF to DegC, see Figure 5.
    Figure 5. BPEL Editor, adding an Assign Task
    BPEL Editor, adding an Assign Task
  6. Drag the MBP business process to the Assembly Editor.
  7. Right-click on the canvas and choose add node => Stand-alone References.
  8. Wire the stand-alone reference to the MBP Interface.
  9. Respond Yes to the question, "A matching reference will be created on the source node. Do you want to continue?"
  10. Respond Yes to the Reference dialog (see Figure 6).
    Figure 6. Reference dialog
    Reference dialog
  11. Notice that the stand-alone reference name is MBPPartner.

Creating a client EJB to invoke the stand-alone reference

Next, use the steps below to create a client EJB that invokes the stand-alone reference.

  1. From the WebSphere Integration Developer, choose the J2EE perspective. Create an EJB project called ConverterClientEJB and place it in the same Enterprise Application as the stand-alone reference (MyBusinessProcessApp). Do not create an EJB client jar. Create a default stateless session bean.
    Figure 7. New EJB Project Dialog
    New EJB Project Dialog
  2. In the default stateless session bean, add the remote method from Listing 1:
    Listing 1. The remote method
    public float convertFtoC(float f) {
    	ServiceManager serviceManager = new ServiceManager();
    	MBP service = (MBP)serviceManager.locateService("MBPPartner");
    	System.out.println(">>>>>> Calling Business Process convert: f = " + f);
    	Float result = service.convert(new Float(f));
    	float c = result.floatValue();
    	System.out.println(">>>>>> Received from Business Process convert: c = " + c);
    	return c;
    }

    and the required imports from Listing 2:

    Listing 2. Required imports
    import com.ibm.websphere.sca.ServiceManager;
    import process.business.my.mbp.interface_.MBP;
  3. Promote the method to the interface, as in Listing 3:
    Listing 3. Promote the method to the interface
    public interface DefaultSession extends javax.ejb.EJBObject {
    	public float convertFtoC(float f) throws java.rmi.RemoteException;
    }
  4. Deploy the EJB.
  5. Ensure that MyBusinessProcessApp has the ConverterClientEJB.

Testing the EJB invoke

The next step is to test the EJB invoke. Test the EBJ to BPEL invocation you performed:

  1. Start the Process Server Test environment.
  2. Add MyBusinessProcessApp to the server.
  3. Start the UniversalTestClient in the browser http://localhost:9080/UTC.
  4. Browse to ejb/ejbs/DefaultSession and test the method convertToC.
    Figure 8. Testing the client EJB invocation
    Testing the client EJB invocation
  5. convertToC assigns the temperature in the BPEL but does not convert the temperature - that will come later.
  6. Observe the log. The log should look similar to Listing 4.
    Listing 4. Observe the log
    [5/17/06 5:03:24:672 EDT] 00000054 SystemOut     
    		O >>>>>> Calling Business Process convert: f = 45.0
    [5/17/06 5:03:27:562 EDT] 00000054 SystemOut     
    		O >>>>>> Received from Business Process convert: c = 45.0

Invoking a stateless session EJB as a service from a BPEL business process

Part of this is nicely described in the developerWorks article: Integrate EJB services with WebSphere Process Server. It's a good idea to refer to this article for steps one and two below.

Creating a service EJB invoked from BPEL

The first step is to create a service EJB that the BPEL will invoke:

  1. In the J2EE perspective, create a stateless session EJB called Temperature in an EJB project called TemperatureEJB, and place the EJB module in Enterprise Application TemperatureApp.
  2. Add a remote method called convertToC (see Listing 5 for implementation) to the Bean and promote it.
    Listing 5. Add a remote method to the Bean
    public float convertToC(float f){
    	System.out.println(">>>>>> ConverterClientEJB: fahrenheit  = " + f);
    	float c = (f - 32F)*5F/9F;
    	System.out.println(">>>>>> ConverterClientEJB: centigrade = " + c);
    	return c;
    }
  3. Deploy the bean.
  4. Create a client jar called TemperatureEJBClient.
  5. Open the ejb deployment descriptor and notice the EJB JNDI name:

    ejb/ejbs/TemperatureHome

  6. Create an EJB client and jar to be used for the SCA import operation.
  7. Right-click on the ConverterEJB and select EJB Client JAR => Create EJB Client Project.
  8. Select the defaults and click Finish. This creates an EJB Client project called TemperatureEJBClient, under Other Projects in the J2EE perspective.
  9. Run and test the EJB in the UTC. The output should look similar to Listing 6.
Listing 6. EJB Client project output
[5/16/06 22:50:34:922 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: fahrenheit  = 33.0
[5/16/06 22:50:34:922 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: centigrade = 0.5555556

Adding an import for the EJB

The second step is to add an import for the EJB in the MyBusinessProcessModule.

  1. In the Business Integration perspective, right-click on MyBusinessProcess and select Dependency Editor, see Figure 9.
  2. Add the TemperatureEJBClient as the dependent Java Project.
    Figure 9. Dependency Editor
    Dependency Editor
  3. Open the MyBusinessProcess Assembly Diagram.
  4. Add an import component on the canvas. Change its name to TemperatureEJB.
  5. Click the Add Interface icon.
  6. Search for the Temperature interface, see Figure 10 below.
    Figure 10. Add the Temperature Interface
    Add the Temperature Interface
  7. Click OK.
  8. Generate the EJB binding for the import.
  9. Right-click on the TemperatureEJB import and select Generate Binding -> Stateless Session Bean Binding.
  10. Select the Properties tab and the Bindings tab. Check to make sure that the JNDI name field is now ejb/ejbs/TemperatureHome
  11. Retest the EJB via the import: right-click on the TemperatureEJB import on the Assembly Editor canvas and select Test Component.
  12. Test using the component tester. The output should look similar to Listing 7.
Listing 7. Test component output
[5/16/06 23:26:10:016 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: fahrenheit  = 45.0
[5/16/06 23:26:10:016 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: centigrade = 7.2222223

Wiring the business process to the EJB

Now we are ready to wire the business process to the EJB import:

It is not possible to wire a BPEL component (W-Type) directly to an EJB import (J-Type). You need to provide a bridging component between the two to convert from W-Type to J-Type. This topic is covered in the Information Center, IBM WebSphere Business Process Management Version 6.0 information center Business services: WSDL and Java interfaces and references.

Here are the detailed steps:

  1. Add a new Java component (name it JavaBridge) and wire it to the target stateless session bean import, TemperatureEJB. This wiring adds a Java reference to the Bridge component.
  2. Click on the interface icon and select the WSDL interface MBP.
  3. Right-click on JavaBridge, select Generate Implementation, and then select bridge as new folder. This brings up a JavaBridge implementation.
  4. Edit the method, see Listing 8.
    Listing 8. New JavaBridge convert method
    /**
    * Method generated to support implemention of operation "convert" 
    * defined for WSDL port type 
    * named "interface.MBP".
    * 
    * Please refer to the WSDL Definition for more information 
    * on the type of input, output and fault(s).
    */
    public Float convert(Float degF) {
    	//TODO Needs to be implemented.
    	//return null;
    	// This is how to implement the bridge method
    	Temperature temp = locateService_TemperaturePartner();
    	float c = 0F;
    	try {
    		c = temp.convertToC(degF.floatValue());
    	} catch (java.rmi.RemoteException e) {
    		e.printStackTrace();
    		c = - 4500F;
    	}
    	return new Float( c );
    }
  5. Wire MBP to JavaBridge.
  6. Double-click on MBP in the Business Process to bring up the BP editor.
  7. Remove the Assign task.
  8. Insert an Invoke task in its place.
  9. Add a Reference Partner call MBPPartner, browse for interfaces, and select MBP.
  10. Select the Invoke task and examine the Details pane. Add variables to inputs and outputs.
  11. The results should look the same as Figure 11 and there should be no errors.
    Figure 11. Properties for Invoke
    Properties for Invoke
  12. The Business process edit should look like Figure 12 below.
    Figure 12. BPEL Editor
    BPEL Editor
  13. Compare the results to make sure they are similar to Figure 13.
    Figure 13. Assembly Editor
    Assembly Editor

Congratulations, you are now done building and are now ready to test.

Testing the component

  1. Right-click on MBP and click Test Component and remove the emulators. After test, you should see the results as recorded in Figure 14 below.
    Figure 14. Final component test
    Final component test
  2. Perform the final end-to-end test with the Universal Test Client.
  3. You might need to first check whether ConverterClientEJB.jar is still in MyBusinessProcessApp deployment descriptor, and if not add it back. (If so remember to add/remove projects from the server before testing) Deployment.
  4. The descriptor should similar to Figure 15.
    Figure 15. MyBusinessProcessApp Deployment Descriptor
    MyBusinessProcessApp Deployment Descriptor
  5. Bring up the UTE. Browse for ejb/ejbs/DefaultSessionHome and test against it.
  6. See the log showing end-to-end invocation below:
Listing 9. Add a remote method to the Bean
[5/17/06 13:08:55:984 EDT] 0000005c SystemOut     
   O >>>>>> Calling Business Process convert: f = 185.0
[5/17/06 13:08:56:328 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: fahrenheit  = 185.0
[5/17/06 13:08:56:328 EDT] 0000005c SystemOut     
   O >>>>>> ConverterClientEJB: centigrade = 85.0
[5/17/06 13:08:56:328 EDT] 0000005c SystemOut     
   O >>>>>> Received from Business Process convert: c = 85.0

Conclusion

This article demonstrated how to use WebSphere Integration Developer to incrementally build and test an end-to-end example showing how EJBs can act as clients and services in relation to BPEL business processes. It highlighted the use of a stand-alone reference within the client EJB to invoke a BPEL business process, and showed how a BPEL business process can invoke a service EJB, using a W-Type to J-Type bridging component. We used the WebSphere Integration Developer Universal Test Client to test the example.


Download

DescriptionNameSize
My BP Project zip fileMyBP_ProjInterchangeFile.zip64KB

Resources

Learn

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=151237
ArticleTitle=Using BPEL and EJBs with WebSphere Process Server and WebSphere Integration Developer
publish-date=08092006