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

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

Introduction

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

Prototype

public InboundHttp2ToHttpAdapterBuilder(Http2Connection connection) 

Source Link

Document

Creates a new InboundHttp2ToHttpAdapter builder for the specified Http2Connection .

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);/* ww  w. j  a va  2s.  c o  m*/
    } 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);/*ww  w . ja va  2  s .  co m*/
    } 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);/* www . ja  v  a 2 s .  co  m*/
    } else {
        configureClearText(ch);
    }
}

From source file:com.linecorp.armeria.client.HttpConfigurator.java

License:Apache License

private Http2ConnectionHandler newHttp2ConnectionHandler(Channel ch) {
    final boolean validateHeaders = false;
    final Http2Connection conn = new DefaultHttp2Connection(false);
    conn.addListener(new Http2GoAwayListener(ch));
    final InboundHttp2ToHttpAdapter listener = new InboundHttp2ToHttpAdapterBuilder(conn)
            .propagateSettings(true).validateHttpHeaders(validateHeaders)
            .maxContentLength(options.maxFrameLength()).build();

    Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders);
    Http2FrameWriter writer = new DefaultHttp2FrameWriter();

    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer);
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader);

    final HttpToHttp2ClientConnectionHandler handler = new HttpToHttp2ClientConnectionHandler(decoder, encoder,
            new Http2Settings(), validateHeaders);

    // Setup post build options
    handler.gracefulShutdownTimeoutMillis(options.idleTimeoutMillis());
    handler.decoder().frameListener(listener);

    return handler;
}

From source file:com.linecorp.armeria.server.ServerInitializer.java

License:Apache License

private Http2ConnectionHandler createHttp2ConnectionHandler(ChannelPipeline pipeline,
        ChannelHandler... toRemove) {// ww  w  .  j  ava 2 s. c  o  m
    final boolean validateHeaders = true;
    final Http2Connection conn = new DefaultHttp2Connection(true);
    conn.addListener(new Http2GoAwayListener(pipeline.channel()));

    final Http2FrameListener listener = new InboundHttp2ToHttpAdapterBuilder(conn).propagateSettings(true)
            .validateHttpHeaders(validateHeaders).maxContentLength(config.maxFrameLength()).build();

    Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders);
    Http2FrameWriter writer = new DefaultHttp2FrameWriter();

    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer);
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader);

    final HttpToHttp2ServerConnectionHandler handler = new HttpToHttp2ServerConnectionHandler(pipeline, decoder,
            encoder, new Http2Settings(), validateHeaders, toRemove);

    // Setup post build options
    handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis());
    handler.decoder().frameListener(listener);

    return handler;
}

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

License:Open Source License

/**
 * For HTTP/2 we don't have anything as simple as the HttpClientCodec (at least, not in Netty
 * 5.0alpha 2), so we create the equivalent here.
 *
 * @return/*  w  w  w  .jav a  2s.  co m*/
 */
private NettyHttpToHttp2Handler makeHttp2ConnectionHandler() {
    // DefaultHttp2Connection is for client or server. False means "client".
    Http2Connection connection = new DefaultHttp2Connection(false);
    InboundHttp2ToHttpAdapter inboundAdapter = new InboundHttp2ToHttpAdapterBuilder(connection)
            .maxContentLength(this.requestPayloadSizeLimit).propagateSettings(true).build();
    DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener(connection,
            inboundAdapter);

    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(NettyChannelContext.INITIAL_HTTP2_WINDOW_SIZE);

    NettyHttpToHttp2HandlerBuilder builder = new NettyHttpToHttp2HandlerBuilder().connection(connection)
            .frameListener(frameListener).initialSettings(settings);
    if (this.debugLogging) {
        Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.INFO,
                NettyHttpClientRequestInitializer.class);
        builder.frameLogger(frameLogger);
    }
    NettyHttpToHttp2Handler connectionHandler = builder.build();

    return connectionHandler;
}

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  ww.j  ava 2s .com
 */
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);/* w w  w .j  a  v  a2  s.  c  o m*/
    } 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());
}