Example usage for io.netty.handler.codec.http HttpContentCompressor HttpContentCompressor

List of usage examples for io.netty.handler.codec.http HttpContentCompressor HttpContentCompressor

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpContentCompressor HttpContentCompressor.

Prototype

public HttpContentCompressor() 

Source Link

Document

Creates a new handler with the default compression level (6), default window size (15) and default memory level (8).

Usage

From source file:nikoladasm.aspark.server.ServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel channel) throws Exception {
    ChannelPipeline pipeline = channel.pipeline();
    if (sslContext != null) {
        SSLEngine sslEngine = sslContext.createSSLEngine();
        sslEngine.setUseClientMode(false);
        sslEngine.setWantClientAuth(true);
        sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
        sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
        sslEngine.setEnableSessionCreation(true);
        SslHandler sslHandler = new SslHandler(sslEngine);
        pipeline.addLast("ssl", sslHandler);
    }//from   ww  w .  j ava2 s.c o  m
    pipeline.addLast("httpCodec", new HttpServerCodec());
    pipeline.addLast("inflater", new HttpContentDecompressor());
    pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
    ServerHandler serverHandler = new ServerHandler(ipAddress, port, dispatcher, exceptionMap, webSockets,
            serverName, pool);
    pipeline.addLast("handler", serverHandler);
}

From source file:org.apache.camel.component.netty4.http.HttpServerInitializerFactory.java

License:Apache License

@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        //TODO must close on SSL exception
        // sslHandler.setCloseOnSSLException(true);
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}",
                sslHandler);/* w  w w  .j av a2  s. com*/
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
        ChannelHandler decoder = decoders.get(x);
        if (decoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
        }
        pipeline.addLast("decoder-" + x, decoder);
    }
    pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));

    pipeline.addLast("encoder", new HttpResponseEncoder());
    List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
        ChannelHandler encoder = encoders.get(x);
        if (encoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
        }
        pipeline.addLast("encoder-" + x, encoder);
    }
    if (supportCompressed()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }

    int port = consumer.getConfiguration().getPort();
    ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port)
            .getChannelHandler();

    if (consumer.getConfiguration().isUsingExecutorService()) {
        EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
        pipeline.addLast(applicationExecutor, "handler", handler);
    } else {
        pipeline.addLast("handler", handler);
    }
}

From source file:org.apache.camel.component.netty4.http.HttpServerSharedInitializerFactory.java

License:Apache License

@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}",
                sslHandler);// w  w  w.  j  a  v  a  2 s .c om
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    }
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }

    pipeline.addLast("handler", channelFactory.getChannelHandler());

}

From source file:org.apache.cxf.transport.http.netty.server.NettyHttpServletPipelineFactory.java

License:Apache License

protected ChannelPipeline getDefaulHttpChannelPipeline(Channel channel) throws Exception {

    // Create a default pipeline implementation.
    ChannelPipeline pipeline = channel.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.log(Level.FINE,/*  www.  ja v  a  2  s . c  om*/
                "Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}",
                sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxChunkContentSize));

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());
    // Set up the idle handler
    pipeline.addLast("idle", new IdleStateHandler(nettyHttpServerEngine.getReadIdleTime(),
            nettyHttpServerEngine.getWriteIdleTime(), 0));

    return pipeline;
}

From source file:org.apache.tajo.pullserver.HttpDataServerChannelInitializer.java

License:Apache License

@Override
protected void initChannel(Channel channel) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = channel.pipeline();

    // Uncomment the following line if you want HTTPS
    // SSLEngine engine =
    // SecureChatSslContextFactory.getServerContext().createSSLEngine();
    // engine.setUseClientMode(false);
    // pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("decoder", new HttpRequestDecoder());
    //pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
}

From source file:org.bridje.http.impl.HttpServerImpl.java

License:Apache License

@Override
public void start() {
    try {/*from w  w  w . ja va2s  . co m*/
        LOG.log(Level.INFO, "Starting {0}, Listen: {1} Port: {2} {3}",
                new Object[] { config.getName(), config.getListen(), String.valueOf(config.getPort()),
                        (config.isSsl() ? "SSL: " + config.getSslAlgo() : "") });
        group = new NioEventLoopGroup();
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.group(group).channel(NioServerSocketChannel.class)
                    .localAddress(this.config.createInetSocketAddress())
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel ch) {
                            if (sslContext != null) {
                                SSLEngine engine = sslContext.createSSLEngine();
                                engine.setUseClientMode(false);
                                ch.pipeline().addLast("ssl", new SslHandler(engine));
                            }
                            ch.pipeline().addLast("codec", new HttpServerCodec());
                            ch.pipeline().addLast("switch", new HttpWsSwitch(handlers));
                            ch.pipeline().addLast("handler", new HttpServerChannelHandler(HttpServerImpl.this));
                            ch.pipeline().addLast("compressor", new HttpContentCompressor());
                        }
                    });
            ChannelFuture f = b.bind(this.config.getPort()).sync();
            f.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully().sync();
        }
    } catch (InterruptedException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:org.jocean.http.server.HttpTestServerInitializer.java

License:Apache License

@Override
public void initChannel(Channel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();//w w  w  . ja  v  a2s .c om
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast(new HttpServerCodec());
    p.addLast(new HttpContentCompressor());
    p.addLast(newHandler.call());
}

From source file:org.knoxcraft.netty.server.HttpUploadServer.java

License:Apache License

public boolean enable(final Logman logger) {
    thread = new Thread() {
        public void run() {
            bossGroup = new NioEventLoopGroup(1);
            workerGroup = new NioEventLoopGroup();
            try {
                ServerBootstrap b = new ServerBootstrap();
                b.group(bossGroup, workerGroup);
                b.channel(NioServerSocketChannel.class);
                b.handler(new LoggingHandler(LogLevel.INFO));
                b.childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override//from  ww w  .j  a  va 2s .co  m
                    public void initChannel(SocketChannel ch) {
                        ChannelPipeline pipeline = ch.pipeline();

                        pipeline.addLast(new HttpRequestDecoder());
                        // Prevents HTTP messages from being "chunked"
                        pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
                        pipeline.addLast(new HttpResponseEncoder());

                        // Remove the following line if you don't want automatic content compression.
                        pipeline.addLast(new HttpContentCompressor());

                        pipeline.addLast(new HttpUploadServerHandler(logger));
                    }
                });

                Channel ch = b.bind(PORT).sync().channel();

                ch.closeFuture().sync();
            } catch (InterruptedException e) {
                // TODO: log this server-side using logman?
                logger.error("Interrupted server thread!");
            } finally {
                bossGroup.shutdownGracefully();
                workerGroup.shutdownGracefully();
            }
        }
    };
    thread.start();
    return true;
}

From source file:org.waarp.gateway.ftp.adminssl.HttpSslInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) {
    final ChannelPipeline pipeline = ch.pipeline();
    // Add SSL handler first to encrypt and decrypt everything.
    SslHandler sslhandler = waarpSslContextFactory.initInitializer(true, false);
    pipeline.addLast("ssl", sslhandler);

    pipeline.addLast("codec", new HttpServerCodec());
    //pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
    //pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("streamer", new ChunkedWriteHandler());
    if (useHttpCompression) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }/*from  ww w.  j  a v a 2  s.  c om*/
    pipeline.addLast(FileBasedConfiguration.fileBasedConfiguration.getHttpPipelineExecutor(), "handler",
            new HttpSslHandler());
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpReponsiveSslInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline pipeline = ch.pipeline();
    // Add SSL handler first to encrypt and decrypt everything.
    SslHandler sslhandler = Configuration.getWaarpSslContextFactory().initInitializer(true, false);
    pipeline.addLast("ssl", sslhandler);

    pipeline.addLast("decoder", new HttpServerCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
    pipeline.addLast("streamer", new ChunkedWriteHandler());
    if (useHttpCompression) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }//from   w  ww.j  a  va  2  s. c om
    pipeline.addLast("handler", new HttpResponsiveSslHandler());
}