Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FilterChain.doFilter(), what if I don't call this in Filter.doFilter()'s impl?

 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FilterChain.doFilter() method is called somewhere in the Filter.doFilter() method's implementation. What if I don't call at all?

-- Srikanth
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The request processing will stop in the Filter.doFilter() method. It will not call next filter/resource in the chain.

Thanks
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Narendra! But will the Servlet be called? (If there's a matching Servlet/JSP is found for that URL pattern) Sounds like a stupid question and I guess it will, am I right?

-- Srikanth
 
Jan van Mansum
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following example. Run it first with no query string, then with the parameter interrupt=yes. (E.g, http://localhost/InterruptionFilterSample/index.jsp?interrupt=yes).



What do you see?
Why do you think it is called a FilterChain?
[ November 14, 2007: Message edited by: Jan van Mansum ]
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srikanth Raghavan:
Thanks Narendra! But will the Servlet be called? (If there's a matching Servlet/JSP is found for that URL pattern) Sounds like a stupid question and I guess it will, am I right?

-- Srikanth

Hi,

The FilterChain is built if the matching resource(Servlet/JSP) is found. If you do not call the doFilter method in the filter doFilter method, it means that you want to stop the processing and do not want to process the next filter or servlet or JSP. For example, you are writing the Security filter and do not want to process the Servlet/JSP if the user is not authenticated, then you can terminate the processing of request in the filter itself by not calling the FilterChain.doFilter method.

Hope this help

Thaks
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Narendra and thank you Jan van Mansum for the wonderful example. Gonna take the exam on Saturday (tomorrow). I did the final Mock exam from HFSJ yesterday and I got 43 out of 69. I hope to get through the exam.

-- Srikanth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic