- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- Direct Known Subclasses:
- QServlet
public class MessageServlet
extends javax.servlet.http.HttpServlet
MessageServlet is a servlet for generic message services. It allows a message
service running inside the servlet container as a web application. As a web
application, the message service can receive JMS messages directly from web
clients and sends messages back on HTTP. Therefore, MessageServlet is the
frontend and the gateway for message services. It is responsible for
transformation between the HTTP requests/responses and JMS messages.
MessageServlet has 6 rulesets referenced by the URL path. The first one is
/jms for receiving event postables as the JMS TextEvents. The second is
/collectible for receiving event postables from the client and transforming
them to the collectible JMS TextEvents. The next is /event for receiving
event postables as the non-JMS events. The pre-configured RestURI is for the
ruleset to convert simple REST requests to JMS TextEvents. In this ruleset,
the path of /json or /xml is for posted JSON or XML data from a client.
The path of /stream is for downloading binary content from JDBC datasources,
The rest of paths are for ad hoc HTML form requests. When a web request hits
one of the URLs, the corresponding ruleset will be invoked to process the
incoming request. MessageServlet supports POST, GET and PUT methods. For
POST or PUT, those headers matched with HeaderRegex will be copied into the
message. One of examples with HeaderRegex is "^[Xx]-.+$" that matches all
HTTP headers of starting with "X-". In case of POST, it also supports file
upload or raw content such as xml or json.
A collectible TextEvent is a TextEvent with its message body set to the
collectible format of the original message. It is meant to be sent to remote
destinations. In order to get content of the original message, the remote
consumer will have to parse the message body with the EventParser.
For ad hoc form requests, MessageServlet treats them in two different ways.
If the attribute of view is defined in the request and it is not empty, the
request will be converted into a TextEvent. Otherwise, if the attribute of
name is defined and it is not empty, the request will be converted to an
Event. If neither view nor name is defined, the ad hoc request will be
dropped as a bad request. Further more, if the attribute of URI is defined
and it is not empty, the request Event will be packed into collectible.
Once an incoming request is transformed into message, MessageServlet will
invoke doRequest() of the assigned service to process the message as the
request. After the process is done, the message is supposed to have the
response loaded. MessageServlet will convert it back to the HTTP response
and sends the response back to the HTTP client.
- Author:
- yannanlu@yahoo.com
- See Also:
- Serialized Form