Search in sources :

Example 1 with GzipHandler

use of org.eclipse.jetty.servlets.gzip.GzipHandler in project knox by apache.

the class GatewayServer method createHandlers.

private static HandlerCollection createHandlers(final GatewayConfig config, final GatewayServices services, final ContextHandlerCollection contexts, final Map<String, Integer> topologyPortMap) {
    HandlerCollection handlers = new HandlerCollection();
    RequestLogHandler logHandler = new RequestLogHandler();
    logHandler.setRequestLog(new AccessHandler());
    TraceHandler traceHandler = new TraceHandler();
    traceHandler.setHandler(contexts);
    traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter"));
    CorrelationHandler correlationHandler = new CorrelationHandler();
    correlationHandler.setHandler(traceHandler);
    /* KNOX-732: Handler for GZip compression */
    GzipHandler gzipHandler = new GzipHandler();
    String[] mimeTypes = {};
    if (config.getMimeTypesToCompress() != null && !config.getMimeTypesToCompress().isEmpty()) {
        mimeTypes = (String[]) config.getMimeTypesToCompress().toArray();
    }
    gzipHandler.addIncludedMimeTypes(mimeTypes);
    gzipHandler.setHandler(correlationHandler);
    // Used to correct the {target} part of request with Topology Port Mapping feature
    final PortMappingHelperHandler portMappingHandler = new PortMappingHelperHandler(config);
    portMappingHandler.setHandler(gzipHandler);
    if (config.isGatewayPortMappingEnabled()) {
        for (final Map.Entry<String, Integer> entry : topologyPortMap.entrySet()) {
            log.createJettyHandler(entry.getKey());
            final ContextHandler topologyContextHandler = new ContextHandler();
            final RequestUpdateHandler updateHandler = new RequestUpdateHandler(config, entry.getKey(), services);
            topologyContextHandler.setHandler(updateHandler);
            topologyContextHandler.setVirtualHosts(new String[] { "@" + entry.getKey().toLowerCase() });
            handlers.addHandler(topologyContextHandler);
        }
    }
    handlers.addHandler(logHandler);
    if (config.isWebsocketEnabled()) {
        final GatewayWebsocketHandler websocketHandler = new GatewayWebsocketHandler(config, services);
        websocketHandler.setHandler(portMappingHandler);
        handlers.addHandler(websocketHandler);
    } else {
        handlers.addHandler(portMappingHandler);
    }
    return handlers;
}
Also used : CorrelationHandler(org.apache.knox.gateway.filter.CorrelationHandler) RequestUpdateHandler(org.apache.knox.gateway.filter.RequestUpdateHandler) TraceHandler(org.apache.knox.gateway.trace.TraceHandler) PortMappingHelperHandler(org.apache.knox.gateway.filter.PortMappingHelperHandler) AccessHandler(org.apache.knox.gateway.trace.AccessHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) GatewayWebsocketHandler(org.apache.knox.gateway.websockets.GatewayWebsocketHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with GzipHandler

use of org.eclipse.jetty.servlets.gzip.GzipHandler in project gocd by gocd.

the class Jetty9Server method gzipHandler.

static GzipHandler gzipHandler(Handler handler) {
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.addIncludedMimeTypes("application/javascript", "application/json", "application/vnd.go.cd.v1+json", "application/vnd.go.cd.v2+json", "application/vnd.go.cd.v3+json", "application/vnd.go.cd.v4+json", "application/vnd.go.cd.v5+json", "application/vnd.go.cd.v6+json", "application/vnd.go.cd.v7+json", "application/vnd.go.cd.v8+json", "application/vnd.go.cd.v9+json", "application/xhtml+xml", "image/svg+xml", "text/css", "text/html", "text/plain", "text/xml");
    gzipHandler.addIncludedMethods("HEAD", "GET", "POST", "PUT", "PATCH", "DELETE");
    gzipHandler.setHandler(handler);
    return gzipHandler;
}
Also used : GzipHandler(org.eclipse.jetty.servlets.gzip.GzipHandler)

Aggregations

GzipHandler (org.eclipse.jetty.servlets.gzip.GzipHandler)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CorrelationHandler (org.apache.knox.gateway.filter.CorrelationHandler)1 PortMappingHelperHandler (org.apache.knox.gateway.filter.PortMappingHelperHandler)1 RequestUpdateHandler (org.apache.knox.gateway.filter.RequestUpdateHandler)1 AccessHandler (org.apache.knox.gateway.trace.AccessHandler)1 TraceHandler (org.apache.knox.gateway.trace.TraceHandler)1 GatewayWebsocketHandler (org.apache.knox.gateway.websockets.GatewayWebsocketHandler)1 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)1