Search in sources :

Example 51 with HttpClientCodec

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

the class HttpUploadClientInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast("codec", new HttpClientCodec());
    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());
    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("handler", new HttpUploadClientHandler());
}
Also used : ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor)

Example 52 with HttpClientCodec

use of org.apache.flink.shaded.netty4.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 53 with HttpClientCodec

use of org.apache.flink.shaded.netty4.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 54 with HttpClientCodec

use of org.apache.flink.shaded.netty4.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 55 with HttpClientCodec

use of org.apache.flink.shaded.netty4.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)

Aggregations

HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)61 ChannelPipeline (io.netty.channel.ChannelPipeline)30 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)19 SocketChannel (io.netty.channel.socket.SocketChannel)17 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)16 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)15 IOException (java.io.IOException)13 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)12 HttpRequest (io.netty.handler.codec.http.HttpRequest)12 SslContext (io.netty.handler.ssl.SslContext)12 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)11 URISyntaxException (java.net.URISyntaxException)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 ChannelInitializer (io.netty.channel.ChannelInitializer)9 URI (java.net.URI)9 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)8 InetSocketAddress (java.net.InetSocketAddress)8