org.apache.activemq.web
Class MessageListenerServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.activemq.web.MessageServletSupport
org.apache.activemq.web.MessageListenerServlet
- All Implemented Interfaces:
- Serializable, 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
- Version:
- $Revision: 1.1.1.1 $
- See Also:
- Serialized Form
Methods inherited from class org.apache.activemq.web.MessageServletSupport |
appendParametersToMessage, asBoolean, asBoolean, asDestination, asInt, asInteger, asLong, asLong, asString, getDestination, getDestination, getDestinationFromURI, getPostedMessageBody, getSendPriority, getSendTimeToLive, init, isSendPersistent, isSync, isTopic |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MessageListenerServlet
public MessageListenerServlet()
init
public void init()
throws ServletException
- Overrides:
init
in class GenericServlet
- Throws:
ServletException
doPost
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws 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 HttpServlet
- Parameters:
request
- response
-
- Throws:
ServletException
IOException
doGet
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException
- Supports a HTTP DELETE to be equivlanent of consuming a singe message
from a queue
- Overrides:
doGet
in class HttpServlet
- Throws:
ServletException
IOException
doMessages
protected void doMessages(WebClient client,
HttpServletRequest request,
HttpServletResponse response)
throws JMSException,
IOException
- Reads a message from a destination up to some specific timeout period
- Parameters:
client
- The webclientrequest
- response
-
- Throws:
ServletException
IOException
JMSException
writeMessageResponse
protected void writeMessageResponse(PrintWriter writer,
Message message)
throws JMSException,
IOException
- Throws:
JMSException
IOException
getListener
protected org.apache.activemq.web.MessageListenerServlet.Listener getListener(HttpServletRequest request)
getConsumerIdMap
protected Map<MessageAvailableConsumer,String> getConsumerIdMap(HttpServletRequest request)
getConsumerDestinationNameMap
protected Map<MessageAvailableConsumer,String> getConsumerDestinationNameMap(HttpServletRequest request)
isRicoAjax
protected boolean isRicoAjax(HttpServletRequest request)
getReadTimeout
protected long getReadTimeout(HttpServletRequest request)
- Returns:
- the timeout value for read requests which is always >= 0 and <=
maximumReadTimeout to avoid DoS attacks
Copyright © 2005-2011 Apache Software Foundation. All Rights Reserved.