Part 3 of this article series guides you through the unit testing of the
scenario implementation from
Part 2
with IBM ® WebSphere® Studio Application Developer Version 5
(hereafter called Application Developer). As discussed in Part 2, the Book
Search use case is implemented with a pub/sub message model, as in
TopicMDB.ear. The Book Review use case is
implemented with a p2p message model, as in
QueueMDB.ear. For more information on the
implementation, see Part 2.
The sample applications and sample configurations can be downloaded below.
Step 1. Configuring the embedded JMS provider
The WebSphere embedded JMS provider is required to test the applications. Unlike the built-in MQ Simulator, the Embedded JMS provider requires the optional feature IBM embedded messaging client and server to be installed, as shown in Figure 1, below.
The installation wizard lets you choose a destination folder for the
embedded messaging server, for example
E:\Program Files\IBM\WebSphere MQ.
Assume that Application Developer is installed in
E:\Program Files\IBM\WebSphere Studio. A
successful installation of the embedded messaging client and server
modifies the properties in
E:\Program Files\IBM\WebSphere Studio\runtimes\base_5\properties\implfactory.properties,
as shown below. The MQ Simulator is disabled and the embedded JMS server
is enabled.
#Embedded JMS Provider
com.ibm.ws.messaging.JMSProvider=com.ibm.ws.messaging.JMSEmbeddedProviderImpl
#MQ Simulator for Java Developers JMS Provider for
WebSphere Studio Unit Test Environment
#com.ibm.ws.messaging.JMSProvider=com.ibm.ws.messaging.JMSMQJDProviderImpl
|
Figure 1. Installing embedded messaging client and server feature
Step 2. Configuring the WebSphere Test Environment
In this section, you set up the WebSphere Test Environment. If you don't
need to learn about this process, you can skip this section by downloading the server configuration
CS_Server.wsc and then following the steps in
Step 2 (Jumpstart) below.
Creating a new server instance and configuration
Create a new server and server configuration named
CS_Server:
- In the server perspective, select File = > New = > Server and Server Configuration.
- Enter
CS_Serveras the Server name. - Select the Server type to be WebSphere Version 5 => Test Environment.
- Click Finish.
Assume that the embedded JMS server is installed in
X:\Program Files\IBM\WebSphere MQ
and
DB2® is installed in
X:\Program Files\SQLLIB. Follow these steps to
modify the server variables:
- In the Server perspective, double-click on CS_Server from the Server Configuration view. An editor will open.
- Switch to the Variables Tab. Locate each of the variables shown in Table 1 and click on Edit to modify the value.
- Save the server configuration file.
Table 1
| Variable Name | Variable Value |
| MQ_INSTALL_ROOT | X:\Program Files\IBM\WebSphere MQ |
| MQJMS_LIB_ROOT | ${MQ_INSTALL_ROOT}/java/lib |
| WAS_PUBSUB_ROOT | ${MQ_INSTALL_ROOT}/wemps |
| DB2_JDBC_DRIVER_PATH | X:\Program Files\SQLLIB\java\db2java.zip |
The QueueMDB and TopicMDB application both require a Connection Factory and a destination, as shown in Table 2. This section sets up the connection factories and destinations for both applications.
Table 2
| Application name | Connection Factory name | Destination name |
| QueueMDB | QueueConnectionFactory | CS_Queue |
| TopicMDB | CS_TopicConnectionFactory | CS_Topic |
Create a queue on the embedded JMS server named
CS_Queue:
- In the server configuration editor, click on the JMS tab.
- In the Server Settings section, add a queue named
CS_Queue. - Change the Initial State to START, as shown in Figure 2:
Figure 2. Creating CS_Queue on the embedded JMS server
Add a queue connection factory named
CS_QueueConnectionFactory to the server:
- In the JMS tab of the server configuration editor, click Add to
add a
WASQueueConnectionFactoriesentry. - Enter
CS_QueueConnectionFactoryas the Name. - Enter
jms/qcfas the JNDI Name. - Select localhost as the Node.
- Select server1 as the Server Name.
- Select EntirePool as the Purge Policy.
- Click OK to finish.
Figure 3. Configuring CS_QueueConnectionFactory
Configure a destination for CS_Queue:
- In the JMS tab of the server configuration editor, click
Add to add a
WASQueueentry. - Add the destination for CS_Queue, as shown in Figure 4 below.
- Enter
CS_Queueas the Name. - Enter
jms/queueas the JNDI Name. - Select localhost as the Node.
- Click OK to finish.
Figure 4. Configuring CS_Queue
Add a topic connection factory named
CS_TopicConnectionFactory:
- In the JMS tab of the server configuration editor, click Add to
add a
WASTopicConnectionFactoryentry. - Enter
CS_TopicConnectionFactoryas the Name. - Enter
jms/tcfas the JNDI Name. - Select localhost as the Node.
- Select server1 as the Server Name.
- Select QUEUED as the Port.
- Click OK to finish.
Figure 5. Configuring CS_TopicConnectionFactory
Configure a JMS destination for CS_Topic:
- In the JMS tab of the server configuration editor, click Add to
add a
WASTopicentry. - Enter
CS_Topicas the Name. - Enter
jms/topicas the JNDI Name. - Enter
CS_Topicas the Topic. - Click OK to finish.
Figure 6. Configuring CS_Topic
Configuring the MDB listener ports
As discussed in
Part 1,
the message-driven bean (MDB) listener port is an IBM implementation that
associates an MDB with a connection factory and a destination. This
section creates a listener port named QueuePort
that associates the MDB named QueueMDB with its
connection factory CS_QueueConnectionFactory.
Another listener port named TopicPort is
created to associate the MDB named TopicMDB
with its connection factory
CS_TopicConnectionFactory.
Configure a listener port named QueuePort:
- In the server configuration editor, click on the EJB tab.
- Click on Add to create a listener port named
QueuePort. - Select jms/qcf as the Connection Factory JNDI Name.
- Select jms/queue as the Destination JNDI Name.
- Click OK to finish.
Configure a listener port named TopicPort:
- In the Server Configuration Editor, click on the EJB tab.
- Click on Add to create a listener port named
TopicPort. - Select jms/tcf as the Connection Factory JNDI Name.
- Select jms/topic as the Destination JNDI Name.
- Click OK to finish.
Configuring a DB2 XA datasource
A DB2 XA-compliant datasource is needed for the Book Review application (QueueMDB) to connect to a back-end CMP entity bean. The next two sections show how to configure the datasource:
Creating a DB2 JDBC provider (XA)
- In the server configuration editor, switch to the Datasource tab.
- Click on Add to add a new JDBC provider.
- Select IBM DB2 as the Database type. Select DB2 JDBC Provider (XA) as the JDBC provider type.
- Click Next.
- Enter
DB2 JDBC Provider (XA)as the Name and leave the default values for the other fields, as shown in Figure 8. - Click Finish.
Figure 8. Creating a DB2 JDBC Provider (XA)
Creating a DB2 XA datasource
- Highlight the DB2 JDBC Provider (XA) and click on Add in the second panel. The datasource is defined in the JDBC provider selected above.
- Select DB2 JDBC Provider (XA) as the JDBC provider.
- Choose Version 5.0 datasource.
- Click Next.
- Enter
DB2 Data Source (XA)as the Name. - Enter
jdbc/db2xaDSas the JNDI Name. - Ensure Use this data source in container managed persistence (CMP) is checked.
- Click Next, highlight the database name under Resource
Properties, and set its value to
Sample. - Click Finish.
- Save and close the Server Configuration Editor.
Figure 9. Creating a DB2 Data Source (XA)
You have now finished the set up on the WebSphere Test Environment. Continue in Step 3 below.
Step 2 (Jumpstart). Creating a server instance from the sample server configurations
If you've completed Step 2. Configuring WebSphere Test Environment, you can skip this section. Use this section if you want to download the sample server configurations and use them instead of going thru the steps in Step 2.
Importing the sample server configurations
- Select File => Import => Server Configuration, and then click Next.
- Enter a configuration name of
CS_Server. - Set the folder to the Case Study Server project, which will be dynamically created later on.
- Choose a server configuration type of WebSphere version 5.0 Server Configuration.
- Click Browse, navigate to the location where you unzipped the sample code, and select the CS_Server.wsc directory, as shown in Figure 10.
- Click Finish. In the dialog asking to create the Case Study Server Project, click Yes.
Figure 10. Importing Server Configuration
Creating a new server instance
- Select File => New => Other = > Server to create a new server instance, and then click Next.
- Set the server name to CS_Server, using the Case Study Server Project folder.
- Choose a server type of WebSphere Version 5.0 Test Environment and then click Finish.
- Open the Sever Perspective by selecting Window => OpenPerspective => Other => Server.
- In the Server Configuration View, select CS_Server; then right-click and change Switch Configuration from No configuration to CS_Server, as shown in Figure 11:
Figure 11. Switch Server Configuration
Assume that the embedded JMS server is installed in
X:\Program Files\IBM\WebSphere MQ
and DB2
is installed in X:\Program Files\SQLLIB. Follow
these steps to modify the server variables:
- In the Server perspective, double-click on CS_Server from the Server Configuration view. An editor will open.
- Switch to the Variables Tab. Locate each of the variables shown in Table 3 and click Edit to modify the value.
- Save the server configuration file.
Table 3
| Variable Name | Variable Value |
| MQ_INSTALL_ROOT | X:\Program Files\IBM\WebSphere MQ |
| MQJMS_LIB_ROOT | ${MQ_INSTALL_ROOT}/java/lib |
| WAS_PUBSUB_ROOT | ${MQ_INSTALL_ROOT}/wemps |
| DB2_JDBC_DRIVER_PATH | X:\Program Files\SQLLIB\java\db2java.zip |
Step 3. Importing EAR files into the workspace
After the WebSphere Test Environment is fully set up, download the sample EAR files and import them into the workspace:
- Select File => Import = > EAR file from the menu, and then click Next.
- Browse to the path where
TopicMDB.earis located and select it as the EAR module to import. - Enter
TopicMDBas the Project Name. - Click Finish.
- Perform the same steps for
QueueMDB.earand enterQueueMDBas the Project Name.
Step 4. Deploying projects to the server
Add the two Enterprise Applications, TopicMDB and QueueMDB, to the server:
- In the Server perspective - server view, right-click on CS_Server and select Add => TopicMDB.
- Right-click on CS_Server and select Add => QueueMDB.
Step 5. Testing the Book Search application
The Book Search application is implemented in TopicMDB. The application has a GUI interface that lets readers query a book by book and author name.
The class client.demo.MessageProcessor creates a
JMS search message and sends it to a Topic to which the MDBs
ejb.topic.TopicMDB_A and
ejb.topic.TopicMDB_B are listening. The MDBs
parse the message and invoke
ejb.session.SessionEJB.
MessageProcessor also creates a dynamic reply
Topic to which the SessionEJB sends the search
result message. MessageProcessor, which is
listening to the reply Topic, filters out any obsolete replies based on
the JMSCorrelationIDs.
Here are the steps to test the book search scenario:
- In the Server perspective, right click on CS_Server and select Start.
Launching the application client
- In the J2EE perspective, select Run => Run from the menu.
- Select WebSphere V5 Application Client.
- Click New.
- Enter
TopicMDBas the Name. - Select WebSphere V5 as the Server Type.
- Select TopicMDB as the Enterprise Application.
- Switch to the Classpath page. Add the following external JAR files
from the IBM WebSphere MQ installed directory
(for example,X:\Program Files\IBM\WebSphere MQ\java\lib):com.ibm.mq.jar com.ibm.mqbind.jar com.ibm.mqjms.jar
- Click Apply and then Run.
Figure 12. Configuring application client launcher
Figure 13. Configuring application client launcher
- When the application is started, enter
Joe Nobodyas the Reader name and click Inquiry. The reply from the back-end system is displayed in the scrollable pane, as shown in Figure 14:
Figure 14. Testing the Book Search application
If the operation is successful, you will see the following traces in the Debug Perspective. Because a J2EE application client runs on its own JVM, which is different from the server JVM, you must refer to the application client thread for the application trace and to the server console for the server trace.
The trace for the client:
1. User request is received: Joe Nobody $*Customer*$ Career Direction $*item*$ 2. MessageProcessor,sendMessage(), is to publish message to CS_Topic: Joe Nobody $*Customer*$ Career Direction $*item*$ Notify, MessageProcessor, onMessge(): The reply message is current Notify, MessageProcessor, onMessge(), Inquiry reply: Joe Nobody $*Customer*$ Career Direction $*item*$ The book is on the shelf, take it home and enjoy. -- Section B $*Result*$ |
The trace for the server:
3. TopicMDB_B, onMessage(): ObjectMessage arrives... 4.TopicMDB_B, onMessage(): Delegate business requirement to Session Bean 5. SessionEJB, sendReply(): Joe Nobody $*Customer*$ Career Direction $*item*$ The book is on the shelf, take it home and enjoy. -- Section B $*Result*$ |
Step 6. Testing the Book Review application
The Book Review application is implemented in QueueMDB. Through a Web
browser, a user submits a comment on a book. A message created by the
servlet com.web.QueueClient is then delivered
to a JMS Queue. The MDB com.mdb.QueueMDB
listens to the Queue and invokes the CMP
com.entity.EntityEJB. Then the servlet
QueueClient redirects the user to a JSP,
response.jsp.
Because the business logic is handled by a CMP, you must create a table
named ENTITYEJB. The
CreateEINTITYEJB.ddl is provided for creating
an ENTITYEJB table in the SAMPLE database. Follow these steps to create
the table:
- In the J2EE Navigator view, navigate to the folder
QueueMDBEJB\ejbModule\META-INF\.
Right-click on CreateENTITYEJB.ddl and select Run on database server:
Figure 15. Creating the ENTITYEJB table
- Accept the defaults in the Run script wizard and click Next.
- Accept the defaults and click Next.
- Create a new or use an existing database connection. Fill in the database connection information.
- Click Finish.
Running the application on the server
- In the J2EE Navigator view, right-click on index.html in the QueueMDBWeb project and select Run on Server.
- Fill in the input in the browser as shown in Figure 16:
Figure 16. Testing the Book Review application
- Click Submit.
- Here is the output generated by the
response.jsp:
Figure 17. Output in response.jsp
Here are some common problems you might see during the testing:
If QueueMDB does not start, ensure that the listener port,
QueuePort, is associated with
CS_QueueConnectionFactory (jms/qcf) and
CS_Queue (jms/queue).
In addition, ensure that the JMS queue destination
(CS_Queue) is created with the same name of the
queue (CS_Queue) on the embedded JMS
server.
Ensure that the listener port, TopicPort, is
associated with CS_TopicConnectionFactory and
CS_Topic.
Ensure that TopicMDB is associated with a queued
port. Queued port and direct port are the TCP/IP port numbers reserved for
the embedded JMS provider's listener ports. Queued port supports both p2p
and pub/sub, while direct port supports only non-transactional,
non-persistent, and non-durable subscriptions. Therefore,
TopicMDB should be associated with a queued
port instead of a direct port.
If the QueueMDB application starts but the operation fails with an SQL return code, ensure that the following configurations have been completed:
- The DB2 JDBDC driver is at the JDBC2 level. To ensure that JDBC2 is in
use, invoke the file
<DB2 installDir>\java12\usejdbc2. You might need to stop the DB2 engine, unlock the JDBC driver, invoke this command, and then restart the DB2 engine. - The DB2_JDBC_DRIVER variable is configured correctly, as discussed in Step 2 above.
- The ENTITYEJB table has been created in the SAMPLE database.
Problem with the application client launcher
If you start the TopicMDB application and get no reply after entering the
request, check the trace from the server and the application client. If
the trace shows that the MDBs did not receive message arrival
notification, the application client launcher may have failed. Ensure that
the launcher's classpath is properly configured and that
utility.jar and
Quary.jar contain the serializable
JavaTM bean used to populate the message. If they are not
in the application client's manifest file as dependent JAR files, the
client will fail to publish the message.
Check that the variables are configured correctly.
Back to Part 1 -- JMS and Message-Driven Beans
Back to Part 2 -- End-to-End Case Study
| Name | Size | Download method |
|---|---|---|
| Download file yu3.zip | 0.2 MB | FTP |
Information about download methods
-
EJB 2.0
Specification (Sun Web site)
-
JMS Specification
(Sun Web site)
-
JMS tutorial (Sun
Web site)
-
WebSphere
Application Server Information Center
-
Developing and Testing Message-driven Bean Applications with the MQ Simulator for Java Developers in WebSphere Studio V5
Ying Zhao is a software developer on the WebSphere Studio Application Developer team at the IBM Toronto Lab. Ying received her Master of Science degree in Electrical Engineering at Technion - Israeli Institute of Technology in 1999. Ying is an IBM Certified Enterprise Developer, Solution Developer, XML Developer and Specialist for WebSphere Studio Application Developer. You can reach Ying at yingzhao@ca.ibm.com.
Colin Yu is a technical designer on the WebSphere Business Scenarios team at the IBM Toronto Lab. Colin received a Bachelor of Engineering degree in 1995 and a Master of Applied Science degree from the University of Waterloo, Ontario in 2000. Colin is an IBM Certified Enterprise Developer and Systems Expert on WebSphere Application Server, and an IBM Certified Solution Developer on WebSphere Studio Application Developer and VisualAge for Java. You can reach Colin at coliny@ca.ibm.com.
Jane Fung works on the WebSphere Studio Application Developer Intergration Edition tools development team at the IBM Toronto Lab. Jane earned a Bachelor of Applied Science degree in Electrical Engineering at the University of Waterloo, Ontario, and is a Sun Java 2 Certified Programmer. You can reach Jane at jcyfung@ca.ibm.com.




