View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
5    *               Keith Naas <knaas@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 3 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, see
19   * <http://www.gnu.org/licenses/>.
20   */
21  package org.jumpmind.symmetric.web;
22  
23  import java.io.IOException;
24  
25  import javax.servlet.FilterChain;
26  import javax.servlet.FilterConfig;
27  import javax.servlet.ServletException;
28  import javax.servlet.ServletRequest;
29  import javax.servlet.ServletResponse;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.jumpmind.symmetric.common.ParameterConstants;
34  
35  /***
36   * 
37   * Configured within symmetric-web.xml
38   * 
39   * <pre>
40   *  &lt;bean id=&quot;compressionFilter&quot;
41   *  class=&quot;org.jumpmind.symmetric.web.CompressionFilter&quot;&gt;
42   *    &lt;property name=&quot;regexPattern&quot; value=&quot;string&quot; /&gt;
43   *    &lt;property name=&quot;regexPatterns&quot;&gt;
44   *      &lt;list&gt;
45   *        &lt;value value=&quot;string&quot;/&gt;
46   *      &lt;list/&gt;
47   *    &lt;property/&gt;
48   *    &lt;property name=&quot;uriPattern&quot; value=&quot;string&quot; /&gt;
49   *    &lt;property name=&quot;uriPatterns&quot;&gt;
50   *      &lt;list&gt;
51   *        &lt;value value=&quot;string&quot;/&gt;
52   *      &lt;list/&gt;
53   *    &lt;property/&gt;
54   *    &lt;property name=&quot;disabled&quot; value=&quot;boolean&quot; /&gt;
55   *    &lt;property name=&quot;compressionThreshold&quot; value=&quot;int&quot; /&gt;
56   *  &lt;/bean&gt;
57   * </pre>
58   */
59  public class CompressionFilter extends AbstractFilter {
60  
61      private static final Log logger = LogFactory.getLog(CompressionFilter.class);
62  
63      private org.jumpmind.symmetric.web.compression.CompressionFilter delegate;
64  
65      @Override
66      public boolean isContainerCompatible() {
67          return true;
68      }
69  
70      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
71              ServletException {
72          if (delegate != null) {
73              delegate.doFilter(request, response, chain);
74          }
75      }
76  
77      @Override
78      public void destroy() {
79          super.destroy();
80          if (delegate != null) {
81              delegate.destroy();
82          }
83      }
84  
85      @Override
86      public void init(final FilterConfig filterConfig) throws ServletException {
87          super.init(filterConfig);
88          delegate = new org.jumpmind.symmetric.web.compression.CompressionFilter();
89  
90          delegate.init(filterConfig);
91      }
92  
93      @Override
94      public boolean isDisabled() {
95          return parameterService.is(ParameterConstants.TRANSPORT_HTTP_COMPRESSION_DISABLED_SERVLET);
96      }
97  
98      @Override
99      protected Log getLogger() {
100         return logger;
101     }
102 
103 }