Package org.apache.activemq.web
Class MessageServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.activemq.web.MessageServletSupport
org.apache.activemq.web.MessageServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcloseConsumerOnOneShot(jakarta.servlet.http.HttpServletRequest request, WebClient client, jakarta.jms.Destination dest) Close the consumer if one-shot mode is used on the given request.protected voiddoDelete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Supports a HTTP DELETE to be equivalent of consuming a single message from a queueprotected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Supports a HTTP DELETE to be equivalent of consuming a single message from a queueprotected voiddoMessages(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Reads a message from a destination up to some specific timeout periodprotected voiddoPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Sends a message to a destinationprotected StringgetContentType(jakarta.servlet.http.HttpServletRequest request) protected longgetReadDeadline(jakarta.servlet.http.HttpServletRequest request) getWebClient(jakarta.servlet.http.HttpServletRequest request) protected voidhandleAsyncRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, WebClient client, jakarta.jms.Destination destination, org.apache.activemq.MessageAvailableConsumer consumer, long deadline) voidinit()protected booleanisXmlContent(jakarta.jms.Message message) protected voidsetResponseHeaders(jakarta.servlet.http.HttpServletResponse response, jakarta.jms.Message message) protected voidwriteMessageResponse(PrintWriter writer, jakarta.jms.Message message) protected voidwriteResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.jms.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, isTopicMethods inherited from class jakarta.servlet.http.HttpServlet
doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log
-
Constructor Details
-
MessageServlet
public MessageServlet()
-
-
Method Details
-
init
public void init() throws jakarta.servlet.ServletException- Overrides:
initin classjakarta.servlet.GenericServlet- Throws:
jakarta.servlet.ServletException
-
doPost
protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Sends a message to a destination- Overrides:
doPostin classjakarta.servlet.http.HttpServlet- Parameters:
request-response-- Throws:
jakarta.servlet.ServletExceptionIOException
-
doDelete
protected void doDelete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Supports a HTTP DELETE to be equivalent of consuming a single message from a queue- Overrides:
doDeletein classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Supports a HTTP DELETE to be equivalent of consuming a single message from a queue- Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doMessages
protected void doMessages(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Reads a message from a destination up to some specific timeout period- Parameters:
request-response-- Throws:
jakarta.servlet.ServletExceptionIOException
-
handleAsyncRequest
protected void handleAsyncRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, WebClient client, jakarta.jms.Destination destination, org.apache.activemq.MessageAvailableConsumer consumer, long deadline) -
writeResponse
protected void writeResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.jms.Message message) throws IOException, jakarta.jms.JMSException - Throws:
IOExceptionjakarta.jms.JMSException
-
writeMessageResponse
protected void writeMessageResponse(PrintWriter writer, jakarta.jms.Message message) throws jakarta.jms.JMSException, IOException - Throws:
jakarta.jms.JMSExceptionIOException
-
isXmlContent
protected boolean isXmlContent(jakarta.jms.Message message) throws jakarta.jms.JMSException - Throws:
jakarta.jms.JMSException
-
getWebClient
-
getContentType
-
setResponseHeaders
protected void setResponseHeaders(jakarta.servlet.http.HttpServletResponse response, jakarta.jms.Message message) throws jakarta.jms.JMSException - Throws:
jakarta.jms.JMSException
-
getReadDeadline
protected long getReadDeadline(jakarta.servlet.http.HttpServletRequest request) - Returns:
- the timeout value for read requests which is always >= 0 and <= maximumReadTimeout to avoid DoS attacks
-
closeConsumerOnOneShot
protected void closeConsumerOnOneShot(jakarta.servlet.http.HttpServletRequest request, WebClient client, jakarta.jms.Destination dest) Close the consumer if one-shot mode is used on the given request.
-