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

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

Introduction

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

Prototype

@Override
    public HttpServerOptions setTrustStoreOptions(JksOptions options) 

Source Link

Usage

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  w  w  w.  j a  v a  2s. c o  m

    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.gravitee.gateway.standalone.vertx.VertxHttpServerFactory.java

License:Apache License

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

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

    // Netty pool buffers must be enabled by default
    options.setUsePooledBuffers(true);/*  w w w .j a  v  a 2  s  .  c om*/

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

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

        options.setTrustStoreOptions(new JksOptions().setPath(httpServerConfiguration.getKeyStorePath())
                .setPassword(httpServerConfiguration.getKeyStorePassword()));
        options.setKeyStoreOptions(new JksOptions().setPath(httpServerConfiguration.getTrustStorePath())
                .setPassword(httpServerConfiguration.getKeyStorePassword()));
    }

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

    return vertx.createHttpServer(options);
}

From source file:org.wisdom.framework.vertx.Server.java

License:Apache License

private void bind(int p, Handler<AsyncResult<Void>> completion) {
    // Get port number.
    final int thePort = pickAPort(port);
    HttpServerOptions options = new HttpServerOptions();
    if (ssl) {//from   w w w  . j a va  2  s.c  o  m
        options.setSsl(true);
        options.setTrustStoreOptions(SSLServerContext.getTrustStoreOption(accessor));
        options.setKeyStoreOptions(SSLServerContext.getKeyStoreOption(accessor));
        if (authentication) {
            options.setClientAuth(ClientAuth.REQUIRED);
        }
    }

    if (hasCompressionEnabled()) {
        options.setCompressionSupported(true);
    }

    if (configuration.getIntegerWithDefault("vertx.acceptBacklog", -1) != -1) {
        options.setAcceptBacklog(configuration.getInteger("vertx.acceptBacklog"));
    }
    if (configuration.getIntegerWithDefault("vertx.maxWebSocketFrameSize", -1) != -1) {
        options.setMaxWebsocketFrameSize(configuration.getInteger("vertx.maxWebSocketFrameSize"));
    }
    if (configuration.getStringArray("wisdom.websocket.subprotocols").length > 0) {
        options.setWebsocketSubProtocols(configuration.get("wisdom.websocket.subprotocols"));
    }
    if (configuration.getStringArray("vertx.websocket-subprotocols").length > 0) {
        options.setWebsocketSubProtocols(configuration.get("vertx.websocket-subprotocols"));
    }
    if (configuration.getIntegerWithDefault("vertx.receiveBufferSize", -1) != -1) {
        options.setReceiveBufferSize(configuration.getInteger("vertx.receiveBufferSize"));
    }
    if (configuration.getIntegerWithDefault("vertx.sendBufferSize", -1) != -1) {
        options.setSendBufferSize(configuration.getInteger("vertx.sendBufferSize"));
    }

    http = vertx.createHttpServer(options).requestHandler(new HttpHandler(vertx, accessor, this))
            .websocketHandler(new WebSocketHandler(accessor, this));

    http.listen(thePort, host, event -> {
        if (event.succeeded()) {
            logger.info("Wisdom is going to serve HTTP requests on port {}.", thePort);
            port = thePort;
            completion.handle(Future.succeededFuture());
        } else if (port == 0) {
            logger.debug("Cannot bind on port {} (port already used probably)", thePort, event.cause());
            bind(0, completion);
        } else {
            logger.error("Cannot bind on port {} (port already used probably)", thePort, event.cause());
            completion.handle(Future.failedFuture("Cannot bind on port " + thePort));
        }
    });
}

From source file:org.workspace7.k8s.auth.proxy.K8sWebProxyVerticle.java

License:Apache License

/**
 * @param keyCloakOAuth2/*from   ww w .  j  a v  a2  s.  com*/
 * @param next
 */
protected void startWebApp(AsyncResult<OAuth2Auth> keyCloakOAuth2, Handler<AsyncResult<HttpServer>> next) {

    Router router = Router.router(vertx);

    final String proxyUri = "https://" + config().getString("k8s_proxy_host") + ":"
            + config().getInteger("k8s_proxy_port");

    if (keyCloakOAuth2.succeeded()) {

        OAuth2AuthHandler keycloakOAuthHandler = OAuth2AuthHandler.create(keyCloakOAuth2.result(), proxyUri);
        keycloakOAuthHandler.setupCallback(router.get("/callback"));

        //router.route().handler(BodyHandler.create());

        router.route("/api/*").handler(keycloakOAuthHandler);
        router.route("/ui/*").handler(keycloakOAuthHandler);

        //Handle UI Requests
        router.route("/ui/").handler(this::handleUIPath);

        //Handle API Requests
        router.route("/api/*").handler(this::handleApiPath);

        router.get("/").handler(ctx -> ctx.reroute("/ui/"));

        //These options are for setting up the server (k8s-proxy)
        HttpServerOptions httpServerOptions = new HttpServerOptions().setSsl(true);

        //Server HTTPS
        httpServerOptions.setPemKeyCertOptions(proxyPemOptions());
        httpServerOptions.setTrustStoreOptions(proxyTrustOptions());

        vertx.createHttpServer(httpServerOptions).requestHandler(router::accept)
                .listen(config().getInteger("k8s_proxy_port"), config().getString("k8s_proxy_host"), next);
    } else {
        _logger.error("Unable to start proxy : {}", keyCloakOAuth2.cause());
        next.handle(Future.failedFuture(keyCloakOAuth2.cause()));
    }
}