Section 7.6. Sending the Message


7.6. Sending the Message

Example 7-3 shows how to send a JMS Message from the Controller Servlet.

Example 7-3. ControllerServlet.java
 public class ControllerServlet extends HttpServlet {     ...     private static final String XA_QUEUE_CONNECTION_FACTORY =                                "java:comp/env/jms/MyXAQueueConnectionFactory";     private static final String CREDIT_CHECK_QUEUE =                                "java:comp/env/jms/CreditCheckQueue";     ...     protected void processRequest(HttpServletRequest request,             HttpServletResponse response)             throws ServletException, IOException {         ...         else if(RUN_CREDIT_CHECK_ACTION.equals(actionName))         {            CreditCheckRequestDTO creditCheckReq = null;             System.out.println("Credit Check:\nName = [" +                                 request.getParameter("name") + "]");             System.out.println("SSN = [" + request.getParameter("ssn") + "]");             System.out.println("Email = [" + request.getParameter("email") + "]");             creditCheckReq = new CreditCheckRequestDTO(                                    request.getParameter("name"),                                    request.getParameter("ssn"),                                    request.getParameter("email"));             JmsProducer.sendMessage(creditCheckReq, XA_QUEUE_CONNECTION_FACTORY,                                     CREDIT_CHECK_QUEUE);             destinationPage = "/index.jsp";         }         ...     }     ... } 

If you'll recall from the "Running a Credit Check" section, pressing the "Submit Credit Info" from the "Run Credit Check" form invokes the Controller Servlet's runCreditCheck action. The Controller Servlet stores the user's credit information in the CreditCheckReqDTO and calls JmsProducer.sendMessage( ) to send the credit data as an asynchronous JMS message. After sending the message, the Controller Servlet returns the user to the main page. The JmsProducer is a utility class that hides the details of sending a JMS messagethe next few sections cover the JMS API and the JmsProducer in greater detail.

We've encapsulated the user's credit information in a CreditCheckRequestDTO and shown how to send it as a JMS Message with the JmsProducer. After quickly reviewing the core JMS API, we'll see how the JmsProducer sends a JMS Message.



JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net