MDServlet provides a highly configurable servlet interface for the MDSAX toolkit from JXML.com, distributed under an open source (BSD-type) license. Using MDServlet, developers can build sites that serve XML and transform XML documents using components, without ever needing to learn about the internals of the Simple API for XML (SAX). MDSAX provides a framework for working with SAX-based parsers and parser filters, describing their structures using simple XML documents. MDServlet provides a servlet-based interface that makes those documents and processing structures readily available to developers (and users, to some extent.)
To use MDServlet, you need:
MDServlet provides an interface between an HTTP server and MDSAX, allowing developers and possibly users to specify the set of filters used to process a document before it is transmitted from the server to the user. For the most part, this is useful with transformations, but it could also be useful for dealing with issues like extracting linking information from a large number of documents.
For the most part, MDServlet collects parameters and passes them to an instance of MDModule, which sets up the filter stack, processes the document, and keeps track of the information it returns. MDServlet retrieves the information it wants from the resultMap, and sends it on to the user, as shown in the figure below. (In my current examples, that information is XML, but with a different set of filters, that information could be nearly any collection of information.)
MDServlet provides a middle layer between a highly configurable MDSAX filter tree and an HTTP servlet interface.
MDServlet is intended to serve as a foundation for connecting MDSAX to HTTP servers, but I recognize that its generic structure may not be appropriate for many tasks. Part of the joy of open source, of course, is that you can take this code and subclass or modify it easily. If you need to add user authentication, session management, or other features to MDSerlvet to make it fit your needs, you're quite welcome to do so.
MDServlet is managed through the use of parameters set in the servlet administration tool. MDServlet can be configured to accept configuration information through GET and POST queries, or locked down to use a preset group of parameters.
The parameters available are:
|contentType||The MIME type that will be used for the Content-type header. Currently defaults to text/xml. (May change to application/xml in future versions.) Specifying a different value is useful if your servlet is sending out something besides XML. I use text/plain when testing, personally, as it lets me look at the XML to make sure transformations took place as expected.|
|baseURL||The location where the server should look to find the application boot information, the application processing structure, and possibly the application target documents. Optional - I just find it easier than typing this info in for each parameter.|
|appBootURL||The boot context URL that tells MDSAX which Java classes correspond to which elements in the next phase of building the filter stack.|
|contextURL||The ContextML document that describes the filter stack that should be used to process the document specified by the appURL.|
|appURL||The document that's actually going to be processed and from which results will be generated and sent to the user.|
|appBootURLParamName||A query parameter name that MDServlet can use in place of the appBootURL parameter set in the server administration program, if permitted to by the acceptAppBootURL parameter below.|
|contextURLParamName||A query parameter name that MDServlet can use in place of the contextURL parameter set in the server administration program, if permitted to by the acceptContextURL parameter below.|
|appURLParamName||A query parameter name that MDServlet can use in place of the appURL parameter set in the server administration program, if permitted to by the acceptAppURL parameter below.|
|returnName||MDServlet currently relies on the MDSAX Display element to get its output, rather than building it from SAX events. This identifies which object in the resultMap generated by processing should be returned to the user. Currently defaults to 'result'.|
|acceptAppBootURL||If set to true, MDServlet will accept parameters from user requests that change the application boot URL. Otherwise, these parameters are ignored.|
|acceptContextURL||If set to true, MDServlet will accept parameters from user requests that change the context URL. Otherwise, these parameters are ignored.|
|acceptAppURL||If set to true, MDServlet will accept parameters from user requests that change the application URL. Otherwise, these parameters are ignored.|
|acceptGet||If set to true, MDServlet will accept HTTP GET requests.|
|acceptPost||If set to true, MDServlet will accept HTTP POST requests.|
|useBaseURLforQueries||If set to true, MDServlet will prefix the parameters sent by users for appBootURL and contextURL with the baseURL parameter value.|
To see how some of these parameters work, as well as some inputs and outputs, see my sample configuration with Jigsaw.
While this version of MDServlet works, there's a lot of room for potential improvement.
Sound interesting? Download now!
Note on the License: I normally use the Mozilla Public License on open source tools I develop, but in this case I'm using a BSD license to match the licensing of MDSAX. You need to remember to enclose both license notices, but the rules regulating the distribution of MDSAX and MDServlet are identical.
Last updated 3/26/99