O'Reilly logo

Java Web Services: Up and Running by Martin Kalin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Web Services and Java Message Service

GlassFish, like any full-feature application server, includes a JMS provider that supports publish/subscribe (topic-based) and point-to-point (queue-based) messaging. Topics and queues are persistent stores. For example, one application can send a message to a JMS queue, and another application, at some later time, can retrieve the message from the queue. However, the JMS does not specify how long an implementation needs to persist messages. This section illustrates the basics of JWS/JMS interaction with two web services. The MsgSender service has a send operation that inserts a message in a queue, and the MsgReceiver service has a receive operation that retrieves a message from the front of the queue (see Figure 6-2).

Integrating JAX-WS and JMS

Figure 6-2. Integrating JAX-WS and JMS

Here is the source code for the MsgSender service:

package ch06.jms; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.QueueConnectionFactory; import javax.jms.QueueConnection; import javax.jms.Session; import javax.jms.JMSException; import javax.annotation.Resource; // A web service that sends a message to a queue. @WebService public class MsgSender { // name and mappedName can differ; mappedName is the JNDI lookup name @Resource(name="qcf", mappedName="qcf") private QueueConnectionFactory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required