You can use Servlet and assumerver Pages to integrate thin clients with MQSeries. This integration requires you to fill in an HTML form in detail, collect user data from the form, and then send the data to the backend application through a message queue. Next, the backend application processes the form data and sends a response through the message queue. The response must be displayed in the browser.
This article discusses the interaction between thin clients, Servlets, and message queues, and demonstrates how to use different products provided by IBM in this solution. Readers should understand the Java language and be familiar with WebSphere and MQSeries.
The Architecture Overview provides the recommended solution architecture. It involves three layers of methods.
Solution architecture
Process
Enter the HTML form. Send the form to Servlet. Servlet converts the HTTP request into an MQSeries message and puts it into a queue. The backend application processes the message and sends back a response through the message queue. The Servlet retrieves messages from the queue and stores them in a Java Bean. Then, call the compiled Servlet and assumerver pages and dynamically generate the result HTML Page. JSP retrieves the message content of this page from Java Bean, merges it into HTML, and then displays the result page in the browser.
The solution utilizes the following technologies:
HTML/HTTP, Java Beans, Servlet and JavaServer Page, Web server, Message Queue
This solution integrates the following products:
Netscape 4.0/Internet Explorer 3.0 or later, ibm http Server 3.0, WebSphere 2.02, JDK version 1.1.7, and MQSeries version 5.0
Connect to MQSeries
We chose the Servlet model because it has many advantages over CGI. Servlet is a standard server-side Java application that extends the functions of Web servers. The Servlet runs completely on the Web Server and does not download anything to the browser. During the loading or initial request, the Servlet is loaded into the address space of the server. After the initial request, the Servlet responds very quickly. The init method of Servlet is ready for Servlet operation. The init method is called only once for each Servlet load. In the init method, create a connection to the MQSeries queue manager as follows:
- public void init(ServletConfig config)
- throws ServletException {
- super.init(config);
- try {
- //Create a connection to the queue manager
- qMgr = new MQQueueManager("NC.QManager");
- }
- catch (MQException ex)
- {
- System.out.println
- ("An MQ error occurred in init(): Completion code "
- + ex.completionCode +
- " Reason code" + ex.reasonCode);
- try
- {
- if (qMgr != null)
- //Disconnect from the queue manager
- qMgr.disconnect();
- }
- catch (MQException e)
- {
- System.out.println("An MQ error occurred "
- + "in init() while disconnecting:" + " Completion code " +
- e.completionCode + " Reason code" + e.reasonCode);
- }
- }
- }
Since you only need to establish a connection to the MQSeries queue manager once and it takes a long time to establish a connection, the init method is an ideal place to execute this process. Then the subsequent call to the Servlet will be executed faster. WebSphere also allows users to pre-load servlets by using the management GUI. Therefore, as the queue manager is established, the Servlet is ready and will be waiting to deliver any messages.
If MQException is captured in the init method, the above Code is disconnected from the queue manager. As a result, in order to establish a connection with the queue manager, the user will have to reload the Servlet.
MQSeries Bindings for Java must be used for Servlet-MQSeries conversations. MQSeries Bindings for Java enables you to write MQSeries applications in Java. These applications communicate directly with the MQSeries queue manager to provide high-productivity, high-performance development options. They use the Java local method to directly call the existing Queue Manager API instead of using the MQSeries server connection channel for communication, which provides better performance for Java MQSeries applications. In the code, we must import the "com. ibm. mqbind. *" package. The java class of MQSeries should also be located in the WebSphere class path; this will allow the WebSphere Application Server to locate the MQSeries Bindings for Java package.
- How to install Apache Servlet
- Optimize Servlet configuration for web. xml slimming
- How to configure Servlet in XML
- Solve the Problem of Servlet JSP page garbled
- Servlet and JSP security issues