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();
}
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));
}
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);
}
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);
}
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;
}
Aggregations