Hello, all,

I'm trying to find a way to modify the content of a servlet after the servlet
has completed all of its processing but before it actually gets sent to the
browser (obviously).

Here's the context. Our web site stores all its content in XML. All servlets,
jsps, and static files return this XML and what I'd like to do is turn it all
into HTML on the fly without each servlet, etc., having to worry about doing the
transformation itself. My naive first idea was to set the content-type to
text/cml (CML is the name of the markup language) and have a
CmlToHtmlInterceptor (extends BaseInterceptor) with a afterBody method that
would check the content-type and if it's text/cml, retrieve the contents (maybe
from a ByteBuffer), run it through an XSL engine, turning it into HTML and
sending that back after changing the appropriate headers (content-type,
content-length, etc.).

Here are my problems: 1) I don't understand the order in which the interceptor
methods are called. Should this be done in afterBody? postService? Is the
calling sequence documented anywhere? 2) I don't understand the relationship
between ByteBuffers and ServletOutputStreams. Or am I completely barking up the
wrong tree? Maybe what I mean to ask is how do I get the contents of a servlet
in a way that's suitable for modification? 3) This is incidental, but
Request.getContentLength() always gives me a -1 when called in afterBody and
postService. Request.getOutputBuffer().count (correctly) gives me 8192 (for the
small pages I've done). How/where do I get an accurate content-length?

One level up, does this seem like a reasonable way to do the transformation of
aggregate XML docs? I didn't want to make a TransformationServlet and have
everything forward requests off to it for a number of reasons -- orthogonality
being a prime one. On the other hand, my understanding of the Tomcat 3.1 code
base is spotty at best. I may have no idea what I'm doing. Any feedback would be
most appreciated!

Thanks,
     Alex


Reply via email to