Package org.apache.activemq.web
Class MessageListenerServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.activemq.web.MessageServletSupport
org.apache.activemq.web.MessageListenerServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
- Direct Known Subclasses:
AjaxServlet
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Supports a HTTP DELETE to be equivlanent of consuming a singe message from a queueprotected voiddoMessages(AjaxWebClient client, 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 destination or manage subscriptions.protected AjaxWebClientgetAjaxWebClient(jakarta.servlet.http.HttpServletRequest request) protected longgetReadTimeout(jakarta.servlet.http.HttpServletRequest request) voidinit()protected voidwriteMessageResponse(PrintWriter writer, jakarta.jms.Message message, String id, String destinationName) 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
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log
-
Constructor Details
-
MessageListenerServlet
public MessageListenerServlet()
-
-
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 or manage subscriptions. If the the content type of the POST isapplication/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 notapplication/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:
doPostin classjakarta.servlet.http.HttpServlet- Parameters:
request-response-- 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 equivlanent of consuming a singe message from a queue- Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doMessages
protected void doMessages(AjaxWebClient client, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.jms.JMSException, IOException Reads a message from a destination up to some specific timeout period- Parameters:
client- The webclientrequest-response-- Throws:
jakarta.servlet.ServletExceptionIOExceptionjakarta.jms.JMSException
-
writeMessageResponse
protected void writeMessageResponse(PrintWriter writer, jakarta.jms.Message message, String id, String destinationName) throws jakarta.jms.JMSException, IOException - Throws:
jakarta.jms.JMSExceptionIOException
-
getAjaxWebClient
-
getReadTimeout
protected long getReadTimeout(jakarta.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:
destroyin interfacejakarta.servlet.Servlet- Overrides:
destroyin classjakarta.servlet.GenericServlet
-