aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes FilterChain.doFilter(), what if I don't call this in Filter.doFilter()'s impl? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "FilterChain.doFilter(), what if I don Watch "FilterChain.doFilter(), what if I don New topic
Author

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

Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
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

Joined: Dec 04, 2004
Posts: 950
Hi,

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

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
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

Joined: Oct 19, 2007
Posts: 74
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 ]

SCJP 1.4, SCWCD 1.4
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
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

Joined: Oct 31, 2005
Posts: 389
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: FilterChain.doFilter(), what if I don't call this in Filter.doFilter()'s impl?
 
Similar Threads
Puzzled by filter response object
How to configure Filter so that it will only process request but not response
Call back and inline functions
doFilter method
Set Reponse Headers Problem