Class MessageListenerServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
    Direct Known Subclasses:
    AjaxServlet

    public class MessageListenerServlet
    extends MessageServletSupport
    A servlet for sending and receiving messages to/from JMS destinations using HTTP POST for sending and HTTP GET for receiving.

    You can specify the destination and whether it is a topic or queue via configuration details on the servlet or as request parameters.

    For reading messages you can specify a readTimeout parameter to determine how long the servlet should block for. The servlet can be configured with the following init parameters:

    defaultReadTimeout
    The default time in ms to wait for messages. May be overridden by a request using the 'timeout' parameter
    maximumReadTimeout
    The maximum value a request may specify for the 'timeout' parameter
    maximumMessages
    maximum messages to send per response
    See Also:
    Serialized Form
    • Constructor Detail

      • MessageListenerServlet

        public MessageListenerServlet()
    • Method Detail

      • init

        public void init()
                  throws javax.servlet.ServletException
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • doPost

        protected void doPost​(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
        Sends a message to a destination or manage subscriptions. If the the content type of the POST is application/x-www-form-urlencoded, then the form parameters "destination", "message" and "type" are used to pass a message or a subscription. If multiple messages or subscriptions are passed in a single post, then additional parameters are shortened to "dN", "mN" and "tN" where N is an index starting from 1. The type is either "send", "listen" or "unlisten". For send types, the message is the text of the TextMessage, otherwise it is the ID to be used for the subscription. If the content type is not application/x-www-form-urlencoded, then the body of the post is sent as the message to a destination that is derived from a query parameter, the URL or the default destination.
        Overrides:
        doPost in class javax.servlet.http.HttpServlet
        Parameters:
        request -
        response -
        Throws:
        javax.servlet.ServletException
        IOException
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException
        Supports a HTTP DELETE to be equivlanent of consuming a singe message from a queue
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doMessages

        protected void doMessages​(AjaxWebClient client,
                                  javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response)
                           throws javax.jms.JMSException,
                                  IOException
        Reads a message from a destination up to some specific timeout period
        Parameters:
        client - The webclient
        request -
        response -
        Throws:
        javax.servlet.ServletException
        IOException
        javax.jms.JMSException
      • writeMessageResponse

        protected void writeMessageResponse​(PrintWriter writer,
                                            javax.jms.Message message,
                                            String id,
                                            String destinationName)
                                     throws javax.jms.JMSException,
                                            IOException
        Throws:
        javax.jms.JMSException
        IOException
      • getAjaxWebClient

        protected AjaxWebClient getAjaxWebClient​(javax.servlet.http.HttpServletRequest request)
      • getReadTimeout

        protected long getReadTimeout​(javax.servlet.http.HttpServletRequest request)
        Returns:
        the timeout value for read requests which is always >= 0 and <= maximumReadTimeout to avoid DoS attacks
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        Overrides:
        destroy in class javax.servlet.GenericServlet