File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Confusion regarding filters (HFSJ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Confusion regarding filters (HFSJ)" Watch "Confusion regarding filters (HFSJ)" New topic
Author

Confusion regarding filters (HFSJ)

B Misra
Greenhorn

Joined: Jul 27, 2007
Posts: 22
I am having two basic problems with HFSJ Filter's chapter:

1) In HFSJ in page 715 it says we can not just modify the response after call to chain.doFilter() as by when the execution pointer returns the request already have been posted back to the client as it do not wait for the filter method to finish. But in page 723 it is flushing the custom output stream after the call to chain.doFilter() - please explain where I am making a mistake?

2) In page 735 question no. 5 it says
"Filters may be used to create request or response wrappers" - Correct
"Wrappers may be used to create request or response filters." - Incorrect

Why??
i can see the 2nd statement is absurd but why the first one is correct!?


Thanks in advance.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

B Misra wrote:1) In HFSJ in page 715 it says we can not just modify the response after call to chain.doFilter() as by when the execution pointer returns the request already have been posted back to the client as it do not wait for the filter method to finish. But in page 723 it is flushing the custom output stream after the call to chain.doFilter() - please explain where I am making a mistake?


Both are correct. In your first query it is talking about a normal response object(HttpServletRespone) so the last component in the chain may flush (committed) the response before the control comes to the filter. In second query, when you have a wrapped object you are not flushing the actual response object but the wrapper object which wraps the actual response object . Did I get your question right?

2) In page 735 question no. 5 it says
"Filters may be used to create request or response wrappers" - Correct
"Wrappers may be used to create request or response filters." - Incorrect

i can see the 2nd statement is absurd but why the first one is correct!?


Because,inside the filter we create wrapper object and passes it to the chain.doFilter() method.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
B Misra
Greenhorn

Joined: Jul 27, 2007
Posts: 22
Vijitha Kumara wrote:
B Misra wrote:1) In HFSJ in page 715 it says we can not just modify the response after call to chain.doFilter() as by when the execution pointer returns the request already have been posted back to the client as it do not wait for the filter method to finish. But in page 723 it is flushing the custom output stream after the call to chain.doFilter() - please explain where I am making a mistake?


Both are correct. In your first query it is talking about a normal response object(HttpServletRespone) so the last component in the chain may flush (committed) the response before the control comes to the filter. In second query, when you have a wrapped object you are not flushing the actual response object but the wrapper object which wraps the actual response object . Did I get your question right?



Thanks for the reply Vijitha.
So in the first case the actual request object will always be committed before the execution returns to filter but in 2nd case writing to the custom response does not commit the actual response object within the custom response, until explicitly flushed?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Actually when you flushes the custom output stream in the filter (that is when the control returns to the filter) it'll flush the actual output stream (which it wraps) so the container will take care of it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion regarding filters (HFSJ)
 
Similar Threads
Doubt on Filters
Doubt in Filters HFSJ
Confusing terminology: Filter and Wrapper
Filters
Question 5 of Chapter 13