Search in sources :

Example 1 with GzipFilter

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();
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InputStream(java.io.InputStream) ServerSocket(java.net.ServerSocket) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) GzipFilter(org.eclipse.jetty.servlets.GzipFilter) ServerConnector(org.eclipse.jetty.server.ServerConnector) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ConnectException(java.net.ConnectException)

Example 2 with GzipFilter

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);
}
Also used : GzipFilter(org.eclipse.jetty.servlets.GzipFilter) FilterRegistration(javax.servlet.FilterRegistration)

Aggregations

GzipFilter (org.eclipse.jetty.servlets.GzipFilter)2 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 FilterRegistration (javax.servlet.FilterRegistration)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)1