Class GZIPServletFilter

java.lang.Object
de.hybris.platform.util.GZIPServletFilter
All Implemented Interfaces:
javax.servlet.Filter

public class GZIPServletFilter extends Object implements javax.servlet.Filter
This class provides a servlet filter which adds gzip compression to the filtered servlets.
To use this filter, the three classes GZIPServletFilter, GZIPResponseWrapper and GZIPResponseStream are required.

To configure the application server to use this filter, you have to add appropriate <filter> and <filter-mapping> entries to the web.xml file of your web application. These should look like this:

        <filter>
        <filter-name>gzipfilter</filter-name>
        <filter-class>de.hybris.platform.jalo.util.GZIPServletFilter</filter-class>
 </filter>

 <filter-mapping>
        <filter-name>gzipfilter</filter-name>
        <servlet-name>hmc</servlet-name>
 </filter-mapping>
 

Note that you can use a different filtermapping depending on your need. If you want to zip all Struts actions and jsp files you can use

  <filter-mapping>
     <filter-name>profiling</filter-name>
     <url-pattern>*.do</url-pattern>
  </filter-mapping>
  <filter-mapping>
     <filter-name>profiling</filter-name>
     <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
 
  • Constructor Details

    • GZIPServletFilter

      public GZIPServletFilter()
  • Method Details

    • doFilter

      public void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
      This method does the actual filtering. It creates a custom ServletResponseWrapper which in turn uses a custom output stream/writer to do the gzip compression.
      All this is only done if the http client signals in the request header that it is capable of handling gzip compressed data (almost all modern browsers should do so).
      Specified by:
      doFilter in interface javax.servlet.Filter
      Throws:
      IOException
      javax.servlet.ServletException
    • init

      public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
      Specified by:
      init in interface javax.servlet.Filter
      Throws:
      javax.servlet.ServletException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface javax.servlet.Filter