tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hassan Schroeder" <hassan.schroe...@gmail.com>
Subject Re: enabling/disabling a servlet filter conditionally
Date Fri, 01 Aug 2008 22:48:30 GMT
On Fri, Aug 1, 2008 at 3:30 PM, André Warnier <aw@ice-sa.com> wrote:

>> 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.
>>
> On second read, can you elaborate on that one ?
> Do I understand correctly, as follows ?

> b) make filter A, in case it doesn't want filter B to run, change the
> request URL to, e.g., "something.abc",

yes, with the caveat that "change the request URL" means use  a
RequestDispatcher to forward the request.

The second approach which might be less obtrusive, means to define
your Filters so that Filter B is only applied to REQUESTs, e.g.

<filter-mapping>
  <filter-name>Filter_B</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

When Filter A sees the condition where Filter B should not be
applied, it forwards the request to the original request URL; now
Filter B is not part of the FilterChain because it's not a REQUEST.
Actually, you could probably do the same with Filter A, since you
presumably wouldn't need it to act on the request a second time.

Again, untested, but easy enough to try, and you don't need to make
any filename/URL-pattern changes as with the first approach.

HTH,
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message