These constants define the JNDI context factory and the names of the QueueConnection factory and queue destinations. All of the system's messages travel through two queues, toWS@open3soap and fromWS@open3soap. The toWS prefix refers to messages headed toward the Web service, and fromWS handles messages coming back from the Web service. The open3soap suffix is the namespace of the destination. We must configure the destinations in Open3.org JMS destinations.xml file. The destinations.xml file is under the config/ directory of the base directory. Add these two lines:

The JMSClientSendReceive class also contains the elements for the XML document that forms the body of our messages. You wouldn't necessarily want to define your XML tags as String constants, but we've done so for simplicity:

The init() function connects the client to the server and sets up the sender and receiver sessions. In implementing the MessageListener interface, we utilize the event listener model for receiving messages. JMS specifies that only one thread may operate on a session at a time, and therefore we create separate sessions for the sender and receiver:

The AUTO_ACKNOWLEDGE mode is utilized. Messages are automatically acknowledged when received by the client.

This class also defines an empty onMessage() method that is overridden by classes that extend JMSClientSendReceive:

public void onMessage(javax.jms.Message msg) { }

The class implements a general sendJMSMessage method that takes a String parameter and utilizes this to build a JMS TextMessage. The system strictly utilizes JMS TextMessages to encapsulate the XML documents.

OrderApplication Class

Our next class is OrderApplication, which simulates an application for processing orders:

OrderApplication's constructor calls the parent's init() function to establish its JMS connections. Notice that the receiver is connected to FROM_WS_DEST_NAME, which is the queue for messages coming from the Web service, and the sender to TO_WS_DEST_NAME, which is the queue for messages going out to the Web service: