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

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

Introduction

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

Prototype

public HttpServerOptions() 

Source Link

Document

Default constructor

Usage

From source file:io.github.pflima92.plyshare.gateway.GatewayOptions.java

License:Apache License

@Override
protected void init() {

    super.init();

    profile = DEFAULT_PROFILE;/* w ww  . j  av  a  2 s .c  o m*/
    owner = DEFAULT_OWNER;
    serialKey = UUID.randomUUID().toString();
    gatewayDatabaseOptions = new GatewayDatabaseOptions();
    apiPort = DEFAULT_API_PORT;
    proxyPort = DEFAULT_PROXY_PORT;
    dashboardPort = DEFAULT_DASHBOARD_PORT;
    httpServerOptions = new HttpServerOptions();
    periodicHealthCheck = DEFAULT_PERIOD_HEALTH_CHECK;
    audit = DEFAULT_AUDIT_OPTION;
    libPath = DEFAULT_LIB_PATH;
}

From source file:io.gravitee.am.gateway.handler.vertx.RxWebTestBase.java

License:Apache License

protected HttpServerOptions getHttpServerOptions() {
    return new HttpServerOptions().setPort(RANDOM_PORT).setHost("localhost");
}

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  ww.  ja  v  a  2  s .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);/*from  w  w  w. j av a 2 s .co  m*/

    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:io.helixservice.feature.restservice.RestServiceVerticle.java

License:Open Source License

@Override
public void start() throws Exception {
    try {/*from  w  w w . j a v a 2  s  .  c  o m*/
        ConfigProperty port = new ConfigProperty(configProvider, "vertx.server.port");

        HttpServerOptions serverOptions = new HttpServerOptions().setPort(port.asInt());
        HttpServer httpServer = vertx.createHttpServer(serverOptions);

        router.route().handler(fiberHandler(finisher(BodyHandler.create())));
        configureFeatures();

        httpServer.requestHandler(getHandler(router)).listen();
    } catch (Throwable t) {
        LOG.error("Unable to start RestServiceVerticle", t);
        throw t;
    }
}

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 .  ja va 2s. c o m*/

    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:io.servicecomb.transport.rest.vertx.RestServerVerticle.java

License:Apache License

private HttpServerOptions createDefaultHttpServerOptions() {
    HttpServerOptions serverOptions = new HttpServerOptions();
    serverOptions.setAcceptBacklog(ACCEPT_BACKLOG);
    serverOptions.setSendBufferSize(SEND_BUFFER_SIZE);
    serverOptions.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
    serverOptions.setUsePooledBuffers(true);

    if (endpointObject.isSslEnabled()) {
        SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(SSL_KEY, null);
        SSLOption sslOption;//w w w.  ja v a  2  s .c  om
        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:io.silverware.microservices.providers.cdi.internal.RestInterface.java

License:Apache License

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get("/rest").handler(this::listBeans);
    router.get("/rest/:microservice").handler(this::listMethods);
    router.get("/rest/:microservice/:method").handler(this::callNoParamMethod);
    router.post("/rest/:microservice/:method").handler(this::callMethod);

    HttpServerOptions options = new HttpServerOptions().setAcceptBacklog(1000);
    HttpServer server = vertx.createHttpServer(options).requestHandler(router::accept);
    if (host.isEmpty()) {
        server.listen(port);//from   www  . j  ava2s  .co  m
    } else {
        server.listen(port, host);
    }
}

From source file:io.sqp.proxy.ServerVerticle.java

License:Open Source License

@Override
public void start() {
    // TODO: set subprotocols

    JsonObject config = config();//  ww w  .  ja va  2  s.  c om

    String path = config.getString("path", DEFAULT_PATH);
    int port = config.getInteger("port", DEFAULT_PORT);
    int poolSize = config.getInteger("connectionPoolSize", DEFAULT_POOL_SIZE);
    JsonArray backendConfs = config.getJsonArray("backends");
    _executorService = Executors.newFixedThreadPool(10); // TODO: set this reasonably

    // Initialize the backend connection pool
    BackendConnectionPool connectionPool = new VertxBackendConnectionPool(vertx, poolSize, backendConfs);

    try {
        connectionPool.init();
    } catch (ServerErrorException e) {
        _logger.log(Level.SEVERE, "Failed to create the connection pool", e);
        throw new RuntimeException(e.getMessage(), e.getCause());
    }

    HttpServerOptions options = new HttpServerOptions();
    int maxFrameSize = options.getMaxWebsocketFrameSize();

    // Create the actual server
    HttpServer server = vertx.createHttpServer(options);

    // For each incoming websocket connection: create a client connection object
    server.websocketHandler(socket -> {
        if (!socket.path().equals(path)) {
            socket.reject();
            return;
        }
        // TODO: check sub protocols
        new VertxClientConnection(_executorService, socket, connectionPool, maxFrameSize);
    });
    // start to listen
    server.listen(port, result -> {
        if (result.succeeded()) {
            _logger.log(Level.INFO, "Listening on port " + port + " and path '" + path + "'...");
            setStarted(true);
        } else {
            _logger.log(Level.SEVERE, "Failed to listen", result.cause());
            setStartingError(result.cause());
        }
    });
}

From source file:lumbermill.internal.http.VertxHttpServer.java

License:Apache License

public VertxHttpServer(MapWrap config) {
    port = config.asInt("port", DEFAULT_PORT);
    observableListenersByTag = new HashMap<>();

    // Setup vertx
    vertx = Vertx.vertx();//from ww  w  .ja  v  a 2s . co m
    vertx.deployVerticle(this);
    if (config.exists("keyStorePath")) {
        httpServer = vertx.createHttpServer(new HttpServerOptions().setSsl(true)
                .setKeyStoreOptions(new JksOptions().setPath(config.asString("keyStorePath"))
                        .setPassword(config.asString("keyStorePassword"))));
    } else {
        httpServer = vertx.createHttpServer();
    }

    router = Router.router(vertx);
}