The JavaEE API comes with the HttpServletResponseWrapper which, to quote the javadoc, "provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet." Without subclassing, this class just passes all calls through to the wrapped response object. There's a similar wrapper for requests.
Can anyone point me at any utility libraries that provide useful subclass implementations of these classes? Particularly, I'm looking for a subclass of the response wrapper that captures the written response (as a String, byte[], whatever's appropriate) and exposes it via an API method.
I've written a rather half-baked version myself, but frankly, I shouldn't have to, and I'd rather throw it away and use one off the shelf.
Best Answer
I am not aware of any implementation, even though the gzip example can be adapted easily by just writing to a ByteArrayOutputStream. You can also take ideas by looking at other response wrapper implementations at:
Original answer:
There is the classic article in JavaWorld Filter code with Servlet 2.3 model. You can find examples for wrapped request and response:
Compression the response
Handling file upload
The code is a bit old (june 2001!), but it demonstrate the usage well.