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

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

Introduction

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

Prototype

public Http2Settings() 

Source Link

Usage

From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java

License:Apache License

private Http2ClientConnectionHandler newHttp2ConnectionHandler(Channel ch) {
    final boolean validateHeaders = false;
    final Http2Connection conn = new DefaultHttp2Connection(false);
    conn.addListener(new Http2GoAwayListener(ch));

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

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

    final Http2ResponseDecoder listener = new Http2ResponseDecoder(ch);

    final Http2ClientConnectionHandler handler = new Http2ClientConnectionHandler(decoder, encoder,
            new Http2Settings(), listener);

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

    return handler;
}

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

License:Apache License

private Http2Settings http2Settings() {
    final Http2Settings http2Settings = new Http2Settings();
    if (clientFactory.initialHttp2StreamWindowSize() != DEFAULT_WINDOW_SIZE) {
        http2Settings.initialWindowSize(clientFactory.initialHttp2StreamWindowSize());
    }/*ww  w .jav a2 s.  c o m*/
    if (clientFactory.http2MaxFrameSize() != DEFAULT_MAX_FRAME_SIZE) {
        http2Settings.maxFrameSize(clientFactory.http2MaxFrameSize());
    }
    return http2Settings;
}

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.http.HttpServerPipelineConfigurator.java

License:Apache License

private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) {

    final Http2Connection conn = new DefaultHttp2Connection(true);
    conn.addListener(new Http2GoAwayListener(pipeline.channel()));

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

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

    final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder,
            new Http2Settings());

    // Setup post build options
    final Http2RequestDecoder listener = new Http2RequestDecoder(pipeline.channel(), handler.encoder());

    handler.connection().addListener(listener);
    handler.decoder().frameListener(listener);
    handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis());

    return handler;
}

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

License:Apache License

private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) {

    final Http2Connection conn = new DefaultHttp2Connection(true);
    conn.addListener(new Http2GoAwayListener(pipeline.channel()));

    final Http2FrameReader reader = new DefaultHttp2FrameReader(true);
    final Http2FrameWriter writer = new DefaultHttp2FrameWriter();

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

    final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder,
            new Http2Settings());

    // Setup post build options
    final Http2RequestDecoder listener = new Http2RequestDecoder(config, pipeline.channel(), handler.encoder());

    handler.connection().addListener(listener);
    handler.decoder().frameListener(listener);
    handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis());

    return handler;
}

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

License:Apache License

private Http2ConnectionHandler createHttp2ConnectionHandler(ChannelPipeline pipeline,
        ChannelHandler... toRemove) {//from  w ww.j  av  a2 s  .  co  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.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    // // w  ww.  ja  v  a2 s  . c o  m
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(DEFAULT_FLOW_CONTROL_WINDOW);
    settings.pushEnabled(false);
    settings.maxConcurrentStreams(0);
    ByteBuf preface = Http2CodecUtil.connectionPrefaceBuf().retainedDuplicate();
    ctx.write(preface);
    writer.writeSettings(ctx, settings, ctx.newPromise());
    writer.writeWindowUpdate(ctx, 0, 983041, ctx.newPromise());
    ctx.flush();
    ctx.read();
}

From source file:com.turo.pushy.apns.BenchmarkApnsServer.java

License:Open Source License

public BenchmarkApnsServer(final InputStream certificateChainInputStream,
        final InputStream privateKeyPkcs8InputStream, final NioEventLoopGroup eventLoopGroup)
        throws SSLException {
    final SslContext sslContext;
    {//from  w  w  w. j a v a  2s . c  om
        final SslProvider sslProvider;

        if (OpenSsl.isAvailable()) {
            if (OpenSsl.isAlpnSupported()) {
                sslProvider = SslProvider.OPENSSL;
            } else {
                sslProvider = SslProvider.JDK;
            }
        } else {
            sslProvider = SslProvider.JDK;
        }

        sslContext = SslContextBuilder.forServer(certificateChainInputStream, privateKeyPkcs8InputStream, null)
                .sslProvider(sslProvider)
                .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
                .clientAuth(ClientAuth.OPTIONAL)
                .applicationProtocolConfig(
                        new ApplicationProtocolConfig(ApplicationProtocolConfig.Protocol.ALPN,
                                ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
                                ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
                                ApplicationProtocolNames.HTTP_2))
                .build();
    }

    this.bootstrap = new ServerBootstrap();
    this.bootstrap.group(eventLoopGroup);

    this.bootstrap.channel(NioServerSocketChannel.class);
    this.bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel channel) throws Exception {
            final SslHandler sslHandler = sslContext.newHandler(channel.alloc());
            channel.pipeline().addLast(sslHandler);
            channel.pipeline()
                    .addLast(new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) {

                        @Override
                        protected void configurePipeline(final ChannelHandlerContext context,
                                final String protocol) throws Exception {
                            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                                context.pipeline().addLast(
                                        new BenchmarkApnsServerHandler.BenchmarkApnsServerHandlerBuilder()
                                                .initialSettings(new Http2Settings()
                                                        .maxConcurrentStreams(MAX_CONCURRENT_STREAMS))
                                                .build());

                                BenchmarkApnsServer.this.allChannels.add(context.channel());
                            } else {
                                throw new IllegalStateException("Unexpected protocol: " + protocol);
                            }
                        }
                    });
        }
    });
}

