.pipeline() .addLast("codec", new HttpClientCodec()) .addLast("application codec", new Http1ClientCodec());
@Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (protocol.equals(ApplicationProtocolNames.HTTP_1_1)) { replaceCodec(ctx, new HttpClientCodec()); replaceApplicationCodec(ctx, new Http1ClientCodec()); ctx.fireUserEventTriggered(RequestBuffer.WriteReady.INSTANCE); } else if (protocol.equals(ApplicationProtocolNames.HTTP_2)) { replaceCodec(ctx, http2Handler.get()); replaceApplicationCodec(ctx, new Http2ClientCodec()); } else { throw new RuntimeException("Unknown Application Protocol '" + protocol + "'"); } } }
public void initChannel(Channel channel) { if (enableTls) { ClientConfig config = ClientConfig.fromConfig("xio.h1TestClient"); SslContext sslContext = SslContextFactory.buildClientContext(config.getTls()); channel .pipeline() .addLast( sslContext.newHandler( channel.alloc(), remote.getHostString(), remote.getPort())); } channel .pipeline() .addLast(new HttpClientCodec()) .addLast(new Http1ClientCodec()) .addLast(new RawBackendHandler(ctx)); } });
@Before public void setUp() { channel .pipeline() .addLast( "nextRequest", new ChannelOutboundHandlerAdapter() { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { log.debug("request: " + msg); requests.add((HttpObject) msg); outputReceived.countDown(); } }); channel.pipeline().addLast("handler", new Http1ClientCodec()); channel .pipeline() .addLast( "nextResponse", new SimpleChannelInboundHandler<Response>() { @Override protected void channelRead0(ChannelHandlerContext ctx, Response msg) { log.debug("response: " + msg); responses.add(msg); outputReceived.countDown(); } }); }