Sun Java System Message Queue 3.7 UR1 Developer's Guide for Java Clients

Example 1: Deferring SOAP Processing

In the first example, illustrated in Figure 5–9, an incoming SOAP message is received by a servlet. After receiving the SOAP message, the servlet MyServlet uses the MessageTransformer utility to transform the message into a JMS message, and (reliably) forwards it to an application that receives it, turns it back into a SOAP message, and processes the contents of the SOAP message.

For information on how the servlet receives the SOAP message, see Writing a SOAP Service.

Figure 5–9 Deferring SOAP Processing

Diagram showing deferred SOAP processing. Figure content
is described in text.

ProcedureTo Transform the SOAP Message into a JMS Message and Send the JMS Message

  1. Instantiate a ConnectionFactory object and set its attribute values, for example:


    QueueConnectionFactory myQConnFact =
            new com.sun.messaging.QueueConnectionFactory();
  2. Use the ConnectionFactory object to create a Connection object.


    QueueConnection myQConn =
             myQConnFact.createQueueConnection();
  3. Use the Connection object to create a Session object.


    QueueSession myQSess = myQConn.createQueueSession(false,
             Session.AUTO_ACKNOWLEDGE);
  4. Instantiate a Message Queue Destination administered object corresponding to a physical destination in the Message Queue message service. In this example, the administered object is mySOAPQueue and the physical destination to which it refers is myPSOAPQ.


    Queue mySOAPQueue = new com.sun.messaging.Queue("myPSOAPQ");
  5. Use the MessageTransformer utility, as shown, to transform the SOAP message into a JMS message. For example, given a SOAP message named MySOAPMsg,


    Message MyJMS = MessageTransformer.SOAPMessageIntoJMSMessage
                                         (MySOAPMsg, MyQSess);
  6. Create a QueueSender message producer.

    This message producer, associated with mySOAPQueue, is used to send messages to the queue destination named myPSOAPQ.


    QueueSender myQueueSender = myQSess.createSender(mySOAPQueue);
  7. Send a message to the queue.


    myQueueSender.send(myJMS);

ProcedureTo Receive the JMS Message, Transform it into a SOAP Message, and Process It

  1. Instantiate a ConnectionFactory object and set its attribute values.


    QueueConnectioFactory myQConnFact = new
             com.sun.messaging.QueueConnectionFactory();
  2. Use the ConnectionFactory object to create a Connection object.


    QueueConnection myQConn = myQConnFact.createQueueConnection();
  3. Use the Connection object to create one or more Session objects.


    QueueSession myRQSess = myQConn.createQueueSession(false,
             session.AUTO_ACKNOWLEDGE);
  4. Instantiate a Destination object and set its name attribute.


    Queue myRQueue = new com.sun.messaging.Queue("mySOAPQ");
  5. Use a Session object and a Destination object to create any needed MessageConsumer objects.


    QueueReceiver myQueueReceiver =
         myRQSess.createReceiver(myRQueue);
  6. If needed, instantiate a MessageListener object and register it with a MessageConsumer object.

  7. Start the QueueConnection you created in Example 1: Deferring SOAP Processing. Messages for consumption by a client can only be delivered over a connection that has been started.


    myQConn.start();
  8. Receive a message from the queue.

    The code below is an example of a synchronous consumption of messages:


    Message myJMS = myQueueReceiver.receive();
  9. Use the Message Transformer to convert the JMS message back to a SOAP message.


    SOAPMessage MySoap =
             MessageTransformer.SOAPMessageFromJMSMessage
                 (myJMS, MyMsgFactory);

    If you specify null for the MessageFactory argument, the default Message Factory is used to construct the SOAP Message.

  10. Disassemble the SOAP message in preparation for further processing. See The SOAP Message Object for information.