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
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.
- From the WebSphere Integration Developer, select the Business Integration perspective, create a module called
MyBusinessProcess, and then create a business process calledMBPinside the module. - Select generate a new interface to generate the interface MBP. Select convert (an operation), input
degF, and outputdegC, both of typefloatto create the business process, as in Figure 2.
Figure 2. Assembly Diagram: Select the convert operation (input and output) to create a business process
- In the MBP business process, delete variable
Input1, and create two new variables,degC, anddegF, both of typefloat.
Figure 3. Business Process Editor
- Associate the Receive with
degF, and Reply withdegC, see Figure 4.
Figure 4. Business Process Editor -- Receive properties
- Add an Assign task between Receive and Reply for test purposes, and assign the variables
DegFtoDegC, see Figure 5.
Figure 5. BPEL Editor, adding an Assign Task
- Drag the MBP business process to the Assembly Editor.
- Right-click on the canvas and choose add node => Stand-alone References.
- Wire the stand-alone reference to the MBP Interface.
- Respond Yes to the question, "A matching reference will be created on the source node. Do you want to continue?"
- Respond Yes to the Reference dialog (see Figure 6).
Figure 6. Reference dialog
- 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.
- From the WebSphere Integration Developer, choose the J2EE perspective. Create an EJB project called
ConverterClientEJBand 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
- In the default stateless session bean, add the remote method from Listing 1:
Listing 1. The remote methodpublic 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 importsimport com.ibm.websphere.sca.ServiceManager; import process.business.my.mbp.interface_.MBP;
- Promote the method to the interface, as in Listing 3:
Listing 3. Promote the method to the interfacepublic interface DefaultSession extends javax.ejb.EJBObject { public float convertFtoC(float f) throws java.rmi.RemoteException; }
- Deploy the EJB.
- Ensure that MyBusinessProcessApp has the ConverterClientEJB.
The next step is to test the EJB invoke. Test the EBJ to BPEL invocation you performed:
- Start the Process Server Test environment.
- Add MyBusinessProcessApp to the server.
- Start the UniversalTestClient in the browser http://localhost:9080/UTC.
- Browse to ejb/ejbs/DefaultSession and test the method
convertToC.
Figure 8. Testing the client EJB invocation
-
convertToCassigns the temperature in the BPEL but does not convert the temperature - that will come later. - 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:
- In the J2EE perspective, create a stateless session EJB called
Temperaturein an EJB project calledTemperatureEJB, and place the EJB module in Enterprise ApplicationTemperatureApp. - 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 Beanpublic float convertToC(float f){ System.out.println(">>>>>> ConverterClientEJB: fahrenheit = " + f); float c = (f - 32F)*5F/9F; System.out.println(">>>>>> ConverterClientEJB: centigrade = " + c); return c; }
- Deploy the bean.
- Create a client jar called
TemperatureEJBClient. - Open the ejb deployment descriptor and notice the EJB JNDI name:
ejb/ejbs/TemperatureHome - Create an EJB client and jar to be used for the SCA import operation.
- Right-click on the ConverterEJB and select EJB Client JAR => Create EJB Client Project.
- Select the defaults and click Finish. This creates an EJB Client project called TemperatureEJBClient, under Other Projects in the J2EE perspective.
- 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 |
The second step is to add an import for the EJB in the MyBusinessProcessModule.
- In the Business Integration perspective, right-click on MyBusinessProcess and select Dependency Editor, see Figure 9.
- Add the TemperatureEJBClient as the dependent Java Project.
Figure 9. Dependency Editor
- Open the MyBusinessProcess Assembly Diagram.
- Add an import component on the canvas. Change its name to
TemperatureEJB. - Click the Add Interface icon.
- Search for the
Temperatureinterface, see Figure 10 below.
Figure 10. Add the Temperature Interface
- Click OK.
- Generate the EJB binding for the import.
- Right-click on the TemperatureEJB import and select Generate Binding -> Stateless Session Bean Binding.
- Select the Properties tab and the Bindings tab. Check to make sure that the JNDI name field is now
ejb/ejbs/TemperatureHome - Retest the EJB via the import: right-click on the TemperatureEJB import on the Assembly Editor canvas and select Test Component.
- 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:
- 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. - Click on the interface icon and select the WSDL interface MBP.
- Right-click on JavaBridge, select Generate Implementation, and then select bridge as new folder. This brings up a JavaBridge implementation.
- 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 ); }
- Wire MBP to JavaBridge.
- Double-click on MBP in the Business Process to bring up the BP editor.
- Remove the Assign task.
- Insert an Invoke task in its place.
- Add a Reference Partner call
MBPPartner, browse for interfaces, and select MBP. - Select the Invoke task and examine the Details pane. Add variables to inputs and outputs.
- The results should look the same as Figure 11 and there should be no errors.
Figure 11. Properties for Invoke
- The Business process edit should look like Figure 12 below.
Figure 12. BPEL Editor
- Compare the results to make sure they are similar to Figure 13.
Figure 13. Assembly Editor
Congratulations, you are now done building and are now ready to test.
- 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
- Perform the final end-to-end test with the Universal Test Client.
- 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.
- The descriptor should similar to Figure 15.
Figure 15. MyBusinessProcessApp Deployment Descriptor
- Bring up the UTE. Browse for ejb/ejbs/DefaultSessionHome and test against it.
- 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 |
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.
| Description | Name | Size | Download method |
|---|---|---|---|
| My BP Project zip file | MyBP_ProjInterchangeFile.zip | 64KB | HTTP |
Information about download methods
Learn
-
Integrate EJB services with WebSphere Process Server
-
Integrate EJB services with WebSphere Process Server, Part 2
-
Meet the experts: Paul Pacholski on WebSphere Integration Developer
-
IBM WebSphere Business Process Management Version 6.0 information center: Business services, WSDL and Java interfaces and references
-
Safari Bookshelf for developers
-
WebSphere Business Integration zone provides the technical resources you need for WebSphere Business Integration products.
-
WebSphere Process Server and WebSphere Integration Developer resource page
-
IBM WebSphere Integration site provides technical resources for all of IBM's business integration offerings.
-
New to WebSphere Business Integration provides a brief introduction to the IBM WebSphere Business Integration family of products and describes resources available to help you learn more.
Discuss
-
Participate in developerWorks
blogs and get involved in the developerWorks community.
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.
Comments (Undergoing maintenance)





