• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compression filter and wrapper from hfsj doubt ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please refer hfsj book 2nd edition page 715. it talks about compression filter and how to implement it. below is the basic structure the book shows

public void doFilter(request, response, chain) {
// this is where request handling would go
chain.doFilter(request, response);
// do compression logic here
}

further the book says that in the servlet when we write something to response object it goes through the container straight to client and filter DOES NOT get shot in doing the compression logic. i couldnt understand this. i made a small test program as shown below




in the above example the output we get is before chain this is from servlet after chain. this means that after the servlet writes to response , the filter gets another shot and is able to write the output. so that means the as the book says the output DOES NOT goes to client. so that means the filter can do the compression logic right away after doFilter chain call. but turning few pages the book says we need to use wrapper and all that stuff. where i'm wrong. ?

 
Greenhorn
Posts: 26
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

If at request time you pass through filters A, B and C, you can be sure that on response time you'll pass by C, B and A
Actually that's not really true, if filter C decide to throw an error, you'll not pass through B and A.

In Charles Lyons's book, I read that before filter feature exist, that kind of task (compression by example) was handle by wrappers.
I think you can use wrappers but it's better to use filter for compression.

Sébastien
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gurpeet Singh,

in the above example the output we get is before chain this is from servlet after chain. this means that after the servlet writes to response , the filter gets another shot and is able to write the output.


Yes, you are able to write to the response, but you can't really get to the rest of the output inside the response.

The book explains it like this:

By the time the filter's own doFilter() method is at the top of the (conceptual) stack, it's too late for the filter to affect the output.


You can't really do anything else with the response than write to the end of the buffered characters (you can't for example reverse the characters inside the response buffer).

Regards,
Frits
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot Fritz.
 
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic