• 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

Confusion regarding filters (HFSJ)

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
B Misra
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
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