Example usage for io.netty.handler.codec.http2 HttpToHttp2ConnectionHandlerBuilder HttpToHttp2ConnectionHandlerBuilder

List of usage examples for io.netty.handler.codec.http2 HttpToHttp2ConnectionHandlerBuilder HttpToHttp2ConnectionHandlerBuilder

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 HttpToHttp2ConnectionHandlerBuilder HttpToHttp2ConnectionHandlerBuilder.

Prototype

HttpToHttp2ConnectionHandlerBuilder

Source Link

Usage

From source file:ccwihr.client.t2.Http2ClientInitializer.java

License:Apache License

@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);//from   ww  w.j  a  v a  2  s  .  c  om
    } else {
        configureClearText(ch);
    }
}

From source file:cn.jpush.api.common.connection.Http2ClientInitializer.java

License:Apache License

@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(mNettyHttp2Client);
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);//w  w w  .  j a v a2  s .c  om
    } else {
        configureClearText(ch);
    }
}

From source file:com.flysoloing.learning.network.netty.http2.tiles.Http2OrHttpHandler.java

License:Apache License

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)
            // .frameLogger(TilesHttp2ToHttpHandler.logger)
            .connection(connection).build());

    ctx.pipeline().addLast(new Http2RequestHandler());
}

From source file:com.hop.hhxx.example.http2.helloworld.client.Http2ClientInitializer.java

License:Apache License

@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 io.netty.example.http2.helloworld.client.HttpResponseHandler();
    settingsHandler = new io.netty.example.http2.helloworld.client.Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);//from   w ww  .  j  ava 2s  .  c  o  m
    } else {
        configureClearText(ch);
    }
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpServerInitializer.java

License:Open Source License

/**
 * For HTTP/2 we don't have anything as simple as the HttpServerCodec (at least, not in Netty
 * 5.0alpha 2), so we create the equivalent.
 *
 * @return//from w  w  w.j a va  2  s  .c  o  m
 */
private HttpToHttp2ConnectionHandler makeHttp2ConnectionHandler() {
    // DefaultHttp2Connection is for client or server. True means "server".
    Http2Connection connection = new DefaultHttp2Connection(true);
    InboundHttp2ToHttpAdapter inboundAdapter = new InboundHttp2ToHttpAdapterBuilder(connection)
            .maxContentLength(this.responsePayloadSizeLimit).propagateSettings(false).build();
    DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener(connection,
            inboundAdapter);

    Http2Settings settings = new Http2Settings();
    //settings.maxConcurrentStreams(NettyHttpServiceClient.DEFAULT_HTTP2_STREAMS_PER_HOST);
    settings.initialWindowSize(NettyChannelContext.INITIAL_HTTP2_WINDOW_SIZE);

    HttpToHttp2ConnectionHandlerBuilder builder = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(frameListener).initialSettings(settings).connection(connection);

    if (debugLogging) {
        Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.INFO,
                NettyHttpClientRequestInitializer.class);
        builder.frameLogger(frameLogger);
    }

    HttpToHttp2ConnectionHandler connectionHandler = builder.build();

    return connectionHandler;
}

From source file:http.HTTPClientInitializer.java

License:Open Source License

@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 HTTPSettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);/*ww  w  . j av  a 2 s . c  om*/
    } else {
        configureClearText(ch);
    }
}

From source file:io.bsoa.rpc.grpc.client12.Http2ClientInitializer.java

License:Apache License

@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());

    HttpClientCodec sourceCodec = new HttpClientCodec();
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec("connectionHandler", connectionHandler);
    HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536);

    ch.pipeline().addLast("sourceCodec?", sourceCodec);
    ch.pipeline().addLast("upgradeHandlerupgrade", upgradeHandler);
    ch.pipeline().addLast("UpgradeRequestHandler?upgrade", new UpgradeRequestHandler());
    ch.pipeline().addLast("UserEventLogger", new UserEventLogger());

    System.out.println("======1=======>" + ch.pipeline().names() + "<=========" + ch.pipeline().toMap());
}

From source file:io.gatling.http.client.impl.DefaultHttpClient.java

License:Apache License

private Future<Channel> installHttp2Handler(HttpTx tx, Channel channel, ChannelPool channelPool) {

    Promise<Channel> whenAlpn = channel.eventLoop().newPromise();

    channel.pipeline().addAfter(SSL_HANDLER, ALPN_HANDLER,
            new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) {
                @Override//from w w w. ja va2 s. co m
                protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {

                    switch (protocol) {
                    case ApplicationProtocolNames.HTTP_2:
                        LOGGER.debug("ALPN led to HTTP/2 with remote {}", tx.request.getUri().getHost());
                        tx.listener.onProtocolAwareness(true);
                        Http2Connection connection = new DefaultHttp2Connection(false);

                        HttpToHttp2ConnectionHandler http2Handler = new HttpToHttp2ConnectionHandlerBuilder()
                                .initialSettings(Http2Settings.defaultSettings()) // FIXME override?
                                .connection(connection)
                                .frameListener(new DelegatingDecompressorFrameListener(connection,
                                        new ChunkedInboundHttp2ToHttpAdapter(connection, false, true,
                                                whenAlpn)))
                                .build();

                        ctx.pipeline().addLast(HTTP2_HANDLER, http2Handler).addLast(APP_HTTP2_HANDLER,
                                new Http2AppHandler(connection, http2Handler, channelPool, config));

                        channelPool.offer(channel);

                        SslHandler sslHandler = (SslHandler) ctx.pipeline().get(SSL_HANDLER);
                        Set<String> subjectAlternativeNames = Tls
                                .extractSubjectAlternativeNames(sslHandler.engine());
                        if (!subjectAlternativeNames.isEmpty()) {
                            channelPool.addCoalescedChannel(subjectAlternativeNames,
                                    (InetSocketAddress) channel.remoteAddress(), channel, tx.key);
                        }
                        break;

                    case ApplicationProtocolNames.HTTP_1_1:
                        LOGGER.debug("ALPN led to HTTP/1 with remote {}", tx.request.getUri().getHost());
                        if (tx.request.isHttp2PriorKnowledge()) {
                            IllegalStateException e = new IllegalStateException(
                                    "HTTP/2 Prior knowledge was set on host " + tx.request.getUri().getHost()
                                            + " but it only supports HTTP/1");
                            whenAlpn.setFailure(e);
                            throw e;
                        }
                        tx.listener.onProtocolAwareness(false);
                        ctx.pipeline()
                                .addBefore(CHUNKED_WRITER_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec())
                                .addBefore(CHUNKED_WRITER_HANDLER, INFLATER_HANDLER,
                                        newHttpContentDecompressor())
                                .addAfter(CHUNKED_WRITER_HANDLER, APP_HTTP_HANDLER,
                                        new HttpAppHandler(DefaultHttpClient.this, channelPool, config));
                        whenAlpn.setSuccess(ctx.channel());
                        break;

                    default:
                        IllegalStateException e = new IllegalStateException("Unknown protocol: " + protocol);
                        whenAlpn.setFailure(e);
                        ctx.close();
                        // FIXME do we really need to throw?
                        throw e;
                    }
                }
            });

    whenAlpn.addListener(f -> {
        if (!f.isSuccess()) {
            tx.listener.onThrowable(f.cause());
        }
    });

    return whenAlpn;
}

From source file:netty.http2.NettyHttp2ClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    final Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(65535);/* w  w  w.j a  va2  s .c  o  m*/
    settings.headerTableSize(4096);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength)
                            .propagateSettings(true).build()))
            .frameLogger(logger).initialSettings(settings).connection(connection).build();
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}

From source file:org.ballerinalang.test.util.http2.HTTP2ClientInitializer.java

License:Open Source License

@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 HTTP2ResponseHandler();
    settingsHandler = new HTTP2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);/* w w w. j  a v a 2s  .  c om*/
    } else {
        configureClearText(ch);
    }
}