Java 类org.eclipse.jetty.servlets.GzipFilter 实例源码

项目:agate    文件:WebConfiguration.java   
/**
 * Initializes the GZip filter.
 */
private void initGzipFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
  log.debug("Registering GZip Filter");

  FilterRegistration.Dynamic compressingFilter = servletContext.addFilter("gzipFilter", new GzipFilter());

  if (compressingFilter == null) {
    compressingFilter = (FilterRegistration.Dynamic)servletContext.getFilterRegistration("gzipFilter");
  }

  compressingFilter.addMappingForUrlPatterns(disps, true, "*.css");
  compressingFilter.addMappingForUrlPatterns(disps, true, "*.json");
  compressingFilter.addMappingForUrlPatterns(disps, true, "*.html");
  compressingFilter.addMappingForUrlPatterns(disps, true, "*.js");
  compressingFilter.addMappingForUrlPatterns(disps, true, "/metrics/*");
  compressingFilter.addMappingForUrlPatterns(disps, true, WS_ROOT + "/*");
  compressingFilter.setAsyncSupported(true);
}
项目:mica2    文件:WebConfiguration.java   
/**
 * 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);
}
项目:abhot    文件:WebServletModule.java   
@Override
protected void configureServlets()
{
    binder().requireExplicitBindings();
    bind(GuiceFilter.class);

    //Bind web server
    bind(WebServer.class);

    //Bind resource classes here
    bind(MetricsResource.class).in(Scopes.SINGLETON);

    bind(GuiceContainer.class);

    ImmutableMap<String, String> params = new ImmutableMap.Builder<String, String>()
            .put("mimeTypes", MediaType.APPLICATION_JSON)
            .put("methods", "GET,POST")
            .build();
    bind(GzipFilter.class).in(Scopes.SINGLETON);
    filter("/*").through(GzipFilter.class, params);

    bind(LoggingFilter.class).in(Scopes.SINGLETON);
    filter("/*").through(LoggingFilter.class);

    // hook Jackson into Jersey as the POJO <-> JSON mapper
    bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);
    serve("/*").with(GuiceContainer.class);


}
项目:jetty-console    文件:GzipPlugin.java   
@Override
public void beforeStart(WebAppContext context) {
    FilterHolder filterHolder  = new FilterHolder(GzipFilter.class);
    filterHolder.setInitParameter("mimeTypes", DEFAULT_MIME_TYPES);

    context.addFilter(filterHolder, "/*",  EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST));
}
项目:cougar    文件:GzipHandler.java   
public GzipHandler(final int bufferSize,
                   final int minGzipSize,
                   final String excludedAgents,
                   Handler wrappedHandler) throws ServletException {
    this.wrappedHandler = wrappedHandler;
    this.gzipFilter = new GzipFilter();
    this.gzipFilter.init(new FilterConfig() {

        @Override
        public String getFilterName() {
            return "gzipFilter";
        }

        @Override
        public String getInitParameter(String name) {
            if ("bufferSize".equals(name)) return Integer.toString(bufferSize);
            if ("minGzipSize".equals(name)) return Integer.toString(minGzipSize);
            if ("excludedAgents".equals(name)) return excludedAgents;
            return null;
        }

        @Override
        public Enumeration getInitParameterNames() {
            return null;
        }

        @Override
        public ServletContext getServletContext() {
            return new ContextHandler.NoContext();
        }});
}
项目:Wiab.pro    文件:ServerRpcProvider.java   
public void startWebSocketServer(final Injector injector) {
  httpServer = new Server();

  List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
  if (connectors.isEmpty()) {
    LOG.severe("No valid http end point address provided!");
  }
  for (Connector connector : connectors) {
    httpServer.addConnector(connector);
  }
  final WebAppContext context = new WebAppContext();

  context.setParentLoaderPriority(true);

  if (jettySessionManager != null) {
    // This disables JSessionIDs in URLs redirects
    // see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
    // and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
    jettySessionManager.setSessionIdPathParameterName(null);

    context.getSessionHandler().setSessionManager(jettySessionManager);
  }
  final ResourceCollection resources = new ResourceCollection(resourceBases);
  context.setBaseResource(resources);

  addWebSocketServlets();

  try {
    final Injector parentInjector = injector;

    final ServletModule servletModule = getServletModule(parentInjector);

    ServletContextListener contextListener = new GuiceServletContextListener() {

      private final Injector childInjector = parentInjector.createChildInjector(servletModule);

      @Override
      protected Injector getInjector() {
        return childInjector;
      }
    };

    context.addEventListener(contextListener);
    context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
    httpServer.setHandler(context);

    httpServer.start();
    restoreSessions();

  } catch (Exception e) { // yes, .start() throws "Exception"
    LOG.severe("Fatal error starting http server.", e);
    return;
  }
  LOG.fine("WebSocket server running.");
}
项目:chassis    文件:AdminTransportConfiguration.java   
@Bean(initMethod="start", destroyMethod="stop")
@Order(0)
public Server adminServer(
           @Value("${admin.hostname}") String hostname,
           @Value("${admin.port}") int port) {

       // set up servlets
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });

    // enable gzip
    context.addFilter(GzipFilter.class, "/*", null);

    // add common admin servlets
    context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
    context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*");
    context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties");
    context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath");

       // add websocket servlets if WebSockets have been initialized
       if (mappingRegistry != null && messageRegistry != null) {
           context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf");
           context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf");
       }

       // add metric servlets if Metric has been initialized
       if (metricRegistry != null && healthCheckRegistry != null) {
           context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
           context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);

           ServletHolder holder = new ServletHolder(new AdminServlet());
           holder.setInitParameter("service-name", System.getProperty("app.name"));
           context.addServlet(holder, "/metrics/*");
       }

       // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);

    Server server = new Server();

    JettyConnectorRegistry.registerHttpConnector(server, address);
       server.setHandler(context);

    return server;
}
项目:incubator-wave    文件:ServerRpcProvider.java   
public void startWebSocketServer(final Injector injector) {
  httpServer = new Server();

  List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
  if (connectors.isEmpty()) {
    LOG.severe("No valid http end point address provided!");
  }
  for (Connector connector : connectors) {
    httpServer.addConnector(connector);
  }
  final WebAppContext context = new WebAppContext();

  context.setParentLoaderPriority(true);

  if (jettySessionManager != null) {
    // This disables JSessionIDs in URLs redirects
    // see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
    // and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
    jettySessionManager.setSessionIdPathParameterName(null);

    context.getSessionHandler().setSessionManager(jettySessionManager);
  }
  final ResourceCollection resources = new ResourceCollection(resourceBases);
  context.setBaseResource(resources);

  addWebSocketServlets();

  try {

    final ServletModule servletModule = getServletModule();

    ServletContextListener contextListener = new GuiceServletContextListener() {

      private final Injector childInjector = injector.createChildInjector(servletModule);

      @Override
      protected Injector getInjector() {
        return childInjector;
      }
    };

    context.addEventListener(contextListener);
    context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
    httpServer.setHandler(context);

    httpServer.start();
    restoreSessions();

  } catch (Exception e) { // yes, .start() throws "Exception"
    LOG.severe("Fatal error starting http server.", e);
    return;
  }
  LOG.fine("WebSocket server running.");
}