Search in sources :

Example 46 with HttpClientCodec

use of io.netty.handler.codec.http.HttpClientCodec 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)

Example 47 with HttpClientCodec

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

the class Http2ChannelInitializer method configureClearText.

/**
 * Configure the pipeline for HTTP/2 clear text.
 */
private void configureClearText(NioSocketChannel channel) {
    final HttpClientCodec sourceCodec = new HttpClientCodec(_maxInitialLineLength, _maxHeaderSize, _maxChunkSize);
    UnsupportedHandler unsupportedHandler = new UnsupportedHandler();
    Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(unsupportedHandler, unsupportedHandler);
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec((Http2ConnectionHandler) Http2FrameCodecBuilder.forClient().initialSettings(createHttp2Settings()).build(), multiplexHandler);
    final ChannelPromise upgradePromise = channel.newPromise();
    channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(upgradePromise);
    channel.pipeline().addLast(sourceCodec);
    channel.pipeline().addLast(new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, _maxContentLength));
    channel.pipeline().addLast(new Http2ProtocolUpgradeHandler(upgradePromise));
}
Also used : UnsupportedHandler(com.linkedin.r2.netty.handler.http2.UnsupportedHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2ProtocolUpgradeHandler(com.linkedin.r2.netty.handler.http2.Http2ProtocolUpgradeHandler) Http2ClientUpgradeCodec(io.netty.handler.codec.http2.Http2ClientUpgradeCodec) ChannelPromise(io.netty.channel.ChannelPromise) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpClientUpgradeHandler(io.netty.handler.codec.http.HttpClientUpgradeHandler)

Example 48 with HttpClientCodec

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

the class Http2ClientPipelineInitializer method configureHttpPipeline.

/**
 * Sets up HTTP/2 over TCP through protocol upgrade (h2c) pipeline
 */
private void configureHttpPipeline(Channel channel, Http2Connection connection) throws Exception {
    Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(connection).maxContentLength(_maxResponseSize).gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).build();
    HttpClientCodec sourceCodec = new HttpClientCodec(MAX_INITIAL_LINE_LENGTH, _maxHeaderSize, _maxChunkSize);
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(http2Codec);
    HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, MAX_CLIENT_UPGRADE_CONTENT_LENGTH);
    Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTP.toString());
    Http2UpgradeHandler upgradeRequestHandler = new Http2UpgradeHandler();
    Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler();
    channel.pipeline().addLast("sourceCodec", sourceCodec);
    channel.pipeline().addLast("upgradeHandler", upgradeHandler);
    channel.pipeline().addLast("upgradeRequestHandler", upgradeRequestHandler);
    channel.pipeline().addLast("schemeHandler", schemeHandler);
    channel.pipeline().addLast("responseHandler", responseHandler);
}
Also used : Http2ClientUpgradeCodec(io.netty.handler.codec.http2.Http2ClientUpgradeCodec) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpClientUpgradeHandler(io.netty.handler.codec.http.HttpClientUpgradeHandler)

Example 49 with HttpClientCodec

use of io.netty.handler.codec.http.HttpClientCodec in project zuul by Netflix.

the class DefaultOriginChannelInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    final ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new PassportStateOriginHandler.InboundHandler());
    pipeline.addLast(new PassportStateOriginHandler.OutboundHandler());
    if (connectionPoolConfig.isSecure()) {
        pipeline.addLast("ssl", sslContext.newHandler(ch.alloc()));
    }
    pipeline.addLast(HTTP_CODEC_HANDLER_NAME, new HttpClientCodec(BaseZuulChannelInitializer.MAX_INITIAL_LINE_LENGTH.get(), BaseZuulChannelInitializer.MAX_HEADER_SIZE.get(), BaseZuulChannelInitializer.MAX_CHUNK_SIZE.get(), false, false));
    pipeline.addLast(new PassportStateHttpClientHandler.InboundHandler());
    pipeline.addLast(new PassportStateHttpClientHandler.OutboundHandler());
    pipeline.addLast("originNettyLogger", nettyLogger);
    pipeline.addLast(httpMetricsHandler);
    addMethodBindingHandler(pipeline);
    pipeline.addLast(HttpClientLifecycleChannelHandler.INBOUND_CHANNEL_HANDLER);
    pipeline.addLast(HttpClientLifecycleChannelHandler.OUTBOUND_CHANNEL_HANDLER);
    pipeline.addLast(new ClientTimeoutHandler.InboundHandler());
    pipeline.addLast(new ClientTimeoutHandler.OutboundHandler());
    pipeline.addLast("connectionPoolHandler", connectionPoolHandler);
}
Also used : PassportStateOriginHandler(com.netflix.zuul.netty.insights.PassportStateOriginHandler) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) PassportStateHttpClientHandler(com.netflix.zuul.netty.insights.PassportStateHttpClientHandler)

Example 50 with HttpClientCodec

use of io.netty.handler.codec.http.HttpClientCodec in project riposte by Nike-Inc.

the class ComponentTestUtils method createNettyHttpClientBootstrap.

public static Bootstrap createNettyHttpClientBootstrap() {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup()).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpClientCodec());
            p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
            p.addLast("clientResponseHandler", new SimpleChannelInboundHandler<HttpObject>() {

                @Override
                protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
                    throw new RuntimeException("Client response handler was not setup before the call");
                }
            });
        }
    });
    return bootstrap;
}
Also used : SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) SocketChannel(io.netty.channel.socket.SocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) TimeoutException(java.util.concurrent.TimeoutException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ChannelPipeline(io.netty.channel.ChannelPipeline) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpObject(io.netty.handler.codec.http.HttpObject) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)55 ChannelPipeline (io.netty.channel.ChannelPipeline)29 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)26 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)25 Bootstrap (io.netty.bootstrap.Bootstrap)19 Channel (io.netty.channel.Channel)17 SocketChannel (io.netty.channel.socket.SocketChannel)17 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)15 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)14 HttpRequest (io.netty.handler.codec.http.HttpRequest)11 IOException (java.io.IOException)11 SslContext (io.netty.handler.ssl.SslContext)10 ChannelInitializer (io.netty.channel.ChannelInitializer)9 EventLoopGroup (io.netty.channel.EventLoopGroup)9 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 URI (java.net.URI)9 URISyntaxException (java.net.URISyntaxException)9 ChannelFuture (io.netty.channel.ChannelFuture)8 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)7 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)7