NIFI-2771:

- Using GzipHandler instead of GzipFilter.

This closes #1020
This commit is contained in:
Matt Gilman 2016-09-14 10:13:16 -04:00 committed by Oleg Zhurakousky
parent aa933a1941
commit abcfbeb062
2 changed files with 40 additions and 39 deletions

View File

@ -16,32 +16,6 @@
*/
package org.apache.nifi.web.server;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@ -72,6 +46,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
@ -88,6 +63,31 @@ import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* Encapsulates the Jetty instance.
*/
@ -326,7 +326,20 @@ public class JettyServer implements NiFiServer {
handlers.addHandler(loadWar(webErrorWar, "/", frameworkClassLoader));
// deploy the web apps
server.setHandler(handlers);
server.setHandler(gzip(handlers));
}
/**
* Enables compression for the specified handler.
*
* @param handler handler to enable compression for
* @return compression enabled handler
*/
private Handler gzip(final Handler handler) {
final GzipHandler gzip = new GzipHandler();
gzip.setIncludedMethods("GET", "POST", "PUT", "DELETE");
gzip.setHandler(handler);
return gzip;
}
private Map<File, File> findWars(final Set<File> narWorkingDirectories) {

View File

@ -70,16 +70,4 @@
<filter-name>requestLogger</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>gzipCompressionFilter</filter-name>
<filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
<init-param>
<param-name>methods</param-name>
<param-value>get,post,put</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>gzipCompressionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>