Example usage for io.vertx.core.http HttpServerOptions setUseAlpn

List of usage examples for io.vertx.core.http HttpServerOptions setUseAlpn

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerOptions setUseAlpn.

Prototype

@Override
    public HttpServerOptions setUseAlpn(boolean useAlpn) 

Source Link

Usage

From source file:io.apiman.test.common.echo.EchoServerVertx.java

License:Apache License

private HttpServerOptions getHttpServerOptions(String name) {
    HttpServerOptions options = new HttpServerOptions();
    HttpServerOptionsConverter.fromJson(config().getJsonObject(name, new JsonObject()), options);
    if (JdkSSLEngineOptions.isAlpnAvailable()) {
        options.setUseAlpn(true);
    }/*from   w w w.j av a 2  s  . co  m*/
    return options;
}

From source file:io.gravitee.am.gateway.vertx.VertxHttpServerFactory.java

License:Apache License

@Override
public HttpServer getObject() throws Exception {
    HttpServerOptions options = new HttpServerOptions();

    // Binding port
    options.setPort(httpServerConfiguration.getPort());
    options.setHost(httpServerConfiguration.getHost());

    // Netty pool buffers must be enabled by default
    options.setUsePooledBuffers(true);//from  ww w  .ja va 2s .  c  om

    if (httpServerConfiguration.isSecured()) {
        options.setSsl(httpServerConfiguration.isSecured());
        options.setUseAlpn(httpServerConfiguration.isAlpn());

        if (httpServerConfiguration.isClientAuth()) {
            options.setClientAuth(ClientAuth.REQUIRED);
        }

        if (httpServerConfiguration.getTrustStorePath() != null) {
            options.setTrustStoreOptions(new JksOptions().setPath(httpServerConfiguration.getTrustStorePath())
                    .setPassword(httpServerConfiguration.getTrustStorePassword()));
        }

        if (httpServerConfiguration.getKeyStorePath() != null) {
            options.setKeyStoreOptions(new JksOptions().setPath(httpServerConfiguration.getKeyStorePath())
                    .setPassword(httpServerConfiguration.getKeyStorePassword()));
        }
    }

    // Customizable configuration
    options.setCompressionSupported(httpServerConfiguration.isCompressionSupported());
    options.setIdleTimeout(httpServerConfiguration.getIdleTimeout());
    options.setTcpKeepAlive(httpServerConfiguration.isTcpKeepAlive());

    return vertx.createHttpServer(options);
}

From source file:io.nitor.api.backend.tls.SetupHttpServerOptions.java

License:Apache License

public static HttpServerOptions createHttpServerOptions(JsonObject config) {
    JsonObject tls = config.getJsonObject("tls");
    HttpServerOptions httpOptions = new HttpServerOptions()
            // basic TCP/HTTP options
            .setReuseAddress(true).setCompressionSupported(false) // otherwise it automatically compresses based on response headers even if pre-compressed with e.g. proxy
            .setUsePooledBuffers(true).setCompressionLevel(2)
            .setIdleTimeout(config.getInteger("idleTimeout", (int) MINUTES.toSeconds(10)));

    if (!config.getBoolean("http2", true)) {
        httpOptions.setAlpnVersions(asList(HTTP_1_1));
    }/*from w w  w.j a v a2 s  .  com*/

    if (tls != null) {
        httpOptions.setSsl(true)
                // server side certificate
                .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath(tls.getString("serverKey"))
                        .setCertPath(tls.getString("serverCert")))
                // TLS tuning
                .addEnabledSecureTransportProtocol("TLSv1.2").addEnabledSecureTransportProtocol("TLSv1.3");

        JsonObject clientAuth = config.getJsonObject("clientAuth");
        if (httpOptions.isSsl() && clientAuth != null && clientAuth.getString("clientChain") != null) {
            // client side certificate
            httpOptions.setClientAuth(REQUEST)
                    .setTrustOptions(new PemTrustOptions().addCertPath(clientAuth.getString("clientChain")));
        }
        if (TRUE.equals(config.getBoolean("useNativeOpenSsl"))) {
            httpOptions.setUseAlpn(true).setSslEngineOptions(new OpenSSLEngineOptions());
            cipherSuites.stream().map(SetupHttpServerOptions::javaCipherNameToOpenSSLName)
                    .forEach(httpOptions::addEnabledCipherSuite);
        } else {
            httpOptions.setUseAlpn(DynamicAgent.enableJettyAlpn())
                    .setJdkSslEngineOptions(new JdkSSLEngineOptions());
            cipherSuites.forEach(httpOptions::addEnabledCipherSuite);
        }
    }

    return httpOptions;
}

From source file:org.apache.servicecomb.transport.rest.vertx.RestServerVerticle.java

License:Apache License

private HttpServerOptions createDefaultHttpServerOptions() {
    HttpServerOptions serverOptions = new HttpServerOptions();
    serverOptions.setUsePooledBuffers(true);
    serverOptions.setIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
    serverOptions.setCompressionSupported(TransportConfig.getCompressed());
    serverOptions.setMaxHeaderSize(TransportConfig.getMaxHeaderSize());
    serverOptions.setMaxInitialLineLength(TransportConfig.getMaxInitialLineLength());
    if (endpointObject.isHttp2Enabled()) {
        serverOptions.setUseAlpn(TransportConfig.getUseAlpn()).setInitialSettings(
                new Http2Settings().setMaxConcurrentStreams(TransportConfig.getMaxConcurrentStreams()));
    }//  www  .java 2 s. c  om
    if (endpointObject.isSslEnabled()) {
        SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(SSL_KEY, null);
        SSLOption sslOption;
        if (factory == null) {
            sslOption = SSLOption.buildFromYaml(SSL_KEY);
        } else {
            sslOption = factory.createSSLOption();
        }
        SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass());
        VertxTLSBuilder.buildNetServerOptions(sslOption, sslCustom, serverOptions);
    }

    return serverOptions;
}

From source file:space.xkr47.vertx.acme4j.util.SetupHttpServerOptions.java

License:Apache License

public static HttpServerOptions createHttpServerOptions(DynamicCertOptions dynamicCertOptions,
        boolean jettyAgentAlreadyLoaded) {
    HttpServerOptions httpOptions = new HttpServerOptions()
            // basic TCP/HTTP options
            .setReuseAddress(true).setCompressionSupported(false) // otherwise it automatically compresses based on response headers even if pre-compressed with e.g. proxy
            .setUsePooledBuffers(true).setSsl(true).setKeyCertOptions(dynamicCertOptions)
            // TLS tuning
            .addEnabledSecureTransportProtocol("TLSv1.2").addEnabledSecureTransportProtocol("TLSv1.3");

    // enable HTTP/2 support if we can..
    if (USE_OPENSSL) {
        // TODO this has not really been tested with SNI yet
        httpOptions.setUseAlpn(true).setSslEngineOptions(new OpenSSLEngineOptions());
        cipherSuites.stream().map(SetupHttpServerOptions::javaCipherNameToOpenSSLName)
                .forEach(httpOptions::addEnabledCipherSuite);
    } else {/*from w  w w . ja v  a 2  s .  c  o m*/
        httpOptions.setUseAlpn(jettyAgentAlreadyLoaded || DynamicAgent.enableJettyAlpn())
                .setJdkSslEngineOptions(new JdkSSLEngineOptions());
        cipherSuites.forEach(httpOptions::addEnabledCipherSuite);
    }

    return httpOptions;
}