Sorry, forgot the promised attachment...

Jake

At 04:46 PM 3/13/2003 -0600, you wrote:

I've mentioned this issue before regarding a GZIPFilter that wasn't working under Tomcat except for static file content (not working for JSP's and servlets).  However, I didn't get much response to that and it was probably due to the complexity of the problem.  Well, here is a simplied approach to the issue....

I am seeing vastly differing behavior for this filter depending on whether it is filtering static content or JSP's and servlets and it seems to me that this differing behavior must be a bug in Tomcat.  Can someone validate whether or not this is a Tomcat bug?

Here is the code in question.  Note that I have some comments in the code that explain what works, what doesn't so read that to get an idea of what I am talking about.  I have attached all the code in question, but this is the meat of it (based on the tutorial at http://www.orionserver.com/tutorials/filters/3.html ).

public class PrePostFilter extends GenericFilter {

    public void doFilter(final ServletRequest request,
                         final ServletResponse response,
                         FilterChain chain)
                                throws IOException, ServletException {

        PrintWriter out = response.getWriter();

        //works as expected for static html, but not for JSP's where original content is discarded
        //GenericResponseWrapper wrapper = new GenericResponseWrapper((HttpServletResponse) response);

        //works as expected for both static html and JSP's
        CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response);

        chain.doFilter(request, wrapper);
        String responseString = wrapper.toString();
        responseString = "<HR>PRE<HR>" + responseString + "<HR>POST<HR>";
        response.setContentLength(responseString.length());
        out.write(responseString);

/*
        //works as expected for JSP's, but not static html where everything but the "POST" data is written
        out.write("<HR>PRE<HR>");
        CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response);
        chain.doFilter(request, wrapper);
        out.write(wrapper.toString());
        out.write("<HR>POST<HR>");
*/

        out.flush();
        out.close();
    }

}

Questions to answer...

1.  Why don't all 3 examples produce exactly the same output?  It seems to me that they should.
2.  Why does using a response wrapper that uses a ByteArrayOutputStream (as in GenericResponseWrapper) not work with JSP's?  The original data is always unavailable.
3.  Why do I have to use a PrintWriter when filtering JSP's?  Why can't I use an OutputStream?  Using an OutputStream gets me the same results as #2.

So, is there anything wrong with my code or is something just goofy in Tomcat?

Jake


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: fitlerstuff.zip
Description: Zip archive

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to