Search in sources :

Example 1 with AsyncHttpClientHandler

use of org.asynchttpclient.netty.handler.AsyncHttpClientHandler 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

Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)1 IOException (java.io.IOException)1 SSLException (javax.net.ssl.SSLException)1 PoolAlreadyClosedException (org.asynchttpclient.exception.PoolAlreadyClosedException)1 TooManyConnectionsException (org.asynchttpclient.exception.TooManyConnectionsException)1 TooManyConnectionsPerHostException (org.asynchttpclient.exception.TooManyConnectionsPerHostException)1 AsyncHttpClientHandler (org.asynchttpclient.netty.handler.AsyncHttpClientHandler)1 HttpHandler (org.asynchttpclient.netty.handler.HttpHandler)1 WebSocketHandler (org.asynchttpclient.netty.handler.WebSocketHandler)1