Search in sources :

Example 1 with InboundHttp2ToHttpAdapterBuilder

use of io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder in project netty by netty.

the class Http2ClientInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder().frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).propagateSettings(true).build())).frameLogger(logger).connection(connection).build();
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DelegatingDecompressorFrameListener(io.netty.handler.codec.http2.DelegatingDecompressorFrameListener) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) InboundHttp2ToHttpAdapterBuilder(io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder) HttpToHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder)

Example 2 with InboundHttp2ToHttpAdapterBuilder

use of io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder in project netty by netty.

the class InboundHttp2ToHttpAdapterTest method boostrapEnv.

private void boostrapEnv(int clientLatchCount, int clientLatchCount2, int serverLatchCount, int serverLatchCount2, int settingsLatchCount) throws InterruptedException {
    final CountDownLatch prefaceWrittenLatch = new CountDownLatch(1);
    clientDelegator = null;
    serverDelegator = null;
    serverConnectedChannel = null;
    maxContentLength = 1024;
    final CountDownLatch serverChannelLatch = new CountDownLatch(1);
    serverLatch = new CountDownLatch(serverLatchCount);
    clientLatch = new CountDownLatch(clientLatchCount);
    serverLatch2 = new CountDownLatch(serverLatchCount2);
    clientLatch2 = new CountDownLatch(clientLatchCount2);
    settingsLatch = new CountDownLatch(settingsLatchCount);
    sb = new ServerBootstrap();
    cb = new Bootstrap();
    sb.group(new DefaultEventLoopGroup());
    sb.channel(LocalServerChannel.class);
    sb.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            serverConnectedChannel = ch;
            ChannelPipeline p = ch.pipeline();
            Http2Connection connection = new DefaultHttp2Connection(true);
            serverHandler = new Http2ConnectionHandlerBuilder().frameListener(new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).validateHttpHeaders(true).propagateSettings(true).build()).connection(connection).gracefulShutdownTimeoutMillis(0).build();
            p.addLast(serverHandler);
            serverDelegator = new HttpResponseDelegator(serverListener, serverLatch, serverLatch2);
            p.addLast(serverDelegator);
            settingsDelegator = new HttpSettingsDelegator(settingsListener, settingsLatch);
            p.addLast(settingsDelegator);
            serverChannelLatch.countDown();
        }
    });
    cb.group(new DefaultEventLoopGroup());
    cb.channel(LocalChannel.class);
    cb.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            Http2Connection connection = new DefaultHttp2Connection(false);
            clientHandler = new Http2ConnectionHandlerBuilder().frameListener(new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength).build()).connection(connection).gracefulShutdownTimeoutMillis(0).build();
            p.addLast(clientHandler);
            clientDelegator = new HttpResponseDelegator(clientListener, clientLatch, clientLatch2);
            p.addLast(clientDelegator);
            p.addLast(new ChannelHandlerAdapter() {

                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                    Http2Exception e = getEmbeddedHttp2Exception(cause);
                    if (e != null) {
                        clientException = e;
                        clientLatch.countDown();
                    } else {
                        super.exceptionCaught(ctx, cause);
                    }
                }
            });
            p.addLast(new ChannelInboundHandlerAdapter() {

                public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                    if (evt instanceof Http2ConnectionPrefaceWrittenEvent) {
                        prefaceWrittenLatch.countDown();
                        ctx.pipeline().remove(this);
                    }
                }
            });
        }
    });
    serverChannel = sb.bind(new LocalAddress("InboundHttp2ToHttpAdapterTest")).sync().channel();
    ChannelFuture ccf = cb.connect(serverChannel.localAddress());
    assertTrue(ccf.awaitUninterruptibly().isSuccess());
    clientChannel = ccf.channel();
    assertTrue(prefaceWrittenLatch.await(5, SECONDS));
    assertTrue(serverChannelLatch.await(5, SECONDS));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Http2TestUtil.runInChannel(io.netty.handler.codec.http2.Http2TestUtil.runInChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) ChannelPipeline(io.netty.channel.ChannelPipeline) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) HttpObject(io.netty.handler.codec.http.HttpObject) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Example 3 with InboundHttp2ToHttpAdapterBuilder

use of io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder in project netty by netty.

the class Http2OrHttpHandler method configureHttp2.

private static void configureHttp2(ChannelHandlerContext ctx) {
    DefaultHttp2Connection connection = new DefaultHttp2Connection(true);
    InboundHttp2ToHttpAdapter listener = new InboundHttp2ToHttpAdapterBuilder(connection).propagateSettings(true).validateHttpHeaders(false).maxContentLength(MAX_CONTENT_LENGTH).build();
    ctx.pipeline().addLast(new HttpToHttp2ConnectionHandlerBuilder().frameListener(listener).connection(connection).build());
    ctx.pipeline().addLast(new Http2RequestHandler());
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) InboundHttp2ToHttpAdapterBuilder(io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder) InboundHttp2ToHttpAdapter(io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter) HttpToHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder)

Aggregations

DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2 HttpToHttp2ConnectionHandlerBuilder (io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder)2 InboundHttp2ToHttpAdapterBuilder (io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)1 LocalAddress (io.netty.channel.local.LocalAddress)1 LocalChannel (io.netty.channel.local.LocalChannel)1 LocalServerChannel (io.netty.channel.local.LocalServerChannel)1 HttpObject (io.netty.handler.codec.http.HttpObject)1 DelegatingDecompressorFrameListener (io.netty.handler.codec.http2.DelegatingDecompressorFrameListener)1 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)1 Http2Connection (io.netty.handler.codec.http2.Http2Connection)1 Http2TestUtil.runInChannel (io.netty.handler.codec.http2.Http2TestUtil.runInChannel)1