Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interrupting a filter

 
crix madine
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
crix madine
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic