Skip to main content

Integrate EJB Services with WebSphere Process Server

Peter Xu (peteryxu@us.ibm.com), Senior Consulting I/T Specialist, IBM Software Service for WebSphere, IBM
Peter Xu is a Senior Consultant with IBM Software Services for WebSphere group. Consultants with Software Services for WebSphere help customers deploy IBM products into their organizations. Peter provides consulting services, education, and mentoring on J2EE technologies, and specifically WebSphere and WebSphere Studio products to Fortune 500 clients. You can reach him at peteryxu@us.ibm.com.

Summary:  This article shows you how to use IBM WebSphere Process Server Version 6 and IBM WebSphere Integration Developer Version 6 to integrate existing J2EE applications without making changes to them.

Date:  02 Feb 2006
Level:  Intermediate
Activity:  536 views

Introduction

IBM® WebSphere® Process Server is a runtime platform for business integration solutions developed using IBM WebSphere Integration Developer. Many existing business functions for a company's IT infrastructure are written based on Java™ 2 Enterprise Edition (J2EE) stateless Enterprise Java Beans (EJB). When you design and implement new business process integration applications, it is important that you have the ability to leverage and integrate these functions easily.

Overview diagram

The scenario we use in this article is pretty straightforward. It consists of one Service Component Architecture (SCA) module that has a Java component, which uses the imported EJB service.


Figure 1. Module overview
Module overview

Software prerequisites

You need to install:

  • WebSphere Integration Developer V6
  • WebSphere Process Server V6 test environment

This article assumes that you have some knowledge of J2EE and have used WebSphere Studio Application Developer or Rational Application Developer before. To learn more about these products, visit developerWorks.

Configuration

In this section, we develop a sample EJB application and an SCA module that utilizes the EJB service.

You can begin by creating the enterprise application, package, and EJB session.

  1. Create an enterprise application called Echo with one EJB module, EchoEJB

  2. Create a package called com.ibm.issw.poc.invokeejb.

  3. Create a stateless EJB session called Bean Echo


    Figure 2. Create an EJB
    Create an EJB
  4. Create a simple method called echoSimple, and promote it the remote interface:

    public String echoSimple(String name){
    		System.out.println("inside echoSimple");
    		return "Hello, " + name;
    	}

  5. Open the ejb deployment descriptor, and notice the default JNDI name for the EJB:

    ejb/com/ibm/issw/poc/invokeejb/EchoHome


    Figure 3. EJB JNDI name
    EJB JNDI name
  6. Create an EJB client project and jar that will be used later in the SCA module.

  7. Right-click and select EchoEJB => EJB Client Jar => Create EJB Client Project and enter EchoEJBClient in the name field.


    Figure 4. EJB Client
    EJB Client
  8. Run and test the EJB application (see Figure 5).


    Figure 5. Testing the EJB
    Testing the EJB

Now, that we've created the EJB, let's integrate it.

Create an EJB component

To integrate the EJB into the WebSphere Process Server SCA component:

  1. Create a module called InvokeEcho.

  2. From the Dependencies editor, select EchoEJBClient as the dependent Java project and click Add to add EchoEJBCLient as the dependent Java project.


    Figure 6. Add dependencies
    Add dependencies

    It is important to add module dependency at this point. When we add the interface later, the wizard will be able to find the remote EJB interface.

  3. From the Assembly editor, open the module, InvokeEcho in Assembly editor, add an Import component on the canvas. Change the name to EchoEJB.


    Figure 7. Add the Import
    Add the import
  4. Add the interface for the import:

    1. Click the Add Interface icon.

    2. In the resulting window, select Show Java.

    3. Enter echo in the Filter by interface field.

    4. Select Echo from Matching interfaces . This interface is from project /EchoEJBClient/ejbModule (see Figure 8).


      Figure 8. Add Interface for Import
      Add Interface for Import
  5. Click Ok and save the module diagram.


    Figure 9. Import with the interface
    Import with the interface
  6. Generate the Session EJB Binding.

    1. Right-click the EchoEJB import and select Generate Binding => Stateless Session Bean Binding.


      Figure 10. Add Binding
      Add Binding
    2. Notice how the icon changed in the import (see Figure 11).


      Figure 11. Import with Interface Binding
      Import with Interface Binding
    3. Select the Properties view and the Binding tab. You can see that the JNDI name field is now populated (see Figure 12).


      Figure 12. Specify JNDI name for Binding
      Specify JNDI name for Binding

Create a Java Component

To create a Java Component:

  1. Drag and drop a Java Component onto the assembly canvas and change the name to InvokeEcho (see Figure 13).


    Figure 13. Add the Java Component
    Add the Java Component
  2. Create an interface called InvokeEchoInterface with a one-way operation callEcho and one input parameter:


    Figure 14. Create an Interface
    Create an Interface
  3. Select the Java component and add an interface for it, InvokeEchoInterface.

  4. Wire the InvokeEcho and EchoEJB together (see Figure 15).


    Figure 15. Wire Java and Import the Component
    Wire Java and Import the Component

    Notice that a reference EchoPartner has been generated. We will use it in the Java Component implementation (see Figure 16).


    Figure 16. Partner reference
    Partner reference
  5. Select and right-click the Java Component and generate the default Java implementation. When the implementation opens, replace the callEcho method with the following code:

            try {
            	
                System.out.println("in callEcho");
    		    // Create an instance of the ServiceManager
    	        ServiceManager serviceManager = new ServiceManager();
    	        
    	        Echo echo= (Echo)serviceManager.locateService("EchoPartner");
    	        
    	        String result = echo.echoSimple(name);
    	        System.out.println("called imported EJB, and response is " + result);
    	        
            } catch (Exception e) {
                e.printStackTrace();
            }

Running and testing the scenario

To test the scenario:

  1. Right-click InvokeEcho and select Test Component.

  2. In the test configuration, remove the emulator for EchoEJB, since we want to invoke the real EJB implementation.

  3. Enter a value for the name field and click Continue.


    Figure 17. Component Test 1
    Component Test 1
  4. Notice the expected result.


    Figure 18. Component Test 2
    Component Test 2

    Notice the result from the System.out.


    Figure 19. Component Test 3
    Component Test 3

Congratulations, you've successfully imported and invoked the Echo EJB from the SCA component, InvokeEcho. In this scenario, the SCA module and the EJB service are running on the same server.


Conclusion

This article helped you implement a WebSphere Process Server solution that integrates EJB services. As you can see, using EJB services from an SCA component is easy to do. Reusing EJB-based services in this way creates tremendous opportunities for integration products, such as WebSphere Process Server.

Acknowledgements

The author would like to thank Sam Kaipa for reviewing this article.


Resources

About the author

Peter Xu is a Senior Consultant with IBM Software Services for WebSphere group. Consultants with Software Services for WebSphere help customers deploy IBM products into their organizations. Peter provides consulting services, education, and mentoring on J2EE technologies, and specifically WebSphere and WebSphere Studio products to Fortune 500 clients. You can reach him at peteryxu@us.ibm.com.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=102831
ArticleTitle=Integrate EJB Services with WebSphere Process Server
publish-date=02022006
author1-email=peteryxu@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers