Michael Ludwig schrieb am 12.11.2008 um 02:37:29 (+0100):
> But even with my Filter overriding both getOutputStream() and
> getWriter() and substituting buffers that will be written to, there is
> a problem. Servlet S will write to one buffer, and the DefaultServlet
> will write to another one. The place of the include set in the source
> code of S will be lost. Is this analysis correct?

I think the main problem here is starting to collect output in
substituted buffers of response wrappers and not calling the real
getWriter(), or getOutputStream(). Consider this example I've been
learning from:

The Essentials of Filters
http://java.sun.com/products/servlet/Filters.html

public class CharResponseWrapper extends
   HttpServletResponseWrapper {
   private CharArrayWriter output;
   public String toString() {
      return output.toString();
   }
   public CharResponseWrapper(HttpServletResponse response){
      super(response);
      output = new CharArrayWriter();
   }
   public PrintWriter getWriter(){
      return new PrintWriter(output);
   }
}

The problem with this implementation of getWriter() is that it doesn't
call the real implementation in order to force downstream servlets which
may try both of SOS and PW handling the IllegalStateException to do PW
in this case.

So the method should probably be:

   public PrintWriter getWriter() throws IOException {
      PrintWriter orig = super.getWriter();
      return new PrintWriter( output);
   }

That way, the DefaultServlet won't get away with calling
getOutputStream().

Michael Ludwig

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to