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

Doubts in the answers of Filter chapter of HFSJ

 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a few doubts in HFSJ's Filters and Wrappers chapter-end questions.

Q1:
Which are true about filters?

A. A filter can act on only the request or response object, but not both.
B. The destroy method is always a container callback method.
C. The doFilter method is always a container callback method.
D. The only way a filter can be invoked is through a declaration in the DD.
E. Some wrong option...

I thought the answers are: B, C, and D but C is a wrong option and the explanation the book gives is: doFilter is both a callback and an inline method. Can someone explain me the meaning?

And the other doubt that I have is Question number 5.

Q5:

Which about filters are true?

A. Some option...
B. Some option...
C. Some other option...
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. One more option...

I thought option D is correct, but why is it wrong and no explanation is provided which means I am missing an obvious point here.

Thanks in advance,
Srikanth
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is a wrong option and the explanation the book gives is: doFilter is both a callback and an inline method. Can someone explain me the meaning?

the anwer lies in your statement - "its both

a callback method - doFilter(ServltReq, ServlRes, FilterChain)
called by container when your method recieves
a request
a inline metohd - chain.dofilter(req,res)
you call it @ the end of your doFilter metohd.

so, it not ALWAYS A CALLBACK methd
but C says its ALWAYS a CALLBACK METHOD !

got it ?
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Niranjan,

But don't you think that the explanation is obscure? They said doFilter but didn't say from which Interface (Filter or FilterChain). OK, there is a destroy() method over there but that's from the Filter interface so I assumed that they are referring to Filter.doChain method. But in the end, according to your explanation chain.doFilter is inline but this doFilter is from the FilterChain interface.

Am I making sense?
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They said doFilter but didn't say from which Interface (Filter or FilterChain).


yes i too went wrong on the same question when re-reading the book
but now
since
i have told...
you should be ocmfortable !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic