Search in sources :

Example 21 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project async-http-client by AsyncHttpClient.

the class ChannelManager method configureBootstraps.

public void configureBootstraps(NettyRequestSender requestSender) {
    final AsyncHttpClientHandler httpHandler = new HttpHandler(config, this, requestSender);
    wsHandler = new WebSocketHandler(config, this, requestSender);
    final NoopHandler pinnedEntry = new NoopHandler();
    final LoggingHandler loggingHandler = new LoggingHandler(LogLevel.TRACE);
    httpBootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = //
            ch.pipeline().addLast(PINNED_ENTRY, //
            pinnedEntry).addLast(HTTP_CLIENT_CODEC, //
            newHttpClientCodec()).addLast(INFLATER_HANDLER, //
            newHttpContentDecompressor()).addLast(CHUNKED_WRITER_HANDLER, //
            new ChunkedWriteHandler()).addLast(AHC_HTTP_HANDLER, httpHandler);
            if (LOGGER.isTraceEnabled()) {
                pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler);
            }
            if (config.getHttpAdditionalChannelInitializer() != null)
                config.getHttpAdditionalChannelInitializer().initChannel(ch);
        }
    });
    wsBootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = //
            ch.pipeline().addLast(PINNED_ENTRY, //
            pinnedEntry).addLast(HTTP_CLIENT_CODEC, //
            newHttpClientCodec()).addLast(AHC_WS_HANDLER, wsHandler);
            if (LOGGER.isDebugEnabled()) {
                pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler);
            }
            if (config.getWsAdditionalChannelInitializer() != null)
                config.getWsAdditionalChannelInitializer().initChannel(ch);
        }
    });
}
Also used : HttpHandler(org.asynchttpclient.netty.handler.HttpHandler) LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) Channel(io.netty.channel.Channel) WebSocketHandler(org.asynchttpclient.netty.handler.WebSocketHandler) TooManyConnectionsException(org.asynchttpclient.exception.TooManyConnectionsException) TooManyConnectionsPerHostException(org.asynchttpclient.exception.TooManyConnectionsPerHostException) PoolAlreadyClosedException(org.asynchttpclient.exception.PoolAlreadyClosedException) SSLException(javax.net.ssl.SSLException) IOException(java.io.IOException) ChannelPipeline(io.netty.channel.ChannelPipeline) AsyncHttpClientHandler(org.asynchttpclient.netty.handler.AsyncHttpClientHandler)

Aggregations

ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)21 ChannelPipeline (io.netty.channel.ChannelPipeline)12 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)6 SslHandler (io.netty.handler.ssl.SslHandler)6 SocketChannel (io.netty.channel.socket.SocketChannel)5 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)5 LoggingHandler (io.netty.handler.logging.LoggingHandler)5 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)4 Channel (io.netty.channel.Channel)4 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)4 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)4 ByteBuf (io.netty.buffer.ByteBuf)3 ChannelFuture (io.netty.channel.ChannelFuture)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)3 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)3 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)2