org.hd.d.pg2k.webSvr.util
Class CompressionFilter

java.lang.Object
  extended by org.hd.d.pg2k.webSvr.util.CompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public final class CompressionFilter
extends java.lang.Object
implements javax.servlet.Filter

Implementation of javax.servlet.Filter used to compress the ServletResponse if it is bigger than a threshold.

We might need to modify this to suppress caching for HTTP/1.0 clients (eg by setting Pragma: no-cache and Expires: 0).

Version:
$Revision: 1.8 $, $Date: 2005/08/18 09:30:46 $
Author:
Amy Roh (original), Damon Hart-Davis

Field Summary
private static java.lang.String ANTI_DUP_ATTR_NAME
          Name of attribute that we use to avoid duplicate application of this filter on one filter chain.
protected  int compressionThreshold
          The threshold result size below which not to try to compress.
private  javax.servlet.FilterConfig config
          The filter configuration object we are associated with.
private  int debug
          Debug level for this filter.
(package private) static java.lang.String GZIP_TOKEN
          Encoding token indicating that GZIP compression is accepted.
private  WebUtils.ServletLoggerWithFallback logger
          Our logger which falls back to System.out if servlet log not available; never null.
private  java.lang.String overrideAttribute
          The name of the application-level attribute to disable compression if Boolean.FALSE, or null.
private  StatsLogger.StatsConfig statsIDCompression
          The stats set to which we log HTTP gzip-(un)compressed-transport counts.
 
Constructor Summary
CompressionFilter()
           
 
Method Summary
 void destroy()
          Take this filter out of service.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Filters the server operation.
 javax.servlet.FilterConfig getFilterConfig()
           
 void init(javax.servlet.FilterConfig filterConfig)
          Place this filter into service.
 void setFilterConfig(javax.servlet.FilterConfig c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GZIP_TOKEN

static final java.lang.String GZIP_TOKEN
Encoding token indicating that GZIP compression is accepted. The test should be case-insensitive and work if the client-supplied token starts with "x-".

See Also:
Constant Field Values

logger

private final WebUtils.ServletLoggerWithFallback logger
Our logger which falls back to System.out if servlet log not available; never null.


statsIDCompression

private final StatsLogger.StatsConfig statsIDCompression
The stats set to which we log HTTP gzip-(un)compressed-transport counts. This is one of three codes for:

We may enable or disable this logging (etc) from system parameters, but this is nonetheless our unique identifier.


config

private javax.servlet.FilterConfig config
The filter configuration object we are associated with. If this value is null, this filter instance is not currently configured.


overrideAttribute

private java.lang.String overrideAttribute
The name of the application-level attribute to disable compression if Boolean.FALSE, or null.


compressionThreshold

protected int compressionThreshold
The threshold result size below which not to try to compress.


debug

private int debug
Debug level for this filter.


ANTI_DUP_ATTR_NAME

private static final java.lang.String ANTI_DUP_ATTR_NAME
Name of attribute that we use to avoid duplicate application of this filter on one filter chain.

See Also:
Constant Field Values
Constructor Detail

CompressionFilter

public CompressionFilter()
Method Detail

getFilterConfig

public javax.servlet.FilterConfig getFilterConfig()

setFilterConfig

public void setFilterConfig(javax.servlet.FilterConfig c)

init

public void init(javax.servlet.FilterConfig filterConfig)
Place this filter into service.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - The filter configuration object

destroy

public void destroy()
Take this filter out of service.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Filters the server operation. The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed into this method allows the Filter to pass on the request and response to the next entity in the chain.

This method first examines the request to check whether the client supports compression.

It passes the request and response unaltered if there is no support for compression.

If compression support is available, this filter creates a CompressionServletResponseWrapper object which compresses the content and modifies the header if the content length is big enough. It then invokes the next entity in the chain using the FilterChain object (chain.doFilter()).

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.