Package org.apache.activemq.web
Class MessageServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.activemq.web.MessageServletSupport
-
- org.apache.activemq.web.MessageServlet
-
- All Implemented Interfaces:
Serializable
,Servlet
,ServletConfig
public class MessageServlet 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. One thing to keep in mind with this solution - due to the nature of REST, there will always be a chance of losing messages. Consider what happens when a message is retrieved from the broker but the web call is interrupted before the client receives the message in the response - the message is lost.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MessageServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeConsumerOnOneShot(HttpServletRequest request, WebClient client, Destination dest)
Close the consumer if one-shot mode is used on the given request.protected void
doDelete(HttpServletRequest request, HttpServletResponse response)
Supports a HTTP DELETE to be equivalent of consuming a single message from a queueprotected void
doGet(HttpServletRequest request, HttpServletResponse response)
Supports a HTTP DELETE to be equivalent of consuming a single message from a queueprotected void
doMessages(HttpServletRequest request, HttpServletResponse response)
Reads a message from a destination up to some specific timeout periodprotected void
doPost(HttpServletRequest request, HttpServletResponse response)
Sends a message to a destinationprotected String
getContentType(HttpServletRequest request)
protected long
getReadDeadline(HttpServletRequest request)
WebClient
getWebClient(HttpServletRequest request)
protected void
handleContinuation(HttpServletRequest request, HttpServletResponse response, WebClient client, Destination destination, MessageAvailableConsumer consumer, long deadline)
void
init()
protected boolean
isXmlContent(Message message)
protected void
setResponseHeaders(HttpServletResponse response, Message message)
protected void
writeMessageResponse(PrintWriter writer, Message message)
protected void
writeResponse(HttpServletRequest request, HttpServletResponse response, Message message)
-
Methods inherited from class org.apache.activemq.web.MessageServletSupport
appendParametersToMessage, asBoolean, asBoolean, asDestination, asInt, asInteger, asLong, asLong, asString, getDestination, getDestination, getDestinationFromURI, getPostedMessageBody, getSelector, getSendPriority, getSendTimeToLive, init, isSendPersistent, isSync, isTopic
-
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log
-
-
-
-
Method Detail
-
init
public void init() throws ServletException
- Overrides:
init
in classGenericServlet
- Throws:
ServletException
-
doPost
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Sends a message to a destination- Overrides:
doPost
in classHttpServlet
- Parameters:
request
-response
-- Throws:
ServletException
IOException
-
doDelete
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Supports a HTTP DELETE to be equivalent of consuming a single message from a queue- Overrides:
doDelete
in classHttpServlet
- Throws:
ServletException
IOException
-
doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Supports a HTTP DELETE to be equivalent of consuming a single message from a queue- Overrides:
doGet
in classHttpServlet
- Throws:
ServletException
IOException
-
doMessages
protected void doMessages(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Reads a message from a destination up to some specific timeout period- Parameters:
request
-response
-- Throws:
ServletException
IOException
-
handleContinuation
protected void handleContinuation(HttpServletRequest request, HttpServletResponse response, WebClient client, Destination destination, MessageAvailableConsumer consumer, long deadline)
-
writeResponse
protected void writeResponse(HttpServletRequest request, HttpServletResponse response, Message message) throws IOException, JMSException
- Throws:
IOException
JMSException
-
writeMessageResponse
protected void writeMessageResponse(PrintWriter writer, Message message) throws JMSException, IOException
- Throws:
JMSException
IOException
-
isXmlContent
protected boolean isXmlContent(Message message) throws JMSException
- Throws:
JMSException
-
getWebClient
public WebClient getWebClient(HttpServletRequest request)
-
getContentType
protected String getContentType(HttpServletRequest request)
-
setResponseHeaders
protected void setResponseHeaders(HttpServletResponse response, Message message) throws JMSException
- Throws:
JMSException
-
getReadDeadline
protected long getReadDeadline(HttpServletRequest request)
- Returns:
- the timeout value for read requests which is always >= 0 and <= maximumReadTimeout to avoid DoS attacks
-
closeConsumerOnOneShot
protected void closeConsumerOnOneShot(HttpServletRequest request, WebClient client, Destination dest)
Close the consumer if one-shot mode is used on the given request.
-
-