Skip to main content

WebSphere Application Server Pluggable Application Client

Kulvir Bhogal (kbhogal@us.ibm.com), IBM e-business Consultant, Fort Worth, Texas
Kulvir Singh Bhogal works as an IBM consultant, devising and implementing J2EE-centric solutions at customer sites across the United States. You can reach Kulvir at kbhogal@us.ibm.com

Summary:  The WebSphere Application Server Pluggable Application Client lets you use a Sun Java Runtime Environment to interact with application server resources and code artifacts, such as EJBs. This article will show you how to use the Pluggable Application Client.

Date:  01 Sep 2004
Level:  Intermediate
Activity:  653 views

Introduction

My previous article, Using JNDI with WebSphere® Application Server J2EE Thin Application Client showed how to use Thin Application Client to interact with J2EE resources such as EJBs that are powered by WebSphere Application Server.

This article will describe the WebSphere Application Server Pluggable Application Client. It lets you use a Sun Java™ Run-time Environment (JRE), which works in tandem with a lightweight, downloadable application run time that can interact with the application server's resources (such as enterprise beans). This plug-in ability of the Pluggable Application Client is what differentiates it from Thin Application Client. You provide the JRE, as opposed to having to use the JRE bundled with the Thin Application Client. This article starts by taking you through the installation procedure of the Pluggable Application Client, then shows you how to use it to interact with a stateless session EJB.


The Sun JRE

Since you will be using the Sun JRE to interact with WebSphere Application Server, you need to have the Sun JRE installed. Sun maintains an archive of previous versions of the Sun JRE, and only certain versions are compatible with the Pluggable Application Client. Check the WebSphere Application Server Information Center for compatibility information. Use the Sun JRE installation defaults, which include using two installation directories, such as C:\j2sdk1.4.2_05 and C:\Program Files\Java\j2re1.4.2_05.


Installing the Pluggable Application Client with the Sun JRE

You need to have an instance of WebSphere Application Server V5.1 up and running, since we will use it to deploy the stateless session EJB with which the Pluggable Application Client interacts. For demonstration purposes, we will actually use WebSphere Studio Application Developer V5.1.2 (hereafter called Application Developer) and its built-in WebSphere Test Environment (WTE). Application Developer provides you with an integrated development environment (IDE) to develop and test EJBs, and WTE is a single-server, sandbox instance of WebSphere Application Server.

On a client workstation, you need to install the WebSphere Application Server Pluggable Application Client. I installed the Pluggable Application Client on the same machine that is running Application Developer and WTE. The typical setup is shown below:


Figure 1. WebSphere Application Server Pluggable Application Client uses Sun JRE to interact with an instance of WebSphere Application Server
Figure 1. WebSphere Application Server Pluggable Application Client uses Sun JRE to interact with an instance of WebSphere Application Server

As our diagram above shows, application clients use Remote Method Invocation (RMI) over the Internet Inter-Orb Protocol (IIOP) to interact with the application server.

You must install the same version of the Pluggable Application Client client and the application server. In my case, the WTE within Application Developer is an instance of WebSphere Application Server V5.1. The Application Client is bundled with WebSphere Application Server Enterprise Edition, on the CD labeled "Application Clients." It is only available for Windows®.

To install the Pluggable Application Client, launch the installer on the Application Clients CD and select Custom install. When asked to choose which features you want to install, choose the Pluggable Application Client, as shown below:


Figure 2. Choosing the Pluggable Application Client as a feature to be installed
Figure 2. Choosing the Pluggable Application Client as a feature to be installed

During the installation, you will need to enter the hostname of the target WebSphere Application Server, in order to populate the batch file setupclient.bat, which is located in the application client install directory's bin directory. You can modify it later if your target server changes. Since my test server and Pluggable Application Client are on the same machine, I entered localhost for the hostname and port 2809 (the default listening port for WebSphere Application Server V5):


Figure 3. Specifying target WebSphere Application Server information
Figure 3. Specifying target WebSphere Application Server information

There is one change we need to make to the setupclient.bat file before we move on. The space in the directory name will cause problems, so change the line:

set JAVA_JRE=C:\Program Files\Java\j2re1.4.2_05 to:

set JAVA_JRE=C:\Progra~1\Java\j2re1.4.2_05


Introducing the EJB

To demonstrate the ability of the WebSphere Application Server Pluggable Application Client to interact with resources on WebSphere Application Server, we need to have a resource to interact with. If you use J2EE technologies and Sun JRE clients, you'll probably need to interact with EJBs, so we'll have the Pluggable Application Client interact with a stateless session EJB named Converter. You can download it with the sample code associated with this article, and it contains two business methods that have been exposed via the EJB's remote interface. The methods are called celsiusToFahrenheit and fahrenheitToCelsius and do exactly what their names imply, using the formulas below:

Celsius = (Fahrenheit - 32) * 5/9

