Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Integrating Message-Driven Beans into Enterprise Applications with WebSphere Studio: Part 3 -- Unit Testing With WebSphere Studio Application Developer V5

Ying Zhao, Software Developer , IBM Toronto Lab
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, Technical designer , IBM Toronto Lab
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 FungIBM Toronto Lab
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.

Summary:  Part 3 of this article series shows you how to configure and test the message-driven bean (MDB) automated library system created in Part 2.

Date:  13 May 2003
Level:  Intermediate

Activity:  1550 views
Comments:  

Introduction

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
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:

  1. In the server perspective, select File = > New = > Server and Server Configuration.
  2. Enter CS_Server as the Server name.
  3. Select the Server type to be WebSphere Version 5 => Test Environment.
  4. Click Finish.

Modifying server variables

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:

  1. In the Server perspective, double-click on CS_Server from the Server Configuration view. An editor will open.
  2. Switch to the Variables Tab. Locate each of the variables shown in Table 1 and click on Edit to modify the value.
  3. Save the server configuration file.

Table 1

Variable Name Variable Value
MQ_INSTALL_ROOTX:\Program Files\IBM\WebSphere MQ
MQJMS_LIB_ROOT${MQ_INSTALL_ROOT}/java/lib
WAS_PUBSUB_ROOT${MQ_INSTALL_ROOT}/wemps
DB2_JDBC_DRIVER_PATHX:\Program Files\SQLLIB\java\db2java.zip

Creating JMS resources

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
QueueMDBQueueConnectionFactoryCS_Queue
TopicMDBCS_TopicConnectionFactoryCS_Topic

Create a queue on the embedded JMS server named CS_Queue:

  1. In the server configuration editor, click on the JMS tab.
  2. In the Server Settings section, add a queue named CS_Queue.
  3. Change the Initial State to START, as shown in Figure 2:

Figure 2. Creating CS_Queue on the embedded JMS server
Creating CS_Queue on the embedded JMS server

Add a queue connection factory named CS_QueueConnectionFactory to the server:

  1. In the JMS tab of the server configuration editor, click Add to add a WASQueueConnectionFactories entry.
  2. Enter CS_QueueConnectionFactory as the Name.
  3. Enter jms/qcf as the JNDI Name.
  4. Select localhost as the Node.
  5. Select server1 as the Server Name.
  6. Select EntirePool as the Purge Policy.
  7. Click OK to finish.

Figure 3. Configuring CS_QueueConnectionFactory
Configuring CS_QueueConnectionFactory

Configure a destination for CS_Queue:

  1. In the JMS tab of the server configuration editor, click Add to add a WASQueue entry.
  2. Add the destination for CS_Queue, as shown in Figure 4 below.
  3. Enter CS_Queue as the Name.
  4. Enter jms/queue as the JNDI Name.
  5. Select localhost as the Node.
  6. Click OK to finish.

Figure 4. Configuring CS_Queue
Configuring CS_Queue

Add a topic connection factory named CS_TopicConnectionFactory:

  1. In the JMS tab of the server configuration editor, click Add to add a WASTopicConnectionFactory entry.
  2. Enter CS_TopicConnectionFactory as the Name.
  3. Enter jms/tcf as the JNDI Name.
  4. Select localhost as the Node.
  5. Select server1 as the Server Name.
  6. Select QUEUED as the Port.
  7. Click OK to finish.

Figure 5. Configuring CS_TopicConnectionFactory
Configuring CS_TopicConnectionFactory

Configure a JMS destination for CS_Topic:

  1. In the JMS tab of the server configuration editor, click Add to add a WASTopic entry.
  2. Enter CS_Topic as the Name.
  3. Enter jms/topic as the JNDI Name.
  4. Enter CS_Topic as the Topic.
  5. Click OK to finish.

Figure 6. Configuring CS_Topic
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:

  1. In the server configuration editor, click on the EJB tab.
  2. Click on Add to create a listener port named QueuePort.
  3. Select jms/qcf as the Connection Factory JNDI Name.
  4. Select jms/queue as the Destination JNDI Name.
  5. Click OK to finish.

Configure a listener port named TopicPort:

  1. In the Server Configuration Editor, click on the EJB tab.
  2. Click on Add to create a listener port named TopicPort.
  3. Select jms/tcf as the Connection Factory JNDI Name.
  4. Select jms/topic as the Destination JNDI Name.
  5. 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)

  1. In the server configuration editor, switch to the Datasource tab.
  2. Click on Add to add a new JDBC provider.
  3. Select IBM DB2 as the Database type. Select DB2 JDBC Provider (XA) as the JDBC provider type.
  4. Click Next.
  5. Enter DB2 JDBC Provider (XA) as the Name and leave the default values for the other fields, as shown in Figure 8.
  6. Click Finish.

Figure 8. Creating a DB2 JDBC Provider (XA)
Creating a DB2 JDBC Provider (XA)

