Java Code Examples for io.vertx.core.http.HttpServerOptions#setUsePooledBuffers()

The following examples show how to use io.vertx.core.http.HttpServerOptions#setUsePooledBuffers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestServerVerticle.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
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()));
  }
  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;
}
 
Example 2
Source File: ProxyVerticle.java    From quarantyne with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Future<Void> startFuture) {
  this.bouncer = new Bouncer(vertx, configSupplier, configArgs);
  // proxy server (this server)
  HttpServerOptions httpServerOptions = new HttpServerOptions();
  httpServerOptions.setHost(configArgs.getIngress().getIp());
  httpServerOptions.setUsePooledBuffers(true);
  HttpServer httpServer = vertx.createHttpServer(httpServerOptions);

  // http client to remote
  HttpClientOptions httpClientOptions = new HttpClientOptions();
  httpClientOptions.setKeepAlive(true);
  httpClientOptions.setLogActivity(true);

  if (configArgs.getEgress().isSsl()) {
    httpClientOptions.setSsl(true);
  }
  httpClientOptions.setDefaultHost(configArgs.getEgress().getHost());
  httpClientOptions.setDefaultPort(configArgs.getEgress().getPort());

  this.httpClient = vertx.createHttpClient(httpClientOptions);

  httpServer.requestHandler(frontReq -> {
    if (frontReq.method().equals(HttpMethod.POST) || frontReq.method().equals(HttpMethod.PUT)) {
      frontReq.bodyHandler(reqBody -> {
        proxiedRequestHandler(frontReq, reqBody);
      });
    } else {
      proxiedRequestHandler(frontReq, null);
    }
  }).exceptionHandler(ex -> {
    log.error("HTTP server error", ex);
  }).listen(configArgs.getIngress().getPort(), configArgs.getIngress().getIp(), h -> {
    if (h.failed()) {
      log.error("proxy failed to start", h.cause());
      startFuture.fail(h.cause());
    }
  });
}
 
Example 3
Source File: VertxHttpServerFactory.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@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);

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

        if (httpServerConfiguration.getClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.NONE) {
            options.setClientAuth(ClientAuth.NONE);
        } else if (httpServerConfiguration.getClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.REQUEST) {
            options.setClientAuth(ClientAuth.REQUEST);
        } else if (httpServerConfiguration.getClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.REQUIRED) {
            options.setClientAuth(ClientAuth.REQUIRED);
        }

        if (httpServerConfiguration.getTrustStorePath() != null) {
            if (httpServerConfiguration.getTrustStoreType() == null || httpServerConfiguration.getTrustStoreType().isEmpty() ||
                    httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_JKS)) {
                options.setTrustStoreOptions(new JksOptions()
                        .setPath(httpServerConfiguration.getTrustStorePath())
                        .setPassword(httpServerConfiguration.getTrustStorePassword()));
            } else if (httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PEM)) {
                options.setPemTrustOptions(new PemTrustOptions()
                        .addCertPath(httpServerConfiguration.getTrustStorePath()));
            } else if (httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PKCS12)) {
                options.setPfxTrustOptions(new PfxOptions()
                        .setPath(httpServerConfiguration.getTrustStorePath())
                        .setPassword(httpServerConfiguration.getTrustStorePassword()));
            }
        }

        if (httpServerConfiguration.getKeyStorePath() != null) {
            if (httpServerConfiguration.getKeyStoreType() == null || httpServerConfiguration.getKeyStoreType().isEmpty() ||
                    httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_JKS)) {
                options.setKeyStoreOptions(new JksOptions()
                        .setPath(httpServerConfiguration.getKeyStorePath())
                        .setPassword(httpServerConfiguration.getKeyStorePassword()));
            } else if (httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PEM)) {
                options.setPemKeyCertOptions(new PemKeyCertOptions()
                        .addCertPath(httpServerConfiguration.getKeyStorePath()));
            } else if (httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PKCS12)) {
                options.setPfxKeyCertOptions(new PfxOptions()
                        .setPath(httpServerConfiguration.getKeyStorePath())
                        .setPassword(httpServerConfiguration.getKeyStorePassword()));
            }
        }
    }

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

    return vertx.createHttpServer(options);
}
 
Example 4
Source File: VertxHttpServerFactory.java    From gravitee-gateway with Apache License 2.0 4 votes vote down vote up
@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);

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

        if (httpServerConfiguration.isClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.NONE) {
            options.setClientAuth(ClientAuth.NONE);
        } else if (httpServerConfiguration.isClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.REQUEST) {
            options.setClientAuth(ClientAuth.REQUEST);
        } else if (httpServerConfiguration.isClientAuth() == VertxHttpServerConfiguration.ClientAuthMode.REQUIRED) {
            options.setClientAuth(ClientAuth.REQUIRED);
        }

        if (httpServerConfiguration.getTrustStorePath() != null) {
            if (httpServerConfiguration.getTrustStoreType() == null || httpServerConfiguration.getTrustStoreType().isEmpty() ||
                    httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_JKS)) {
                options.setTrustStoreOptions(new JksOptions()
                        .setPath(httpServerConfiguration.getTrustStorePath())
                        .setPassword(httpServerConfiguration.getTrustStorePassword()));
            } else if (httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PEM)) {
                options.setPemTrustOptions(new PemTrustOptions()
                        .addCertPath(httpServerConfiguration.getTrustStorePath()));
            } else if (httpServerConfiguration.getTrustStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PKCS12)) {
                options.setPfxTrustOptions(new PfxOptions()
                        .setPath(httpServerConfiguration.getTrustStorePath())
                        .setPassword(httpServerConfiguration.getTrustStorePassword()));
            }
        }

        if (httpServerConfiguration.getKeyStorePath() != null) {
            if (httpServerConfiguration.getKeyStoreType() == null || httpServerConfiguration.getKeyStoreType().isEmpty() ||
                    httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_JKS)) {
                options.setKeyStoreOptions(new JksOptions()
                        .setPath(httpServerConfiguration.getKeyStorePath())
                        .setPassword(httpServerConfiguration.getKeyStorePassword()));
            } else if (httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PEM)) {
                options.setPemKeyCertOptions(new PemKeyCertOptions()
                        .addCertPath(httpServerConfiguration.getKeyStorePath()));
            } else if (httpServerConfiguration.getKeyStoreType().equalsIgnoreCase(CERTIFICATE_FORMAT_PKCS12)) {
                options.setPfxKeyCertOptions(new PfxOptions()
                        .setPath(httpServerConfiguration.getKeyStorePath())
                        .setPassword(httpServerConfiguration.getKeyStorePassword()));
            }
        }
    }

    options.setHandle100ContinueAutomatically(true);
    
    // Customizable configuration
    options.setCompressionSupported(httpServerConfiguration.isCompressionSupported());
    options.setIdleTimeout(httpServerConfiguration.getIdleTimeout());
    options.setTcpKeepAlive(httpServerConfiguration.isTcpKeepAlive());
    options.setMaxChunkSize(httpServerConfiguration.getMaxChunkSize());
    options.setMaxHeaderSize(httpServerConfiguration.getMaxHeaderSize());

    // Configure websocket
    System.setProperty("vertx.disableWebsockets", Boolean.toString(!httpServerConfiguration.isWebsocketEnabled()));

    return vertx.createHttpServer(options);
}