• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Confused about doFilter() - Filters and Wrappers Mock in HFSJ

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I got it all right until I came across question 5 on pg 703 in HFSJ:

For the benefit of those who do not have the book, the question is:

Which about filters are true?

E) A filter's doFilter() method must call doFilter() on the input FilterChain object in order to ensure that all filters have a chance to execute.

G) A filter's doFilter() may block further request processing.

I thought E is true and G is false.

The explanations given in the book:

E) Incorrect because doFilter() is not necessary if a filter wishes to block further request processing

G) This is correct

Could somebody give an explanation as to why E is false and G is true.

- If the rest of the filters in the chain should be executed, shouldn't the filter call the chain.doFilter() method? How can you ensure the rest of the filters are called without calling chain.doFilter()?

- Also, can a filter itself block further request processing?

- I read in the spec that "the filter chain can block the request by not making the call to invoke the next entity leaving the filter to fill the response object. and assumed that only a filter chain's doFilter() can block request not filter's doFilter(). Where am I going wrong?

Please help.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I read in the spec that "the filter chain can block the request by not making the call to invoke the next entity



The filter here refers to a chain of filters and NOT FilterChain class
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(E) is wrong since a filter may not call doFilter() on the FilterChain. It may generate the response itself and send back. According to (E) a filter has to compulsorily('must') call doFilter on the FilterChain to let other filters also have a chance of execution. In fact a filter can get the RequestDispatcher from the request and even forward it to other resource; this is rarely used though.

(G) very well specifies this.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic