Search in sources :

Example 11 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project cdap by caskdata.

the class NettyRouter method createServerBootstrap.

private ServerBootstrap createServerBootstrap(final ChannelGroup channelGroup) throws ServiceBindException {
    EventLoopGroup bossGroup = createEventLoopGroup(serverBossThreadPoolSize, "router-server-boss-thread-%d");
    EventLoopGroup workerGroup = createEventLoopGroup(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
    return new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, serverConnectionBacklog).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            channelGroup.add(ch);
            ChannelPipeline pipeline = ch.pipeline();
            if (isSSLEnabled()) {
                pipeline.addLast("ssl", sslHandlerFactory.create(ch.alloc()));
            }
            pipeline.addLast("http-codec", new HttpServerCodec());
            pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
            if (securityEnabled) {
                pipeline.addLast("access-token-authenticator", new AuthenticationHandler(cConf, tokenValidator, discoveryServiceClient, accessTokenTransformer));
            }
            if (cConf.getBoolean(Constants.Router.ROUTER_AUDIT_LOG_ENABLED)) {
                pipeline.addLast("audit-log", new AuditLogHandler());
            }
            // Always let the client to continue sending the request body after the authentication passed
            pipeline.addLast("expect-continue", new HttpServerExpectContinueHandler());
            // for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
            pipeline.addLast("http-request-handler", new HttpRequestRouter(cConf, serviceLookup));
        }
    });
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) HttpServerExpectContinueHandler(io.netty.handler.codec.http.HttpServerExpectContinueHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpRequestRouter(co.cask.cdap.gateway.router.handlers.HttpRequestRouter) HttpStatusRequestHandler(co.cask.cdap.gateway.router.handlers.HttpStatusRequestHandler) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) AuditLogHandler(co.cask.cdap.gateway.router.handlers.AuditLogHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) AuthenticationHandler(co.cask.cdap.gateway.router.handlers.AuthenticationHandler)

Example 12 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class NettyContextTest method addByteEncoderWhenFullReactorPipeline.

@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
    });
    ChannelHandler encoder = new LineBasedFrameDecoder(12);
    testContext.addHandlerFirst("encoder", encoder);
    assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "encoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 13 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class NettyContextTest method addNonByteEncoderWhenFullReactorPipeline.

@Test
public void addNonByteEncoderWhenFullReactorPipeline() throws Exception {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
    });
    ChannelHandler encoder = new ChannelHandlerAdapter() {
    };
    testContext.addHandlerFirst("encoder", encoder);
    assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "encoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 14 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class NettyContextTest method addByteDecoderWhenFullReactorPipeline.

@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
    });
    ChannelHandler decoder = new LineBasedFrameDecoder(12);
    testContext.addHandlerLast("decoder", decoder).addHandlerFirst("decoder$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR));
    assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "decoder$extract", "decoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 15 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project neo4j by neo4j.

the class TransportSelectionHandler method switchToWebsocket.

private void switchToWebsocket(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    memoryTracker.allocateHeap(HTTP_SERVER_CODEC_SHALLOW_SIZE + HTTP_OBJECT_AGGREGATOR_SHALLOW_SIZE + WEB_SOCKET_SERVER_PROTOCOL_HANDLER_SHALLOW_SIZE + WEB_SOCKET_FRAME_AGGREGATOR_SHALLOW_SIZE + WebSocketFrameTranslator.SHALLOW_SIZE + ProtocolHandshaker.SHALLOW_SIZE);
    p.addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_WEBSOCKET_HANDSHAKE_SIZE), new WebSocketServerProtocolHandler("/", null, false, MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameAggregator(MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameTranslator(), newHandshaker());
    p.remove(this);
}
Also used : WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) WebSocketServerProtocolHandler(io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler) WebSocketFrameTranslator(org.neo4j.bolt.transport.pipeline.WebSocketFrameTranslator) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)54 ChannelPipeline (io.netty.channel.ChannelPipeline)35 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)30 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)11 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)11 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)10 Test (org.junit.Test)9 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)8 Channel (io.netty.channel.Channel)7 ChannelHandler (io.netty.channel.ChannelHandler)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)7 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)7 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)6 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)6 WebSocketServerProtocolHandler (io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler)6 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)6 SocketChannel (io.netty.channel.socket.SocketChannel)4 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)4