From source file:com.turo.pushy.apns.MockApnsServer.java

License:Open Source License

protected MockApnsServer(final SslContext sslContext, final EventLoopGroup eventLoopGroup) {
    this.bootstrap = new ServerBootstrap();

    if (eventLoopGroup != null) {
        this.bootstrap.group(eventLoopGroup);
        this.shouldShutDownEventLoopGroup = false;
    } else {//from w  ww  . j a v  a  2s.co  m
        this.bootstrap.group(new NioEventLoopGroup(1));
        this.shouldShutDownEventLoopGroup = true;
    }

    this.bootstrap.channel(SocketChannelClassUtil.getServerSocketChannelClass(this.bootstrap.config().group()));
    this.bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel channel) throws Exception {
            final SslHandler sslHandler = sslContext.newHandler(channel.alloc());
            channel.pipeline().addLast(sslHandler);
            channel.pipeline()
                    .addLast(new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) {

                        @Override
                        protected void configurePipeline(final ChannelHandlerContext context,
                                final String protocol) throws Exception {
                            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                                AbstractMockApnsServerHandler.AbstractMockApnsServerHandlerBuilder handlerBuilder;

                                try {
                                    final SSLSession sslSession = sslHandler.engine().getSession();

                                    // This will throw an exception if the peer hasn't authenticated (i.e. we're expecting
                                    // token authentication).
                                    final String principalName = sslSession.getPeerPrincipal().getName();

                                    final Pattern pattern = Pattern.compile(".*UID=([^,]+).*");
                                    final Matcher matcher = pattern.matcher(principalName);

                                    final String baseTopic;

                                    if (matcher.matches()) {
                                        baseTopic = matcher.group(1);
                                    } else {
                                        throw new IllegalArgumentException(
                                                "Client certificate does not specify a base topic.");
                                    }

                                    final TlsAuthenticationMockApnsServerHandler.TlsAuthenticationMockApnsServerHandlerBuilder tlsAuthenticationHandlerBuilder = new TlsAuthenticationMockApnsServerHandler.TlsAuthenticationMockApnsServerHandlerBuilder();

                                    tlsAuthenticationHandlerBuilder.baseTopic(baseTopic);

                                    handlerBuilder = tlsAuthenticationHandlerBuilder;
                                } catch (final SSLPeerUnverifiedException e) {
                                    // No need for alarm; this is an expected case
                                    final TokenAuthenticationMockApnsServerHandler.TokenAuthenticationMockApnsServerHandlerBuilder tokenAuthenticationHandlerBuilder = new TokenAuthenticationMockApnsServerHandler.TokenAuthenticationMockApnsServerHandlerBuilder();

                                    tokenAuthenticationHandlerBuilder.verificationKeysByKeyId(
                                            MockApnsServer.this.verificationKeysByKeyId);
                                    tokenAuthenticationHandlerBuilder.topicsByVerificationKey(
                                            MockApnsServer.this.topicsByVerificationKey);
                                    tokenAuthenticationHandlerBuilder.emulateExpiredFirstToken(
                                            MockApnsServer.this.emulateExpiredFirstToken);

                                    handlerBuilder = tokenAuthenticationHandlerBuilder;
                                }

                                context.pipeline().addLast(handlerBuilder
                                        .initialSettings(new Http2Settings().maxConcurrentStreams(8))
                                        .emulateInternalErrors(MockApnsServer.this.emulateInternalErrors)
                                        .deviceTokenExpirationsByTopic(
                                                MockApnsServer.this.deviceTokenExpirationsByTopic)
                                        .build());

                                MockApnsServer.this.allChannels.add(context.channel());
                            } else {
                                throw new IllegalStateException("Unexpected protocol: " + protocol);
                            }
                        }
                    });
        }
    });
}

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//from  w  w  w  .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;
}