• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic