0

I have configured a GzipFilter in my custom WebApplicationInitializer and when I try to access the website. It shows me,

Content Encoding Error

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

Please contact the website owners to inform them of this problem.

The GzipFilter I'm using is from this blog,

http://tutorials.jenkov.com/java-servlets/gzip-servlet-filter.html

I can see the browser request gzip content. And for the files that are downloaded I can see the Response header Content-Encoding:gzip. But, I don't see why I get this error. Below is my app config,

public class WebInitializer implements WebApplicationInitializer{
    @Override
    public void onStartup(ServletContext container) throws ServletException {
        //configuration code
        container.addFilter("GzipCompressionFilter",GzipFilter.class).addMappingForUrlPatterns(null, false, "/*");
    }
}

If I use the filter from this post,

http://www.oodlestechnologies.com/blogs/Gzip-Servlet-Filter-in-Spring-MVC

The request never ends and the files download partially and loads infinitely. What could be the problem?

I'm using maven-jetty plugin to start jetty with mvn jetty:run goal. Currently I'm using the above filters to serve GZip content from the server. Is there any other way in maven-jetty plugin to enable GZip compression? GZipFilter is deprecated and I can't see any GZipHandler implementation for embedded jetty server. My maven-jetty config,

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
        <stopKey>jettyStop</stopKey>
        <stopPort>9191</stopPort>
        <httpConnector>
          <host>0.0.0.0</host>
          <port>8080</port>
        </httpConnector>
    </configuration>
</plugin>
Lucky
  • 16,787
  • 19
  • 117
  • 151
  • What version of Jetty? (note, Jetty 9+ uses Servlet 3.1 which is incompatible with *all* Filter based Gzip implementations due to the introduction of Async I/O in the servlet spec) – Joakim Erdfelt Aug 08 '16 at 21:14
  • @JoakimErdfelt I'm using Jetty version `9.3.7.v20160115`. So what is the alternative for GzipFilter in jetty version > 8. If `GzipHandler` is the alternative, I don't know how to use that in my embedded jetty configuration. – Lucky Aug 09 '16 at 05:56
  • One example of GzipHandler usage -https://github.com/jetty-project/embedded-jetty-cookbook/blob/master/src/main/java/org/eclipse/jetty/cookbook/GzipResponsesExample.java – Joakim Erdfelt Aug 09 '16 at 12:57
  • @JoakimErdfelt Thanks, But Sorry I was wrong. I don't use the embedded jetty. I use [jetty-maven plugin](http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html) goal [`mvn jetty:run`](http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-run-goal) to start my server. So I don't have a main method. And I use no xml for configuration since I'm using java based configuration. The only jetty configuration is on my pom.xml posted above. How can I use the example? Do I need to configure it in the `jetty-gzip.xml`? – Lucky Aug 09 '16 at 13:14
  • It is dangerous to use `jetty-maven-plugin` for production, don't do it! You **need** to produce an (installable and/or deployable) artifact and start your server outside of `jetty-maven-plugin`, once you have that figured out, then you'll understand how to get GzipHandler into place in the correct place. – Joakim Erdfelt Aug 09 '16 at 14:13
  • @JoakimErdfelt Yes, I use jetty only as development server and tomcat in production server. Then I guess I have to switch to embedded jetty for using GzipHandler. Thanks. – Lucky Aug 09 '16 at 14:32

0 Answers0