SimplePublisher.java

Below is the servlet code for this example. It uses the information passed across by the user to retrieve a ConnectionFactory from the JNDI provider, connect to the OpenJMS server, create a publisher, and publish messages to it. Finally, it closes the connection and returns a response to the user.
If a problem is encountered while this request is being processed, a ServletException is returned to the user.

Finally, we must package all the above components in a Web Application Archive (war),
which is identical, in format, to JAR files. The content of openjms.war, which is shown below, complies with the structure identified in the Servlet specifications.

Modify the server.xml Configuration File

In Tomcat's server configuration file, add a new context that defines the OpenJMS Web application. The configuration redirects URLs in the form of
http://localhost:2222/openjms/ to the Web application we have just deployed.

Restarting Tomcat

Restart Tomcat, using either catalina or tomcat scripts files located in the bin directory. If the server comes up without any problems, the following will be displayed on the console:

Starting service Tomcat-Standalone
Apache Tomcat/4.0-b8-dev

Starting the OpenJMS Server

For simplicity, use the out-of-the-box RMI/JDBM configuration, rmi_jms.xml, for the server. Change to the bin directory of the OpenJMS installation and enter the following command line: startjms.bat -config ..\config\rmi_jms.xml

If the server has successfully started, the following output should appear in the console:

The important thing to note is that the server uses RMI with an embedded JNDI provider, called JndiServer, running on the localhost at port 1099. This information will be required by the user to formulate the URL.

Using the OpenJMS Web Application

Once the application has been deployed and both Tomcat and OpenJMS have been started, use the following URL to interact with the application: http://localhost:2222/openjms/servlets/SimplePublisher.html

The following page, excluding the information, will be rendered in the browser.

Figure 4.

Fill in the details, as specified above, and press Submit Query. This request will publish 20 messages under the topic jima.