Search in sources :

Example 6 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project databus by linkedin.

the class HttpServerPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    //TODO   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*  NettyStats nettyStats = _serverContainer.getNettyStats();
        CallCompletion getPipelineCompletion = nettyStats.isEnabled() ?
            nettyStats.getPipelineFactory_GetPipelineCallTracker().startCall() :
            null;*/
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    //pipeline.addLast("in traffic",
    //                 new LoggingHandler("in traffic", InternalLogLevel.INFO, true));
    pipeline.addLast("auto group register ", new ConnectionChannelRegistrationHandler(_serverContainer.getHttpChannelGroup()));
    if (Logger.getRootLogger().isTraceEnabled()) {
        pipeline.addLast("netty server traffic", new LoggingHandler("netty server traffic", InternalLogLevel.DEBUG, true));
    }
    pipeline.addLast("outbound statistics collector", new OutboundContainerStatisticsCollectingHandler(_serverContainer.getContainerStatsCollector()));
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("http logger", new HttpRequestLoggingHandler());
    ExtendedReadTimeoutHandler readTimeoutHandler = new ExtendedReadTimeoutHandler("server container " + _serverContainer.getContainerStaticConfig().getId(), _serverContainer.getNetworkTimeoutTimer(), _serverContainer.getContainerStaticConfig().getReadTimeoutMs(), true);
    HttpRequestHandler reqHandler = new HttpRequestHandler(_serverContainer, readTimeoutHandler);
    pipeline.addLast("handler", reqHandler);
    if (_serverContainer.getContainerStaticConfig().getEnableHttpCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("executionHandler", _serverContainer.getNettyExecHandler());
    DatabusRequestExecutionHandler dbusRequestHandler = new DatabusRequestExecutionHandler(_serverContainer);
    pipeline.addLast("databusRequestRunner", dbusRequestHandler);
    //add a handler to deal with write timeouts
    pipeline.addLast("server container write timeout handler", new ExtendedWriteTimeoutHandler("server container " + _serverContainer.getContainerStaticConfig().getId(), _serverContainer.getNetworkTimeoutTimer(), _serverContainer.getContainerStaticConfig().getWriteTimeoutMs(), true));
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) ConnectionChannelRegistrationHandler(com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) OutboundContainerStatisticsCollectingHandler(com.linkedin.databus2.core.container.netty.OutboundContainerStatisticsCollectingHandler) HttpRequestHandler(com.linkedin.databus2.core.container.netty.HttpRequestHandler) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) DatabusRequestExecutionHandler(com.linkedin.databus2.core.container.netty.DatabusRequestExecutionHandler) ExtendedReadTimeoutHandler(com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler) ExtendedWriteTimeoutHandler(com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 7 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project graylog2-server by Graylog2.

the class HttpTransport method getBaseChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> baseChannelHandlers = super.getBaseChannelHandlers(input);
    if (idleWriterTimeout > 0) {
        // Install read timeout handler to close idle connections after a timeout.
        // This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
        // For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
        baseChannelHandlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(timer, idleWriterTimeout, TimeUnit.SECONDS));
    }
    baseChannelHandlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
    baseChannelHandlers.put("aggregator", () -> new HttpChunkAggregator(maxChunkSize));
    baseChannelHandlers.put("encoder", HttpResponseEncoder::new);
    baseChannelHandlers.put("decompressor", HttpContentDecompressor::new);
    return baseChannelHandlers;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) HttpContentDecompressor(org.jboss.netty.handler.codec.http.HttpContentDecompressor)

Example 8 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project voldemort by voldemort.

the class RestPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("connectionStats", connectionStatsHandler);
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpChunkAggregator(maxHttpContentLength));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("handler", new RestServerRequestHandler(storeRepository));
    pipeline.addLast("storageExecutionHandler", storageExecutionHandler);
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 9 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project cdap by caskdata.

the class NettyRouter method bootstrapServer.

private void bootstrapServer(final ChannelUpstreamHandler connectionTracker) throws ServiceBindException {
    ExecutorService serverBossExecutor = createExecutorService(serverBossThreadPoolSize, "router-server-boss-thread-%d");
    ExecutorService serverWorkerExecutor = createExecutorService(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
    serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(serverBossExecutor, serverWorkerExecutor));
    serverBootstrap.setOption("backlog", serverConnectionBacklog);
    serverBootstrap.setOption("child.bufferFactory", new DirectChannelBufferFactory());
    // Setup the pipeline factory
    serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (isSSLEnabled()) {
                // Add SSLHandler is SSL is enabled
                pipeline.addLast("ssl", sslHandlerFactory.create());
            }
            pipeline.addLast("tracker", connectionTracker);
            pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
            pipeline.addLast("http-decoder", new HttpRequestDecoder());
            pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
            if (securityEnabled) {
                pipeline.addLast("access-token-authenticator", new SecurityAuthenticationHttpHandler(realm, tokenValidator, configuration, accessTokenTransformer, discoveryServiceClient));
            }
            // for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
            pipeline.addLast("http-request-handler", new HttpRequestHandler(clientBootstrap, serviceLookup, ImmutableList.<ProxyRule>of()));
            return pipeline;
        }
    });
    // Start listening on ports.
    ImmutableMap.Builder<Integer, String> serviceMapBuilder = ImmutableMap.builder();
    for (Map.Entry<String, Integer> forward : serviceToPortMap.entrySet()) {
        int port = forward.getValue();
        String service = forward.getKey();
        String boundService = serviceLookup.getService(port);
        if (boundService != null) {
            LOG.warn("Port {} is already configured to service {}, ignoring forward for service {}", port, boundService, service);
            continue;
        }
        InetSocketAddress bindAddress = new InetSocketAddress(hostname, port);
        LOG.info("Starting Netty Router for service {} on address {}...", service, bindAddress);
        try {
            Channel channel = serverBootstrap.bind(bindAddress);
            InetSocketAddress boundAddress = (InetSocketAddress) channel.getLocalAddress();
            serviceMapBuilder.put(boundAddress.getPort(), service);
            channelGroup.add(channel);
            // Update service map
            serviceLookup.updateServiceMap(serviceMapBuilder.build());
            LOG.info("Started Netty Router for service {} on address {}.", service, boundAddress);
        } catch (ChannelException e) {
            if ((Throwables.getRootCause(e) instanceof BindException)) {
                throw new ServiceBindException("Router", hostname.getCanonicalHostName(), port, e);
            }
            throw e;
        }
    }
}
Also used : ServiceBindException(co.cask.cdap.common.ServiceBindException) HttpRequestHandler(co.cask.cdap.gateway.router.handlers.HttpRequestHandler) InetSocketAddress(java.net.InetSocketAddress) SecurityAuthenticationHttpHandler(co.cask.cdap.gateway.router.handlers.SecurityAuthenticationHttpHandler) HttpStatusRequestHandler(co.cask.cdap.gateway.router.handlers.HttpStatusRequestHandler) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ChannelException(org.jboss.netty.channel.ChannelException) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) Channel(org.jboss.netty.channel.Channel) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) DirectChannelBufferFactory(org.jboss.netty.buffer.DirectChannelBufferFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelException(org.jboss.netty.channel.ChannelException) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ImmutableMap(com.google.common.collect.ImmutableMap) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 10 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project socket.io-netty by ibdknox.

the class WebSocketServerPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("handler", socketHandler);
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)14 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)14 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)12 HttpChunkAggregator (org.jboss.netty.handler.codec.http.HttpChunkAggregator)10 HttpContentCompressor (org.jboss.netty.handler.codec.http.HttpContentCompressor)7 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)4 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)4 InetSocketAddress (java.net.InetSocketAddress)3 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)3 JmxReporter (com.codahale.metrics.JmxReporter)2 Channel (org.jboss.netty.channel.Channel)2 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 ServiceBindException (co.cask.cdap.common.ServiceBindException)1 HttpRequestHandler (co.cask.cdap.gateway.router.handlers.HttpRequestHandler)1 HttpStatusRequestHandler (co.cask.cdap.gateway.router.handlers.HttpStatusRequestHandler)1 SecurityAuthenticationHttpHandler (co.cask.cdap.gateway.router.handlers.SecurityAuthenticationHttpHandler)1