Search in sources :

Example 46 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project rskj by rsksmart.

the class Web3WebSocketServer method start.

@Override
public void start() {
    logger.info("RPC WebSocket enabled");
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpServerCodec());
            p.addLast(new HttpObjectAggregator(maxAggregatedFrameSize));
            p.addLast(new WriteTimeoutHandler(serverWriteTimeoutSeconds, TimeUnit.SECONDS));
            p.addLast(new RskWebSocketServerProtocolHandler("/websocket", maxFrameSize));
            p.addLast(new WebSocketFrameAggregator(maxAggregatedFrameSize));
            p.addLast(webSocketJsonRpcHandler);
            p.addLast(web3ServerHandler);
            p.addLast(new Web3ResultWebSocketResponseHandler());
        }
    });
    webSocketChannel = b.bind(host, port);
    try {
        webSocketChannel.sync();
    } catch (InterruptedException e) {
        logger.error("The RPC WebSocket server couldn't be started", e);
        Thread.currentThread().interrupt();
    }
}
Also used : WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) WriteTimeoutHandler(io.netty.handler.timeout.WriteTimeoutHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec)

Example 47 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project ambry by linkedin.

the class Http2BlockingChannelStreamChannelInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast(http2StreamFrameToHttpObjectCodec);
    p.addLast(new HttpObjectAggregator(http2ClientConfig.http2MaxContentLength));
    p.addLast(http2BlockingChannelResponseHandler);
    p.addLast(ambrySendToHttp2Adaptor);
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 48 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project ambry by linkedin.

the class Http2ServerStreamHandler method handlerAdded.

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    ctx.pipeline().addLast(http2StreamFrameToHttpObjectCodec);
    ctx.pipeline().addLast(new HttpObjectAggregator(http2ClientConfig.http2MaxContentLength));
    ctx.pipeline().addLast(ambryNetworkRequestHandler);
    ctx.pipeline().addLast(ambrySendToHttp2Adaptor);
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator)

Example 49 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project weicoder by wdcode.

the class WebSocketServer method handler.

@Override
protected ChannelHandler handler() {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(final SocketChannel ch) throws Exception {
            ch.pipeline().addLast(new HttpServerCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(1024 * 1024));
            ch.pipeline().addLast(new WebSocketHandler("websocket"));
            ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
        }
    };
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) WebSocketHandler(com.weicoder.netty.handler.WebSocketHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelInitializer(io.netty.channel.ChannelInitializer)

Example 50 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project rest.li by linkedin.

the class TestRAPClientCodec method testDecodeException.

@Test
public void testDecodeException() {
    final EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec(), new HttpObjectAggregator(65536), new RAPClientCodec());
    // When we received an invalid message, a decode exception should be thrown out of the
    // end of netty pipeline.
    String junk = "Not a HTTP message\r\n";
    try {
        ch.writeInbound(Unpooled.copiedBuffer(junk, CHARSET));
        Assert.fail("Should have thrown decode exception");
    } catch (Exception ex) {
    // expected.
    }
    ch.finish();
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteString(com.linkedin.data.ByteString) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) Test(org.testng.annotations.Test)

Aggregations

HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)95 ChannelPipeline (io.netty.channel.ChannelPipeline)60 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)34 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)29 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)28 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)25 SocketChannel (io.netty.channel.socket.SocketChannel)20 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)18 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)17 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)16 Bootstrap (io.netty.bootstrap.Bootstrap)13 Channel (io.netty.channel.Channel)12 EventLoopGroup (io.netty.channel.EventLoopGroup)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 SslHandler (io.netty.handler.ssl.SslHandler)11 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)10 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)9 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)8 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)8