Creating a DB2 XA datasource

  1. Highlight the DB2 JDBC Provider (XA) and click on Add in the second panel. The datasource is defined in the JDBC provider selected above.
  2. Select DB2 JDBC Provider (XA) as the JDBC provider.
  3. Choose Version 5.0 datasource.
  4. Click Next.
  5. Enter DB2 Data Source (XA) as the Name.
  6. Enter jdbc/db2xaDS as the JNDI Name.
  7. Ensure Use this data source in container managed persistence (CMP) is checked.
  8. Click Next, highlight the database name under Resource Properties, and set its value to Sample.
  9. Click Finish.
  10. Save and close the Server Configuration Editor.

Figure 9. Creating a DB2 Data Source (XA)
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

  1. Select File => Import => Server Configuration, and then click Next.
  2. Enter a configuration name of CS_Server.
  3. Set the folder to the Case Study Server project, which will be dynamically created later on.
  4. Choose a server configuration type of WebSphere version 5.0 Server Configuration.
  5. Click Browse, navigate to the location where you unzipped the sample code, and select the CS_Server.wsc directory, as shown in Figure 10.
  6. Click Finish. In the dialog asking to create the Case Study Server Project, click Yes.

Figure 10. Importing Server Configuration
Importing Server Configuration

Creating a new server instance

  1. Select File => New => Other = > Server to create a new server instance, and then click Next.
  2. Set the server name to CS_Server, using the Case Study Server Project folder.
  3. Choose a server type of WebSphere Version 5.0 Test Environment and then click Finish.
  4. Open the Sever Perspective by selecting Window => OpenPerspective => Other => Server.
  5. 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
Switch Server Configuration

Modifying server variables

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:

  1. In the Server perspective, double-click on CS_Server from the Server Configuration view. An editor will open.
  2. Switch to the Variables Tab. Locate each of the variables shown in Table 3 and click Edit to modify the value.
  3. Save the server configuration file.

Table 3

Variable Name Variable Value
MQ_INSTALL_ROOTX:\Program Files\IBM\WebSphere MQ
MQJMS_LIB_ROOT${MQ_INSTALL_ROOT}/java/lib
WAS_PUBSUB_ROOT${MQ_INSTALL_ROOT}/wemps
DB2_JDBC_DRIVER_PATHX:\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:

  1. Select File => Import = > EAR file from the menu, and then click Next.
  2. Browse to the path where TopicMDB.ear is located and select it as the EAR module to import.
  3. Enter TopicMDB as the Project Name.
  4. Click Finish.
  5. Perform the same steps for QueueMDB.ear and enter QueueMDB as the Project Name.

Step 4. Deploying projects to the server

Add the two Enterprise Applications, TopicMDB and QueueMDB, to the server:

  1. In the Server perspective - server view, right-click on CS_Server and select Add => TopicMDB.
  2. 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:

Starting the server

  1. In the Server perspective, right click on CS_Server and select Start.

Launching the application client

  1. In the J2EE perspective, select Run => Run from the menu.
  2. Select WebSphere V5 Application Client.
  3. Click New.
  4. Enter TopicMDB as the Name.
  5. Select WebSphere V5 as the Server Type.
  6. Select TopicMDB as the Enterprise Application.
  7. 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 
    

  8. Click Apply and then Run.
    Figure 12. Configuring application client launcher
    Configuring application client launcher

    Figure 13. Configuring application client launcher
    Configuring application client launcher
  9. When the application is started, enter Joe Nobody as 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
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.

Creating the ENTITYEJB table

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:

  1. 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
    Creating the ENTITYEJB table
  2. Accept the defaults in the Run script wizard and click Next.
  3. Accept the defaults and click Next.
  4. Create a new or use an existing database connection. Fill in the database connection information.
  5. Click Finish.

Running the application on the server

  1. In the J2EE Navigator view, right-click on index.html in the QueueMDBWeb project and select Run on Server.
  2. Fill in the input in the browser as shown in Figure 16:
    Figure 16. Testing the Book Review application
    Testing the Book Review application
  3. Click Submit.
  4. Here is the output generated by the response.jsp:

Figure 17. Output in response.jsp
Output in response.jsp

Common problems

Here are some common problems you might see during the testing:

Problem starting QueueMDB

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.

Problem starting TopicMDB

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.

Problem with DB2

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.

Problem delivering messages

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



Download

NameSizeDownload method
Download file yu3.zip0.2 MBFTP|HTTP

Information about download methods


Resources

About the authors

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.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

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=13978
ArticleTitle=Integrating Message-Driven Beans into Enterprise Applications with WebSphere Studio: Part 3 -- Unit Testing With WebSphere Studio Application Developer V5
publish-date=05132003
author1-email=
author1-email-cc=
author2-email=
author2-email-cc=
author3-email=
author3-email-cc=

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.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

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).

Try IBM PureSystems. No charge.

Special offers