Subscribe to WebSphere: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get WebSphere: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

IBM WebSphere software products Authors: Liz McMillan, Pat Romanski, Yeshim Deniz, hyper filter, Timothée Bensimon

Related Topics: Java EE Journal, Apache Web Server Journal, WebSphere

J2EE Journal: Article

Leverage Existing WebSphere Application Server J2EE Resources

Through the Use of WebSphere Application Server Community Edition

By accessing the IBM WebSphere Application Server JNDI tree, WebSphere Application Server Community Edition (IBM's free, lightweight J2EE application server built on Apache Geronimo technology) can interact with and reuse virtually any of the J2EE resources that are housed there.

It is not uncommon for enterprises to leverage different application server flavors throughout their organization to accommodate a variety of business objectives. A case in point might be a company that primarily runs IBM WebSphere Application Server V6, but has a business need to run IBM's cost-free WebSphere Application Server Community Edition as well to power the myriad of J2EE applications running throughout the enterprise. Code reusability is a key programming principle that supports such an environment, enabling you to lower programming costs and exploit existing code assets at the same time.

In this article, we will show you how to leverage existing J2EE code artifacts running in WebSphere Application Server V6 from a J2EE application server that is not WebSphere Application Server. Namely, we will show how to use WebSphere Application Server Community Edition, which is based on Apache Geronimo, the J2EE server project of the Apache Software Foundation, to interact with a J2EE resource powered by WebSphere Application Server V6.

This article assumes a basic knowledge of WebSphere Application Server Community Edition or Apache Geronimo, and general familiarity with J2EE and WebSphere Application Server programming concepts. See Resources for helpful introductory information.

In this article:

  • Community Edition refers to WebSphere Application Server Community Edition.
  • WebSphere Application Server refers to WebSphere Application Server - Express, WebSphere Application Server Base, and WebSphere Application Server Network Deployment.
Our cross application server scenarioWe will illustrate how to use a J2EE resource -- specifically, a stateless session EJB component running in a WebSphere Application Server EJB container -- via a servlet that resides in a Community Edition servlet container. In other words, as shown in Figure 1, a consuming servlet running on Community Edition will be used to hit an EJB component running on WebSphere Application Server V6.

PrerequisitesTo follow along with the steps in this article, you must have the following software properly installed and running:

  • Application Client for WebSphere Software - Also known as the "thin client," this is a set of resources and an IBM JVM specifically designed for client access to WebSphere Application Server applications. This is available through the same install wizard or launchpad wizard in any WebSphere Application Server product. It is also available separately as a trial download. When installing the Application Client, you will need to install the J2EE and JavaTM thin application client, as shown in Figure 2.
  • WebSphere Application Server Community Edition v1.0.0.1 - A lightweight J2EE application server built on Apache Geronimo open source technology, designed to help you accelerate your development and deployment efforts by being quick to download and easy to implement. You can download and use the Community Edition product free of charge.
  • IBM Rational® Application Developer V6 - This is the development environment we will use to implement both the Geronimo and WebSphere code. Be sure to download the optional Integrated Test Environment for WebSphere Application Server V6. A trial version of Rational Application Developer is available for download.
For the purpose of this article, all of the prerequisite software described above can reside on the same physical machine. In a production environment, however, Community Edition would likely reside on a separate machine than that of an actual WebSphere Application Server cluster, rather than the test WebSphere Application Server instance running in Rational Application Developer that we will use here. Regardless, the WebSphere Application Client must be installed on the same machine as Community Edition because we will be importing JAR files from the WebSphere Application Client installation as common libraries in Community Edition.

Create a simple EJB component for WebSphere Application Server
First, using Rational Application Developer, we will create a simple stateless session EJB to run in the WebSphere Application Server EJB container. We will power our EJB with the Rational Application Developer test environment. The simplicity of this EJB is intentional, since we are focusing on the ability to invoke the EJB's remotely exposed methods, rather than on the EJB itself.

1.  In Rational Application Developer, create a new workspace. You can switch workspaces by selecting File => Switch Workspace... or by specifying a new one at startup.
2.  In the J2EE perspective, right-click EJB Projects and select New => EJB Project.
3.  Enter or select the following values (Figure 3):

  • Name: SimpleEJBProjecto EJB version: 2.1
  • Target Server: WebSphere Application Server v6.0
  • EAR project name: SimpleEJBProjectEARthen select Finish.
4.  Expand SimpleEJBProject => Deployment Descriptor: SimpleEJBProject. Right-click Session Beans, then select New => Session Bean (Figure 4).
5.  Enter or select the following values (Figure 5):
  • Bean name: SimpleEJB
  • Default package: devworks.examplethen select Finish.
6.  Select EJB Projects => SimpleEJBProject => Deployment Descriptor: SimpleEJBProject => Session Beans => SimpleEJB, and then click the plus icon to expand the SimpleEJB bean. Modify the remote interface class (SimpleEJB) as follows:

public String retrieveText() {
      return "G-E-R-O-N-I-M-O!!!";

7.  The implementation of the SimpleEJB project is complete. We now need to export an EJB client JAR that includes stubs for calling the remote EJB. This client JAR will be used by our consuming application running on Community Edition.
8.  If you expand Other Projects you should see SimpleEJBProjectClient. If not, create one by right-clicking SimpleEJBProject and then select EJB Client JAR => Create EJB Client JAR Project. Name the new client SimpleEJBProjectClient.
9.  Right-click SimpleEJBProjectClient and select Export... => JAR file => Next. Select a location, name it EJBClient.jar, save it under JAR file, then Finish.
10.  Finally, we need to deploy our simple EJB on WebSphere Application Server. Select the Servers tab, right-click WebSphere Application Server and select Start.
11.  Right-click WebSphere Application Server and select Add and Remove Projects => SimpleEJBProjectEar => Add and then Finish.

At this point, we now have our J2EE resource, a stateless session EJB component. We want to invoke a remote method of this EJB component via a consuming servlet (running on Community Edition) which we will build shortly. Use the Universal Test Client to test your EJB (Figure 6).

Before we build our invoking servlet, we will need to determine where our J2EE resource resides in the WebSphere Application Server JNDI tree. That is next. Determine the fully-qualified JNDI name for the simple EJBTo determine where the EJB we just created resides in our JNDI tree, we can use a script facility called dumpNameScript.

Navigate to the bin directory of the integrated WebSphere Application Server and execute the dumpNamespace script. For example, under Windows, this may be C:\IBM\RAD6\runtimes\base_v6\bin\dumpNameSpace.bat, or for Linux®, /opt/IBM/RAD6/runtimes/base_v6/bin/dumpNameSpace.sh.

More Stories By Kulvir Singh Bhogal

Kulvir Singh Bhogal works as an IBM Software Services for WebSphere consultant, devising and implementing WebSphere-centric solutions at customer sites across the nation. He has over fifty patents pending in a myriad of technology areas. He can be reached at [email protected]

More Stories By Robert R. Peterson

Robert R. Peterson is part of the enablement team under IBM Software Services for WebSphere. He works to ensure that the WebSphere portfolio of products brings IBM's clients the greatest value possible. Robert is an accomplished inventor and co-author of WebSphere Application Server V6: Performance and Scalability. He is an alumni of IBM's prestigious Extreme Blue Program and holds a M.S. in Computer Engineering from the University of Florida.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.