Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter Question

 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which about filters are true? (Choose all that apply.)
A. Filters may be used to create request or response wrappers.
B. Wrappers may be used to create request or response filters.
C. Unlike servlets, all filter initialization code should be placed in the constructor since there is no init() method.
D. Filters support an initialization mechanism that includes an init() method that is guaranteed to be called before the filter is used to handle requests.
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.
F. When calling doFilter() on the input FilterChain, a filter’s doFilter() method must pass in the same ServletRequest and ServletResponse objects that were passed into it.
G. A filter’s doFilter() may block further request processing.

I took this question from Head First SCWCD book.

The correct answers are ;

ADG

but I think the E is also correct ? Why E is not correct ?
 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
in HFSJ some where it said it is not a need to doFilter() on the input FilterChain object within doFilter

hmm check out errata http://oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596516680
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not mandatory to call the next filter in the chain. The filter can decide whether to call the next filter in the chain.

For eg:
There are two different filters for authentication and authorisation. The authentication filter needs to call the authorisation filter only if the principal is authenticated.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But answer E clearly states that is merely necessary if you want to make sure all filters are called. And since a filter cannot know how many more filters will follow, I agree that calling doFilter on the FilterChain object is the only way to ensure that all filters have a change to execute.
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we can interpret the statement E in two ways

1) If we want to ensure that all filters have a chance to execute, a filter’s doFilter() method must call doFilter() on the input FilterChain object.

2) It is mandatory for a filter to call doFilter() on the input FilterChain object. This is to ensure that all filters have a chance to execute.

If we interpret it in the first way (1), the statement is true. If we interpret it in the second way(2), the statement is false. I think the person who made that question meant the second one.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why people design question like this which has no similar comment by two people. is this a kind of abtract way of desiging a question
 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hahahaha .....



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic