tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: [Http]ServletResponseWrapper.getOutputStream()
Date Tue, 25 Nov 2008 14:31:45 GMT
Hash: SHA1


Michael Ludwig wrote:
> Your argument in favour of the unified buffer sounds perfectly logical
> to me. In the end, it's all bytes that get written, regardless of
> whether or not I wrap a PrintWriter around the buffer.

There's always the case that some output has been written before your
filter has been called. In that case, you have to make sure that your
output goes to the correct place. That may mean turning your Writer
contents into an OutputStream, or vice-versa. I think it's simpler to
wrap whichever object the caller is actually requesting.

> I possibly also have to make sure to play by the same rules as the real
> implementation and not allow both getWriter() and getOutputStream() on
> the same resonse.

That's not hard: just make sure you call the wrapped request's getWriter
or getInputStream from your own implementations of the same methods.

> And what do you mean by "caching" it? Just keeping it in an instance
> variable, instead of erroneously creating a new one for each call of
> getWriter(), as I first did?


> I agree: You never know. And who knows what stuff gets set or tweaked in
> Tomcat's internals for each one of getWriter() and getOutputStream(). On
> the other hand, I haven't found any statement to the effect that you
> have to pass through the calls to the underlying response object.

No, you don't have to do this, but the benefit of doing it is that you
have the wrapped request enforcing the "call either getWriter or
getInputStream" requirement.

The rule in filters is: only implement what you actually need. Wrap,
baby, wrap. ;)

- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message