tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hassan Schroeder" <>
Subject Re: enabling/disabling a servlet filter conditionally
Date Fri, 01 Aug 2008 21:32:37 GMT
On Fri, Aug 1, 2008 at 1:39 PM, André Warnier <> wrote:

> Can one dynamically disable a servlet filter under some conditions, from
> within another preceding filter ?

> And suppose that I control the code of filter A but have no access to the
> code of filter B, and filter B has no parameter allowing to make it
> conditional.
> Can I, from within filter A, which gets to see the request first, based on
> some characteristic of the request, decide that for this request I want to
> disable (or short-circuit or bypass) filter B ?

You could /probably/ -- untested conjecture -- break the FilterChain at
that point by forwarding to a URL for which Filter B wasn't applied (or
was applied only to a REQUEST rather than FORWARD.

Or possibly hack the FilterChain itself -- non-portable at best.

The first is probably more reasonable :-)  Read the 2.5 Servlet Spec
chapter on Filters, if you haven't already.

> - and/or, suppose that for filter C I would also have access to the code,
> could I design some mechanism whereby filter A could "tell" filter C not to
> do anything for this request ?

That's an easy one: just have Filter A add a request attribute that
Filter C uses to determine what action to take.

if ( ((String)request.getAttribute("askNicely")).equals("please") ) {

Hassan Schroeder ------------------------

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

View raw message