Search in sources :

Example 1 with PortMappingHelperHandler

use of org.apache.knox.gateway.filter.PortMappingHelperHandler 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)

Aggregations

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 GzipHandler (org.eclipse.jetty.servlets.gzip.GzipHandler)1