The Battle of the GZip Filters
When I first added a Compression/GZip filter to AppFuse, I used the one from Roller, which I believe Lance found in this book. This has worked fairly well since I added it in July last year. When I discovered that there were issues with it on Resin, I chaulked it up as "no big deal" since I don't use Resin anyway. But yesterday, when I discovered that it stopped my apps from displaying my 403 <error-code> page, that was the last straw. I remembered seeing the "Two Servlet Filters Every Web Application Should Have" article on ONJava.com about a different implementation, so decided to download the source and try it out.
I quickly discovered that this Filter does work on Resin, so that's quite a bonus. I've had issues getting Roller to work on Resin with the Filter enabled, so I might have to replace Roller's CompressionFilter. However, I did still have to change a few things to convince this Filter to satisfy my needs.
Here are a few things I discovered about this GZIPFilter vs. Roller's CompressionFilter:
- Don't download the GZIPFilter from the article. There is a newer version of the code. Not much has changed, save for an almost completely re-written GZipResponseStream.java file. This one supposedly does better handling of large files.
- This Filter has the same problem I experienced with Roller's CompressionFilter: JSP pages don't finish rendering when running my Canoo WebTests. I'm assuming that this is because the buffer hasn't finished spitting out HTML. I ended up writing a new isGZIPSupported() method (in GZIPFilter.java) to do the check for GZip support. This allows my webtests to run smoothly by disabling the filter for HttpUnit.
- This Filter shares another issue that I found in the CompressionFilter yesterday. When my webapp returns an HttpServletResponse.SC_FORBIDDEN error code (from trying to access a method that denies the users role), the Filter suppresses the error and the user is not served up the 403 error page defined in my web.xml. To fix this, I overrode sendError() in GZIPResponseWrapper.java and added a check for this error code in the getWriter() method.
Overall, I'm pleased with this code because I love the concept of GZip Filtering, and now it's not causing any conflicts in my app or targeted appservers.
GZIPFilter.isGZIPSupported(HttpServletRequest):
private boolean isGZIPSupported(HttpServletRequest req) {
|
GZIPResponseWrapper.sendError(int, java.lang.String):
public void sendError(int error, String message) throws IOException {
|
GZIPResponseWrapper.getWriter():
public PrintWriter getWriter() throws IOException {
|
Posted by Will Gayther on January 09, 2004 at 06:59 PM MST #
Posted by Matt Raible on January 09, 2004 at 07:03 PM MST #
Posted by andi on January 09, 2004 at 07:11 PM MST #
This is a reasonable suggestion, but most developers I've talked to recently give me a blank stare when I mention gzip-filtering. For folks that use AppFuse as the basis of their apps, they can easily rip out the code and use their appserver's gzip-filter, I just want to provide at least <strong>one</strong> option.
Posted by Matt Raible on January 09, 2004 at 07:23 PM MST #
Posted by andi on January 09, 2004 at 08:24 PM MST #
Posted by Jay Dunning on January 09, 2004 at 10:06 PM MST #
Posted by Will Gayther on January 09, 2004 at 10:56 PM MST #
Posted by Matt Raible on January 10, 2004 at 12:04 AM MST #
Posted by Unknown on January 18, 2004 at 12:43 PM MST #
Posted by Richard Mixon on January 22, 2004 at 03:31 AM MST #
Posted by Matt Raible on January 22, 2004 at 02:11 PM MST #
It looks to me like appfuse is doing a forward in UserAction.java.
So will the HTML generated by the forward from UserAction.do to the JSP page be compressed?
Posted by Richard Mixon on January 22, 2004 at 04:48 PM MST #
Posted by Richard Mixon on January 22, 2004 at 04:49 PM MST #
Posted by Matt Raible on January 22, 2004 at 04:49 PM MST #
Posted by Lance on February 05, 2004 at 02:22 PM MST #