1

I'm getting the following error in my JEE7 app:

2018-05-16 16:49:58,143WARN [org.eclipse.jetty.servlets.GzipFilter](default task-26)GzipFilter is deprecated. Use GzipHandler

My filter config:

    <filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
    <init-param>
        <param-name>mimeTypes</param-name>
        <param-value>text/html,text/plain,text/xml,application/xhtml+xml,application/xml,text/css,application/javascript,image/svg+xml,application/json,application/xml; charset=UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

My question: How I can config that Gzip Handler in my web.xml?

thanks

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
Makhz
  • 65
  • 1
  • 8

1 Answers1

2

Since the introduction of Servlet 3.1 its no longer possible to have a reliable Filter based Gzip implementation.

The Gzip compression (of responses) and decompression (of requests) has to now be handled outside of the webapp and within the server side.

The GzipHandler is a low level Jetty Handler that you add (and configure) before your webapps on the server handler list.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Help, I have a Javascript dynamic generator in my webapp (JEE7/jbossAs7) and the page calls it using a webServlet (The generated javascript is written in the http response as plain text/javascript). Currenty this JS becomes heavy to download (over 5MB). What is the best way to gzip the response (jetty gzip don't works for me)? Thanks in advance. – Makhz May 16 '18 at 22:24
  • Precompress the javascript. If you have mylib.js, then compress it manually before you package/deploy, so that you have both 'mylib.js' and 'mylib.js.gz' in your webapp. Browsers that support gzip get fed the precompressed version, other browsers get the uncompressed version. (Without having the browser even be aware that the precompressed even exists) – Joakim Erdfelt May 17 '18 at 13:36
  • For some example code, see the answers at https://stackoverflow.com/q/24521426/441757. https://stackoverflow.com/a/53808318/441757 is the one I found most helpful for my particular use case. – sideshowbarker May 16 '19 at 02:49