org.eclipse.jetty.servlets.GzipFilter Java Examples
The following examples show how to use
org.eclipse.jetty.servlets.GzipFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GzipHandler.java From cougar with Apache License 2.0 | 5 votes |
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(); }}); }
Example #2
Source File: AdminTransportConfiguration.java From chassis with Apache License 2.0 | 4 votes |
@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; }
Example #3
Source File: ServerRpcProvider.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
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."); }