use of org.eclipse.jetty.servlets.GzipFilter in project validator by validator.
the class Main method main.
public static void main(String[] args) throws Exception {
if (!"1".equals(System.getProperty("nu.validator.servlet.read-local-log4j-properties"))) {
PropertyConfigurator.configure(Main.class.getClassLoader().getResource("nu/validator/localentities/files/log4j.properties"));
} else {
PropertyConfigurator.configure(System.getProperty("nu.validator.servlet.log4j-properties", "log4j.properties"));
}
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
contextHandler.addFilter(new FilterHolder(new GzipFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addFilter(new FilterHolder(new InboundSizeLimitFilter(SIZE_LIMIT)), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addFilter(new FilterHolder(new InboundGzipFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addFilter(new FilterHolder(new MultipartFormDataFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addServlet(new ServletHolder(new VerifierServlet()), "/*");
Server server = new Server(new QueuedThreadPool(100));
server.setHandler(contextHandler);
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(new HttpConfiguration()));
int port = args.length > 0 ? Integer.parseInt(args[0]) : 8888;
serverConnector.setPort(port);
server.setConnectors(new Connector[] { serverConnector });
int stopPort = -1;
if (args.length > 1) {
stopPort = Integer.parseInt(args[1]);
}
if (stopPort != -1) {
try (Socket clientSocket = new Socket(InetAddress.getByName("127.0.0.1"), stopPort);
InputStream in = clientSocket.getInputStream()) {
in.read();
} catch (ConnectException e) {
}
server.start();
try (ServerSocket serverSocket = new ServerSocket(stopPort, 0, InetAddress.getByName("127.0.0.1"));
Socket s = serverSocket.accept()) {
server.stop();
s.getOutputStream().close();
}
} else {
server.start();
}
}
use of org.eclipse.jetty.servlets.GzipFilter in project mica2 by obiba.
the class WebConfiguration method initGzipFilter.
/**
* Initializes the GZip filter.
*/
private void initGzipFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
log.debug("Registering GZip Filter");
FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("gzipFilter", new GzipFilter());
if (filterRegistration == null) {
filterRegistration = (FilterRegistration.Dynamic) servletContext.getFilterRegistration("gzipFilter");
}
filterRegistration.addMappingForUrlPatterns(disps, true, "*.css");
filterRegistration.addMappingForUrlPatterns(disps, true, "*.json");
filterRegistration.addMappingForUrlPatterns(disps, true, "*.html");
filterRegistration.addMappingForUrlPatterns(disps, true, "*.js");
filterRegistration.addMappingForUrlPatterns(disps, true, "/jvm/*");
filterRegistration.addMappingForUrlPatterns(disps, true, WS_ROOT + "/*");
filterRegistration.setAsyncSupported(true);
}
Aggregations