WebSphere and MQSeries integration sample.

Introduction

This sample code demonstrates using a thin client solution with MQSeries.  The scenario requirements is that a user fills out an HTML form. The user data is collected from the form and sent via a message queue to the back end application.  The back end application will then process the form data and send a reply back via the message queue.  The reply needs to be displayed in the browser.
The sample shows the interaction between a thin client, servlet and message queue and demonstrates how different products offered by IBM can be used in the solution.

Process flow

  1. The user fills out an HTML form.
  2. The form  is sent to the servlet.
  3. The servlet converts the HTTP request into an MQ message and puts it on a queue.
  4. The back end application processes the message and sends a reply back through a message queue.
  5. The servlet retrieves the message from the queue and stores it in a Java Bean.
  6. The servlet then invokes a Java Server Page which is compiled and dynamically generates a result HTML page.
  7. The JSP retrieves the message content for the page from the Java Bean and incorporates it into the HTML and displays the result page back on the browser.


Software Requirements

    IBM HTTP Server 3.0
    WebSphere 2.02
    JDK version 1.1.7
    MQSeries version 5.0
    Netscape or Internet Explorer 3.0 or later

Configuring the MQSeries Server

  1. Ensure that MQSeries Server has been installed without any error.
  2. Ensure that the following files provided with this package are copied to a proper working directory:
    1.  a. mqsetup.bat
       b. mqconfig.txt
       c. backend_trg.txt
  3. Start the IBM MQSeries Services.
  4. At an NT command prompt, change to the working directory, and enter mqsetup. The mqsetup.bat file creates and configures the queue manager (NC.QManager), and creates the required queues.
Configuring IBM HTTP Server
 
  1. Ensure that IBM HTTP Server is installed without any errors.
  2. Ensure that the following files provided with this package are copied to the htdocs directory :
    1. a. AddressInputForm.html
      b. AddressOutputPage.jsp


Configuring the WebSphere
 

  1. Ensure that WebSphere Application server is installed without any errors.
  2. Using WebSphere Application Server Administration Tool, go to Setup -> Java Engine pane.

  3.         Select Use System Classpath ? - No.
            Make sure you have the servlets directory and MQ's java classes in the class path.
            In Application Server Classpath - x:\..\..\WebSphere\AppServer\servlets; x:\..\mqm\java\lib;
     

  4. Create a directory structure of  com\ibm\toolbelt\ in your WebSphere's Appserver\servlets directory.
  5. Ensure that the following files provided with this package are copied to the servlets\com\ibm\toolbelt directory:

  6.     a. BillingAddressServlet.class
        b. BillingAddressBean.class
  7. In WebSphere Application Server Administration Tool, go to Servlets -> Configuration pane.
  8. Click on Add. A Add a New Servlet dialog box comes up, fill in the following -

  9.         Servlet Name - BillingAddressServlet
            Class Name - com.ibm.toolbelt.BillingAddressServlet
            Bean Servlet - No

        Click on Test, and verify that the servlet is loaded successful.


Running the sample

In the NT services pane make sure the following services IBM HTTP Server, WebSphere Servlet Service and IBM MQSeries are started. Open up a browser window and invoke the AddressInputForm.html by typing http://localhost/AddressInputForm.html. Fill out the information requested and click Submit.
The browser sends request to the BillingAddressServlet, which will put the message on the queue.  It then retrieves the message back from the queue.  The retrieved message is stored in the BillingAddressBean.  The servlet then invokes AddressOutputPage.jsp.  Which then displays the return message in the browser.
Note that the first time when you invoke the servlet, it take a lot of time to get back the reply.  Your browser may also time out, depending on browser time out value.  This is because WebSphere loads the servlet in the memory.  Also the AddressOutputPage.jsp is compiled into a servlet and gets loaded in memory.  However, subsequent calls to the BillingAddressServlet are much faster since it is now loaded in memory and readily available to execute the work.