Fahrenheit = Celsius * 9/5 + 32

The code below shows our formulas being incorporated as two of the EJB's methods:

public float fahrenheitToCelsius(float fahrenheit)
{
	float celsius = (fahrenheit - 32) * 5/9;
	return celsius;
}
public float celsiusToFahrenheit(float celsius)
{
	float fahrenheit = celsius * 9/5 + 32;
	return fahrenheit;
}

If you are using Application Developer, then you might want to use IBM Universal Test Client to make sure the Converter EJB acts as expected, as shown below:


Figure 4. Using the IBM Universal Test Client to Test Out the Converter EJB
Figure 4. Using the IBM Universal Test Client to Test Out the Converter EJB

If you are using WebSphere Application Server as opposed to the Application Developer WTE, go ahead and deploy the EAR to the application server.


Locating the EJB

The Converter bean has a JNDI name of ejb/com/ibm/ConverterHome. It can be difficult to figure out the JNDI tree of a target server if you are unfamiliar with what was deployed there. To avoid this difficulty, the Application Client ships with a utility named dumpnamespace (found in the Application Client's bin directory), which you can use to view the resources registered with the JNDI server. As sown below, you can see that our EJB has its ConverterHome present in the name space:


Figure 5. Using the dumpnamespace utility to locate the JNDI name of the Converter EJB
Figure 5. Using the dumpnamespace utility to locate the JNDI name of the Converter EJB

Notice the fully qualified JNDI name of the EJB home since we will use it as we interact with our EJB. With the Pluggable Application Client, you must use the fully qualified name of the EJB home (see the section below Life is a bit harder with the Pluggable Application Client).


Preparing the client to interact with the EJB

Now that the Pluggable Application Client is installed, run setupclient.bat to prepare it to interact with WebSphere Application Server. A sample Java class (Client.java) to interact with our EJB can be found in the downloadable sample code, and it contains a main method. As with any EJB client, we create our initial context by gathering configuration information about our target WebSphere Application Server instance from our invocation string, as described below. After creating the initial context, we look up our EJB home from our context using the JNDI lookup string:

cell/nodes/localhost/servers/server1/ejb/com/ibm/ConverterHome

The object we get back is cast to our EJB home object, and from this object we create an instance of the Converter bean. It is on this Converter bean that we can call our exposed remote methods. The sample code demonstrates the use of the fahrenheitToCelsius method.

%JAVA_HOME%/bin/java -Xbootclasspath/p:%WAS_BOOTCLASSPATH% 
-classpath <classpath JARs>
-Djava.ext.dirs=%WAS_EXT_DIRS% -Djava.naming.provider.url=iiop://localhost
-Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
%SERVER_ROOT% %CLIENTSAS% <class containing main method>

The command above must be all on one line. With the parameters filled in, it will execute the sample code:

%JAVA_HOME%/bin/java -Xbootclasspath/p:%WAS_BOOTCLASSPATH% 
-classpath c:\client\clientstubs.jar;c:\client\client.jar
-Djava.ext.dirs=%WAS_EXT_DIRS% -Djava.naming.provider.url=iiop://localhost
-Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
%SERVER_ROOT% %CLIENTSAS% Client

The JAR file clientstubs.jar contains the client-side proxy stubs needed to interact with the remote skeleton of the EJB housed in the application server. The file client.jar contains the Client class, which, as explained, invokes our exposed EJB method. You should see the calling of the EJB's exposed remote method by the Pluggable Application Client as shown below:


Figure 6. Using the Pluggable Application Client code to invoke an EJB remote method on WebSphere Application Server
Figure 6. Using the Pluggable Application Client code to invoke an EJB remote method on WebSphere Application Server

Life is a bit harder with the Pluggable Application Client

With J2EE application clients (as opposed to thin application clients and the Pluggable Application Client), you can use nicknames or shortnames that you have defined in the client application deployment descriptor to perform your JNDI lookups. This is not the case with thin application clients and Pluggable Application Clients, where you must provide the fully qualified location of our JNDI resource as it is located on the application server. As stated earlier, the dumpnamespace utility makes finding out the fully qualified JNDI locations of objects much easier.


Conclusion

This article has demonstrated how the WebSphere Application Server Pluggable Application Client lets you use a Sun JRE to interact with resources on WebSphere Application Server. The Pluggable Application Client makes it possible to plug in a Sun JRE, and since many enterprises use the Sun JRE, being able to interact with objects on WebSphere Application Server is a big advantage.



Download

NameSizeDownload method
pluggable.zip84 KBFTP|HTTP

Information about download methods


Resources

About the author

Kulvir Singh Bhogal works as an IBM consultant, devising and implementing J2EE-centric solutions at customer sites across the United States. You can reach Kulvir at kbhogal@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=16306
ArticleTitle=WebSphere Application Server Pluggable Application Client
publish-date=09012004
author1-email=kbhogal@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