• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubt about HFSJ chapter 13 mock question 5

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This mock question is asking which of the following statements (among others) is correct:

A. Filters may be used to create request or response wrappers.
B. Wrappers may be used to create request or response filters.

I think that when you create Filter, you use wrappers to do some custom work, hence "Wrappers may be used to create request or response filters".

So I chose B, but the answer is A. I don't understand why it is A. Please help with this one.

Thanks
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by liao Yang:

I think that when you create Filter, you use wrappers to do some custom work, hence "Wrappers may be used to create request or response filters".

So I chose B, but the answer is A. I don't understand why it is A. Please help with this one.


Few things:
(1) There is no such thing request/response filters, only request/response wrappers.
(2) You don't create filter nor does any other custom objects including wrappers, the server does it.
(3) Filter creates wrappers around request/response to do custom work.

So the correct answer must be A.
 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Duc.

That's clear.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me for digging up an old topic, but I'm currently in the process of learning to the SCWCD. I have the same doubt - why is A the correct answer? Duc explained, why B isn't correct - that's fine.
But how can you say, that "Filters may be used to create request or response wrappers."?
Your hint, Duc, labelled as 3, doesn't help very much. Even if filter code creates wrappers while it's running, it doesn't mean that "Filter may be (or is) used to create wrappers". Let me draw you an analogy:
- Craftsman creates tools to do his work
therefore
- tools are created by a craftsman
Would you say that craftsmen may used to create tools? Shouldn't you rather say that, "wood may be used to create tools"?

This whole question (5/Chapter 13) is so unclear, that really lost my nerve with it. E answer is labelled incorrectly as wrong, even though it is right in fact.
It says clearly that "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."
And it's correct - if you really want to ensure that all filters have a chance to execute, you MUST call doFilter on the FilterChain.

Also question 1 in this chapter is a bit unclear to me. It has an answer D, stating that:
"The only way a filter can be invoked is through a declaration in the DD."
What about invoking a filter through a doFilter(r,r,c) call?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrzej.

Filters may be used to create request or response wrappers.


It possible to create request and response wrapper objects by using servlets, custom tags, EL functions and Filters. I think authors keep this in mind and used 'may be' (Filters may be used to create request or response wrappers).

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.


I think its correct.

The only way a filter can be invoked is through a declaration in the DD.


It is true. When client made request, the container decides which filter will call first and which is second and third etc. According to this mapping the FilterChain's doFilter() method call's the next filter.
 
Andrzej Maslowski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chinmaya,
thanks for your answer.

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.


I think its correct.


So we're both positive about the subject. I found that someone has posted an errata to this question, but it's still in 'unconfirmed' state.
page 735: http://oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596516680

The only way a filter can be invoked is through a declaration in the DD.


It is true. When client made request, the container decides which filter will call first and which is second and third etc. According to this mapping the FilterChain's doFilter() method call's the next filter.


Ok, I get your point. I wasn't that sure by the time of taking this mock though. I hope questions will be clearer on the final exam.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic