Search in sources :

Example 11 with HttpObjectAggregator

use of io.netty.handler.codec.http.HttpObjectAggregator in project ratpack by ratpack.

the class ContentAggregatingRequestAction method addResponseHandlers.

@Override
protected void addResponseHandlers(ChannelPipeline p, Downstream<? super ReceivedResponse> downstream) {
    p.addLast(AGGREGATOR_HANDLER_NAME, new HttpObjectAggregator(requestConfig.maxContentLength));
    p.addLast(RESPONSE_HANDLER_NAME, new SimpleChannelInboundHandler<FullHttpResponse>(false) {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) throws Exception {
            response.touch();
            dispose(ctx.pipeline(), response);
            ByteBuf content = response.content();
            execution.onComplete(() -> {
                if (content.refCnt() > 0) {
                    content.release();
                }
            });
            success(downstream, toReceivedResponse(response, content));
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            forceDispose(ctx.pipeline());
            error(downstream, cause);
        }
    });
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf)

Example 12 with HttpObjectAggregator

use of io.netty.handler.codec.http.HttpObjectAggregator in project spring-framework by spring-projects.

the class Netty4ClientHttpRequestFactory method buildBootstrap.

private Bootstrap buildBootstrap(URI uri, boolean isSecure) {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel channel) throws Exception {
            configureChannel(channel.config());
            ChannelPipeline pipeline = channel.pipeline();
            if (isSecure) {
                Assert.notNull(sslContext, "sslContext should not be null");
                pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort()));
            }
            pipeline.addLast(new HttpClientCodec());
            pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
            if (readTimeout > 0) {
                pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS));
            }
        }
    });
    return bootstrap;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) Bootstrap(io.netty.bootstrap.Bootstrap) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 13 with HttpObjectAggregator

use of io.netty.handler.codec.http.HttpObjectAggregator in project camel by apache.

the class HttpServerSharedInitializerFactory method initChannel.

@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);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    }
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("handler", channelFactory.getChannelHandler());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 14 with HttpObjectAggregator

use of io.netty.handler.codec.http.HttpObjectAggregator in project rest.li by linkedin.

the class HttpNettyServer method start.

@Override
public void start() {
    _eventExecutors = new DefaultEventExecutorGroup(_threadPoolSize);
    _bossGroup = new NioEventLoopGroup(1, new NamedThreadFactory("R2 Nio Boss"));
    _workerGroup = new NioEventLoopGroup(0, new NamedThreadFactory("R2 Nio Worker"));
    ServerBootstrap bootstrap = new ServerBootstrap().group(_bossGroup, _workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<NioSocketChannel>() {

        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ch.pipeline().addLast("decoder", new HttpRequestDecoder());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));
            ch.pipeline().addLast("encoder", new HttpResponseEncoder());
            ch.pipeline().addLast("rapi", new RAPServerCodec());
            ch.pipeline().addLast(_eventExecutors, "handler", _restOverStream ? new StreamHandler() : new RestHandler());
        }
    });
    bootstrap.bind(new InetSocketAddress(_port));
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 15 with HttpObjectAggregator

use of io.netty.handler.codec.http.HttpObjectAggregator in project asterixdb by apache.

the class HttpServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    p.addLast(new HttpRequestDecoder(MAX_REQUEST_INITIAL_LINE_LENGTH, MAX_REQUEST_HEADER_SIZE, MAX_REQUEST_CHUNK_SIZE));
    p.addLast(new HttpResponseEncoder());
    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
    p.addLast(server.createHttpHandler(RESPONSE_CHUNK_SIZE));
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)35 ChannelPipeline (io.netty.channel.ChannelPipeline)24 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)12 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)12 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)11 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)10 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)9 SocketChannel (io.netty.channel.socket.SocketChannel)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)6 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)6 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)6 Channel (io.netty.channel.Channel)5 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)5 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)5 Bootstrap (io.netty.bootstrap.Bootstrap)4 ByteBuf (io.netty.buffer.ByteBuf)4 EventLoopGroup (io.netty.channel.EventLoopGroup)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4 HttpResponseDecoder (io.netty.handler.codec.http.HttpResponseDecoder)4