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

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

Introduction

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

Prototype

public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener) 

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  www  .  j av a2s  .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);/*from  www .  java2  s .  c o m*/
    } else {
        configureClearText(ch);
    }
}

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 w w  .  j a v  a2 s  . com
    } else {
        configureClearText(ch);
    }
}

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/* www  . j a v a  2 s.  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/*w  w  w  .  jav  a  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);//w ww  .  ja  va 2  s  .  co  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());
}

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   ww w. j  ava2  s.c o 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:io.vertx.core.http.impl.VertxHttp2ConnectionHandlerBuilder.java

License:Open Source License

@Override
protected VertxHttp2ConnectionHandler<C> build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
        Http2Settings initialSettings) throws Exception {
    if (isServer()) {
        if (useCompression) {
            encoder = new CompressorHttp2ConnectionEncoder(encoder, compressionLevel,
                    CompressorHttp2ConnectionEncoder.DEFAULT_WINDOW_BITS,
                    CompressorHttp2ConnectionEncoder.DEFAULT_MEM_LEVEL);
        }//w w w .  j  a  v a2 s  . co m
        VertxHttp2ConnectionHandler<C> handler = new VertxHttp2ConnectionHandler<>(connectionMap, decoder,
                encoder, initialSettings, connectionFactory);
        if (useDecompression) {
            frameListener(new DelegatingDecompressorFrameListener(decoder.connection(), handler.connection));
        } else {
            frameListener(handler.connection);
        }
        return handler;
    } else {
        VertxHttp2ConnectionHandler<C> handler = new VertxHttp2ConnectionHandler<>(connectionMap, decoder,
                encoder, initialSettings, connectionFactory);
        if (useCompression) {
            frameListener(new DelegatingDecompressorFrameListener(decoder.connection(), handler.connection));
        } else {
            frameListener(handler.connection);
        }
        return handler;
    }
}

From source file:jmeter.plugins.http2.sampler.Http2ClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);

    connectionHandler = new HttpToHttp2ConnectionHandler(connection, frameReader(), frameWriter(),
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection).maxContentLength(maxContentLength)
                            .propagateSettings(true).build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);/* w w  w .j  a va2 s  .  co m*/
    } else {
        configureClearText(ch);
    }
}