List of usage examples for io.vertx.core.http HttpServerOptions setKeyStoreOptions
@Override
public HttpServerOptions setKeyStoreOptions(JksOptions options)
From source file:com.englishtown.vertx.jersey.impl.DefaultJerseyServer.java
License:Open Source License
@Override public void init(final JerseyOptions options, final Handler<AsyncResult<HttpServer>> doneHandler) { // Setup the http server options HttpServerOptions serverOptions = new HttpServerOptions().setHost(options.getHost()) .setPort(options.getPort()).setAcceptBacklog(options.getAcceptBacklog()); // Performance tweak // Enable https if (options.getSSL()) { serverOptions.setSsl(true);//from w w w . j a v a 2s.c o m } if (options.getKeyStoreOptions() != null) { serverOptions.setKeyStoreOptions(options.getKeyStoreOptions()); } Integer receiveBufferSize = options.getReceiveBufferSize(); if (receiveBufferSize != null && receiveBufferSize > 0) { // TODO: This doesn't seem to actually affect buffer size for dataHandler. Is this being used correctly or is it a Vertx bug? serverOptions.setReceiveBufferSize(receiveBufferSize); } // Create the http server server = options.getVertx().createHttpServer(serverOptions); // Init jersey handler jerseyHandler.init(options); // Set request handler for the baseUri server.requestHandler(jerseyHandler::handle); // Perform any additional server setup (add routes etc.) if (setupHandler != null) { setupHandler.handle(server); } // Start listening and log success/failure server.listen(ar -> { final String listenPath = (options.getSSL() ? "https" : "http") + "://" + serverOptions.getHost() + ":" + serverOptions.getPort(); if (ar.succeeded()) { logger.info("Http server listening for " + listenPath); } else { logger.error("Failed to start http server listening for " + listenPath, ar.cause()); } if (doneHandler != null) { doneHandler.handle(ar); } }); }
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);/*from w w w . ja v a2 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: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 ww .j a v a 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:pt.davidafsilva.slacker.server.HttpServerConfiguration.java
License:Open Source License
/** * Sets up the http server configuration based on the available environment variables (SLACK_*) * and current configuration via the json configuration file. * * @param config the current configuration * @return the configured server options *//*from w ww . j a va 2 s .c om*/ static HttpServerOptions setup(final JsonObject config) { // evaluate the environment variables evaluateEnvironmentVariables(config); // create the http server options final HttpServerOptions options = new HttpServerOptions().setIdleTimeout(IDLE_TIMEOUT) .setPort(config.getInteger(ConfigurationVariable.HTTP_PORT.name(), DEFAULT_HTTP_PORT)) .setSsl(config.getBoolean(ConfigurationVariable.USE_SSL.name(), DEFAULT_USE_SSL)); // setup the required SSL parameters if (options.isSsl()) { // validate the configuration validateOptions(config, ConfigurationVariable.KEY_STORE_FILE, ConfigurationVariable.KEY_STORE_PASS); // add the enabled cipher suites CIPHER_SUITES.stream().forEach(options::addEnabledCipherSuite); // set the both keystore location and keystore password options.setKeyStoreOptions( new JksOptions().setPath(config.getString(ConfigurationVariable.KEY_STORE_FILE.name())) .setPassword(config.getString(ConfigurationVariable.KEY_STORE_PASS.name()))); } return options; }
From source file:spring.vertxtest.verticle.MyTestVerticle.java
@Override public void start(Future<Void> fut) throws Exception { log.info("start() -- starting Vertx Verticle with eventbus, API handler, and static file handler"); // grab the router router = getRouter();//www. j a va 2 s .c om // enable CORS for the router CorsHandler corsHandler = CorsHandler.create("*"); //Wildcard(*) not allowed if allowCredentials is true corsHandler.allowedMethod(HttpMethod.OPTIONS); corsHandler.allowedMethod(HttpMethod.GET); corsHandler.allowedMethod(HttpMethod.POST); corsHandler.allowedMethod(HttpMethod.PUT); corsHandler.allowedMethod(HttpMethod.DELETE); corsHandler.allowCredentials(false); corsHandler.allowedHeader("Access-Control-Request-Method"); corsHandler.allowedHeader("Access-Control-Allow-Method"); corsHandler.allowedHeader("Access-Control-Allow-Credentials"); corsHandler.allowedHeader("Access-Control-Allow-Origin"); corsHandler.allowedHeader("Access-Control-Allow-Headers"); corsHandler.allowedHeader("Content-Type"); // enable handling of body router.route().handler(BodyHandler.create()); router.route().handler(corsHandler); router.route().handler(this::handleAccessLogging); // publish a payload to provided eventbus destination router.post("/api/eventbus/publish/:destination").handler(this::publish); // open up all for outbound and inbound traffic bridgeOptions = new BridgeOptions(); bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(".*")); bridgeOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(".*")); // sockJsHandler = SockJSHandler.create(vertx).bridge(bridgeOptions); sockJsHandler = SockJSHandler.create(vertx); sockJsHandler.bridge(bridgeOptions, be -> { try { if (be.type() == BridgeEventType.SOCKET_CREATED) { handleSocketOpenEvent(be); } else if (be.type() == BridgeEventType.REGISTER) { handleRegisterEvent(be); } else if (be.type() == BridgeEventType.UNREGISTER) { handleUnregisterEvent(be); } else if (be.type() == BridgeEventType.SOCKET_CLOSED) { handleSocketCloseEvent(be); } } catch (Exception e) { } finally { be.complete(true); } }); router.route("/eventbus/*").handler(sockJsHandler); if (testPathEnabled) { router.route("/" + testUrlPath + "/*") .handler(StaticHandler.create(testFilePath).setCachingEnabled(cachingEnabled)); } // create periodic task, pushing all current EventBusRegistrations vertx.setPeriodic(1000, handler -> { JsonObject obj = new JsonObject(); obj.put("testMessage", "Periodic test message from server..."); vertx.eventBus().publish("heartbeat-test", Json.encodePrettily(obj)); }); EventBus eb = vertx.eventBus(); eb.consumer("client-test", message -> { log.info("Received message from client: " + Json.encodePrettily(message.body()) + " at " + System.currentTimeMillis()); }); HttpServerOptions httpOptions = new HttpServerOptions(); if (sslEnabled) { httpOptions.setSsl(true); httpOptions.setKeyStoreOptions(sslKeyStoreOptions); } log.info("starting web server on port: " + port); vertx.createHttpServer(httpOptions).requestHandler(router::accept).listen(port, result -> { if (result.succeeded()) { setStarted(true); log.info("Server started and ready to accept requests"); fut.complete(); } else { setStarted(false); fut.fail(result.cause()); } }); }