tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Kean" <>
Subject What's the best way to meddle with a ServletOutputStream
Date Mon, 08 Oct 2001 03:17:27 GMT
I'm writing a valve that will automatically add headers and footers to
any web pages that Tomcat serves up. It seems to me that the way to do
this is to add a valve to one of the containers (say, the Engine level)
that replaces the ServletOutputStream in the response with a wrapper
around a ByteArrayOutputStream (similar to
...util.ssi.ServletOutputStreamWrapper), let the servlet process the
request, yank the data out of the Wrapper, tweak it, and write it to the
original ServletOutputStream.

Here are my questions:
1) Is this the Right Way to do it?
2) If so, do I just do something like:
  OutputStream oldStream = response.getStream();
  response.setStream(new SOSWrapper()); // BAOS wrapper that extends SOS
  invoke(request, response);
  StringBuffer sb = new StringBuffer(response.getStream().getBytes());
  sb.append("<!-- Hello World! -->");
  // drop off edge

Incidentally, part of the reason I'm curious about this is to increase my
of Tomcat, so please don't simply respond with "use JSSI".


View raw message