aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes compression filter and wrapper from hfsj doubt ? 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 "compression filter and wrapper from hfsj doubt ?" Watch "compression filter and wrapper from hfsj doubt ?" New topic
Author

compression filter and wrapper from hfsj doubt ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

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. ?

Sebastien French
Greenhorn

Joined: Jan 04, 2012
Posts: 26

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
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

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

Joined: Apr 04, 2012
Posts: 924
    
    1

thanks alot Fritz.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compression filter and wrapper from hfsj doubt ?