add GzipFilter first, before GuiceFitler and CORSFilter
Jetty GZIP filter
Pregunta
Hello i Use jetty 9 with guice and jersey. How to dorce use GZIP?
Server server = new Server(8080);
ServletContextHandler handler = new ServletContextHandler();
handler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
handler.addFilter(CORSFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
FilterHolder holder = new FilterHolder(GzipFilter.class);
holder.setInitParameter("deflateCompressionLevel", "9");
holder.setInitParameter("minGzipSize", "0");
holder.setInitParameter("mimeTypes", "application/json");
handler.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
handler.addEventListener(new GuiceServletConfig());
server.setHandler(handler);
server.start();
server.join();
While i do request in debug i "doFilter" method not called
Solución
Otros consejos
But when using a ServletModule installed on your injector you can just add it in your module configureServlets() function like this.
final Map<String, String> params = Maps.newHashMap();
params.put("mimeTypes", "text/html,text/xml,text/plain,application/javascript,application/json");
params.put("methods", "GET,PUT,POST,DELETE");
params.put("deflateCompressionLevel", "9");
bind(GzipFilter.class).in(Singleton.class);
filter("/*").through(GzipFilter.class, params);
More info see Guice ServletModule#dispatch-order
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow