Search in sources :

Example 1 with HttpRequestDecoder

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

the class TrackerService method startUp.

@Override
protected void startUp() throws Exception {
    Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
    Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
    ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("compressor", new HttpContentCompressor());
            pipeline.addLast("handler", new ReportHandler(resourceReport));
            return pipeline;
        }
    });
    Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
    bindAddress = (InetSocketAddress) channel.getLocalAddress();
    url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
    channelGroup.add(channel);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) Executor(java.util.concurrent.Executor) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 2 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 3 with HttpRequestDecoder

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

the class HttpServerSharedPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
    }
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("handler", channelFactory.getChannelHandler());
    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) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 4 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 5 with HttpRequestDecoder

use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project sockjs-netty by cgbystrom.

the class StressTestServer method start.

public void start() throws Exception {
    final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
    final ServiceRouter router = new ServiceRouter();
    reporter.start();
    router.setMetricRegistry(registry);
    Service echoService = new Service("/stresstest", new SessionCallbackFactory() {

        @Override
        public StressTestSession getSession(String id) throws Exception {
            return new StressTestSession();
        }
    });
    router.registerService(echoService);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Required for WS handshaker or else NPE.
            pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("preflight", new PreflightHandler());
            pipeline.addLast("router", router);
            return pipeline;
        }
    });
    bootstrap.bind(new LocalAddress(port));
}
Also used : LocalAddress(org.jboss.netty.channel.local.LocalAddress) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) JmxReporter(com.codahale.metrics.JmxReporter) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Aggregations

HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)19 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)19 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)17 HttpChunkAggregator (org.jboss.netty.handler.codec.http.HttpChunkAggregator)14 HttpContentCompressor (org.jboss.netty.handler.codec.http.HttpContentCompressor)7 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)5 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)5 InetSocketAddress (java.net.InetSocketAddress)4 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)4 SslHandler (org.jboss.netty.handler.ssl.SslHandler)4 SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)2 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)2 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