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 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.protected void
doDelete
(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 void
doGet
(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 void
doMessages
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Reads a message from a destination up to some specific timeout periodprotected void
doPost
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Sends a message to a destinationprotected String
getContentType
(jakarta.servlet.http.HttpServletRequest request) protected long
getReadDeadline
(jakarta.servlet.http.HttpServletRequest request) getWebClient
(jakarta.servlet.http.HttpServletRequest request) 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) void
init()
protected boolean
isXmlContent
(jakarta.jms.Message message) protected void
setResponseHeaders
(jakarta.servlet.http.HttpServletResponse response, jakarta.jms.Message message) protected void
writeMessageResponse
(PrintWriter writer, jakarta.jms.Message message) protected void
writeResponse
(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, isTopic
Methods inherited from class jakarta.servlet.http.HttpServlet
doHead, doOptions, doPut, doTrace, getLastModified, service, service
Methods 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:
init
in 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:
doPost
in classjakarta.servlet.http.HttpServlet
- Parameters:
request
-response
-- Throws:
jakarta.servlet.ServletException
IOException
-
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:
doDelete
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
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:
doGet
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
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.ServletException
IOException
-
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:
IOException
jakarta.jms.JMSException
-
writeMessageResponse
protected void writeMessageResponse(PrintWriter writer, jakarta.jms.Message message) throws jakarta.jms.JMSException, IOException - Throws:
jakarta.jms.JMSException
IOException
-
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.
-