javawebparts.filter
Class CompressionFilter
java.lang.Object
|
+--javawebparts.filter.CompressionFilter
- All Implemented Interfaces:
- javax.servlet.Filter
- public class CompressionFilter
- extends java.lang.Object
- implements javax.servlet.Filter
This filter allows for compressing the response from the server.
It allows for including or excluding paths from filter functionality. It
also allows for defining what type of compression should be used, if
supported by the client, and in what order.
Init parameters are:
- pathSpec - Either "include" or "exclude". This determines whether
the list of paths in the pathList parameter is a list of paths to include in
filter functionality, or a list of paths to exclude. Required: No.
Default: None.
- pathList - This is a comma-separated list of paths, which can use
asterisk for wildcard support, that denotes either paths to include or
exclude from the functioning of this filter (depending on what pathSpec
is set to). The paths ARE case-senitive! There is no limit to how many
items can be specified, although for performance reasons a developer will
probably want to specify as few as possible to get the job done (each
requested path is matched via regex). Note also that you are of course
still required to specify a path for the filter itself as per the servlet
spec. This parameter however, together with pathSpec, gives you more control
and flexibility than that setting alone. Required: No. Default: None.
General note on pathSpec and pathList: If pathSpec is not specified but
pathList IS, then 'exclude' is assumed for pathSpec. If pathSpec is
specified by pathList IS NOT, then the filter WILL NEVER EXECUTE (this is
technically a misconfiguration). If NEITHER is defined then the generic
filter mapping will be in effect only.
- compressType - What type of compression to perform. The valid
values are 'gzip_only' (GZip will be used, if supported), 'deflate_only'
(Deflate will be used, if supported), 'gzip_first' (GZip will be used if
supported, otherwise Deflate will be used, if supported), 'deflate_first'
(Deflate will be used if supported, otherwise GZip will be used if
supported). Required: Yes. Default: None (must be one of the valid values).
Example configuration in web.xml:
<filter>
<filter-name>CompressionFilter</filter-name>
<filter-class>javawebparts.filter.
CompressionFilter</filter-class>
<init-param>
<param-name>pathSpec</param-name>
<param-value>include</param-value>
</init-param>
<init-param>
<param-name>pathList</param-name>
<param-value>*/bigimage2.gif</
param-value>
</init-param>
<init-param>
<param-name>compressType</param-name>
<param-value>gzip_first</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CompressionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Author:
- Frank W. Zammetti.
Field Summary |
private java.lang.String |
compressType
What type of oompression we want this filter to do. |
private static org.apache.commons.logging.Log |
log
Log instance. |
private java.util.ArrayList |
pathList
List of paths for filter functionality determination. |
private java.lang.String |
pathSpec
Whether pathList includes or excludes. |
Method Summary |
void |
destroy()
Destroy. |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain filterChain)
Do filter's work. |
void |
init(javax.servlet.FilterConfig filterConfig)
Initialize this filter. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
log
private static org.apache.commons.logging.Log log
- Log instance.
pathSpec
private java.lang.String pathSpec
- Whether pathList includes or excludes.
pathList
private java.util.ArrayList pathList
- List of paths for filter functionality determination.
compressType
private java.lang.String compressType
- What type of oompression we want this filter to do. Valid values are
"gzip_only", "deflate_only", "gzip_first" and "deflate_first". If
neither compression type is supported by the client, no compression is
attempted. If the client supports both and this option is "gzip_first",
GZip be used if it is supported, or Deflate if not, and the exact
opposite is true when "deflate_first" is used. If set to "gzip_first"
but only Deflate is supported, Deflate will be used, and vice-versa.
CompressionFilter
public CompressionFilter()
destroy
public void destroy()
- Destroy.
- Specified by:
destroy
in interface javax.servlet.Filter
init
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
- Initialize this filter.
- Specified by:
init
in interface javax.servlet.Filter
- Parameters:
filterConfig
- The configuration information for this filter.
- Throws:
javax.servlet.ServletException
- ServletException.
doFilter
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain filterChain)
throws javax.servlet.ServletException,
java.io.IOException
- Do filter's work.
- Specified by:
doFilter
in interface javax.servlet.Filter
- Parameters:
request
- The current request object.response
- The current response object.filterChain
- The current filter chain.
- Throws:
javax.servlet.ServletException
- ServletException.
java.io.IOException
- IOException.
Copyright © 2005 Frank W. Zammetti