David Cohrs wrote:

> Craig R. McClanahan wrote:
> > * You will need to create a wrapper class for the response
> >   that is handed on to the remainder of the filter chain.  See
> >   below for more info on what this wrapper must do.
> >
> > * Implement your Filter's doFilter() method something like this:
>
> I was under the impression that in Tomcat 4 one could use the new Valve
> interface for doing response filtering?  At least, this is what the
> documentation I read says.  I was about to embark on an exploration of this
> functionality.
>

You could, but the same basic thing would be necessary -- you'd need to wrap the
internal representation of a response to do this.  Filters and Valves share a
similar programming model.

The disadvantage would be that a Valve implementation would be Tomcat-specific,
whereas a Filter implementation would be portable.  In general, I would
recommend using a Valve *only* when a Filter cannot do what you need.  An
example of this is implementing the equivalent of Apache's mod_rewrite module --
because you want to be able to modify the request URI before it is parsed to
select which servlet to run, you cannot do this in a Filter.

>
> Am I misinterpreting the documentation?  Does this approach of a required
> wrapper class still apply to Tomcat 4?

Yep.  Otherwise, when the JSP page (or servlet) writes to the thing returned by
response.getWriter(), it will be writing directly to the underlying socket and
you will not have a chance to post-process the data.

>
> In either case, an example would be *really* helpful!

Definitely.

The example I'm thinking about doing is a response filter that does
GZIP-compression on the fly if the incoming request says that this is supported,
and the response is over a configurable size limit.

Craig McClanahan

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

Reply via email to