aspose file tools*
The moose likes Servlets and the fly likes Interrupting a filter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Interrupting a filter" Watch "Interrupting a filter" New topic
Author

Interrupting a filter

crix madine
Greenhorn

Joined: Jul 07, 2008
Posts: 6
I have the following scenario :

A 3rd party filter (and therefore not modifyable through me) usually handles all requests and responses coming and going to a certain path like

/tobefiltered/*

On certian occasions I just want to filter to request data , but not the response ... Is there any way to intererupt the filterchain so that the response can be sended out without this filter handling it ?

Best regards !
David Howie
Greenhorn

Joined: Jan 26, 2010
Posts: 11
I don't think you can interrupt the filter chain. But you could implement your own filter that is invoked for the same path, and put your filter in the chain prior to 3rd party filter. Your filter would receive the response from the 3rd party filter and could then manipulate the response as desired.

Dave
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

A 3rd party filter (and therefore not modifyable through me) usually handles all requests and responses coming and going to a certain path like


If you can reconfigure the filter chain, David's approach should work. Do you have access to web.xml ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
crix madine
Greenhorn

Joined: Jul 07, 2008
Posts: 6
Can I modify the HttpServletRequest ServletPath through a filter ? I am not quite sure where to find it, the object itself only provides a getter ...
David Howie
Greenhorn

Joined: Jan 26, 2010
Posts: 11
I'm not familiar with any way to change the servlet path, why would you want to do so? If you do not want the 3rd party filter to be invoked than you can bypass it by having your filter skip invocation of the FilterChain.doFilter method. Of course doing so would also mean that the servlet that is to handle the request will not be invoked. The following is my understanding of the flow:

Web Container --> Your Servlet Filter --> 3rd Party Servlet Filter --> Servlet

The way the chain is continued is by each servlet filter invoking the doFilter method on the FilterChain instance that is passed to the filter's doFilter method. Once the servlet has completed processing then the flow returns back up the chain.

Dave
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Interrupting a filter