List of usage examples for io.vertx.core.http HttpServerOptions setPort
public HttpServerOptions setPort(int port)
From source file:com.dinstone.vertx.verticle.HttpManageVerticle.java
License:Apache License
private HttpServerOptions getRestHttpServerOptions() { HttpServerOptions serverOptions = null; try {//from w w w .j a v a2 s . c om serverOptions = applicationContext.getBean("restHttpServerOptions", HttpServerOptions.class); } catch (Exception e) { // ignore } if (serverOptions == null) { serverOptions = new HttpServerOptions(); } serverOptions.setIdleTimeout(manageProperties.getIdleTimeout()); serverOptions.setPort(manageProperties.getPort()); if (manageProperties.getHost() != null) { serverOptions.setHost(manageProperties.getHost()); } return serverOptions; }
From source file:com.dinstone.vertx.verticle.HttpRestVerticle.java
License:Apache License
private HttpServerOptions getRestHttpServerOptions() { HttpServerOptions serverOptions = null; try {/*from ww w. ja v a 2 s. c om*/ serverOptions = applicationContext.getBean("restHttpServerOptions", HttpServerOptions.class); } catch (Exception e) { // ignore } if (serverOptions == null) { serverOptions = new HttpServerOptions(); } serverOptions.setIdleTimeout(restProperties.getIdleTimeout()); serverOptions.setPort(restProperties.getPort()); if (restProperties.getHost() != null) { serverOptions.setHost(restProperties.getHost()); } return serverOptions; }
From source file:io.github.bckfnn.actioner.Main.java
License:Apache License
/** * Initialize.// www . j av a2 s . com * @param future the future to signal when done * @throws Exception if an action class can not be loaded */ @Override public void start(Future<Void> future) throws Exception { log.info("Starting"); config = loadConfig(); if (config.hasPath("translations")) { translations = ConfigFactory.load(config.getString("translations")); } log.debug("config loaded"); initialize(); boolean develop = config.getBoolean("develop"); String contextRoot = config.getString("webserver.contextRoot"); //Schema schema = makeSchema(); //Persistor persistor = makePersistor(config, schema); if (config.hasPath("groups")) { authProvider = new DbAuthProvider(this, ConfigFactory.load(config.getString("groups"))); } Router router = Router.router(vertx); System.out.println(router); router.route().handler(ctx -> { ctx.put(Vertx.class.getName(), vertx); ctx.put(Router.class.getName(), router); ctx.put(ActionRouter.class.getName(), actionRouter); ctx.put(Config.class.getName(), config); ctx.put("ctx", ctx); ctx.put("startTime", System.currentTimeMillis()); ctx.put("translations", translations); ctx.put("contextRoot", contextRoot); ctx.put(AuthProvider.class.getName(), authProvider); ctx.response().putHeader("X-Frame-Options", "deny"); configContext(ctx); log.debug("request: {}", ctx.request().path()); ctx.next(); }); if (authProvider != null) { sessionStore = new PersistentLocalSessionStore(vertx, LocalSessionStore.DEFAULT_SESSION_MAP_NAME, LocalSessionStore.DEFAULT_REAPER_INTERVAL, config.getString("sessionStorage")); //LocalSessionStore.create(vertx); } router.route().handler(CookieHandler.create()); router.route().handler(BodyHandler.create()); if (config.hasPath("metrics")) { MetricRegistry registry = SharedMetricRegistries.getOrCreate(config.getString("metrics.registryName")); if (config.hasPath("metrics.logback")) { final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory(); final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME); final InstrumentedAppender metrics = new InstrumentedAppender(registry); metrics.setContext(root.getLoggerContext()); metrics.start(); root.addAppender(metrics); } if (config.hasPath("metrics.prometheus.uri")) { router.get(config.getString("metrics.prometheus.uri")) .handler(new PrometheusMetricsHandler(registry)); } } if (config.hasPath("webserver.webjars")) { router.route().path(contextRoot + config.getString("webserver.webjars.uri")) .handler(new WebjarsHandler()); } if (config.hasPath("webserver.assets")) { router.route().path(contextRoot + config.getString("webserver.assets.uri")) .handler(new AssetsHandler()); } if (config.hasPath("webserver.public")) { router.route().path(contextRoot + config.getString("webserver.public.uri")) .handler(StaticHandler.create(config.getString("app.publicFolder")).setCachingEnabled(!develop) .setFilesReadOnly(!develop)); } if (authProvider != null) { router.route().handler(SessionHandler.create(sessionStore).setNagHttps(!develop)); router.route().handler(UserSessionHandler.create(authProvider)); } router.route().handler(new AcceptLanguageHandler(true)); router.route().handler(LoggerHandler.create(false, LoggerFormat.SHORT)); configRouter(router); for (String cls : config.getStringList("app.actionClasses")) { actionRouter.addAction(contextRoot, router, getClass().getClassLoader().loadClass(cls)); } router.route().handler(new LayoutTemplateHandler()); router.route().failureHandler(ctx -> { if (ctx.failed() && ctx.failure() != null) { log.error("Error handler", ctx.failure()); } ErrorHandler.create(develop).handle(ctx); }); BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("importList")) .addOutboundPermitted(new PermittedOptions().setAddress("importList")); SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); HttpServerOptions options = new HttpServerOptions(); options.setPort(config.getInt("port")); server = vertx.createHttpServer(options); server.requestHandler(router::accept).listen(res -> { if (res.failed()) { log.error("http server failed to start", res.cause()); future.fail(res.cause()); } else { log.info("http started"); } future.complete(); }); }
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 www . ja va 2 s . co 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 va2 s. com*/ 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.springframework.integration.vertx.WebSocketServer.java
License:Apache License
@Override public synchronized void start() { if (this.running) { return;// w ww . j a va 2s . co m } HttpServerOptions httpServerOptions = new HttpServerOptions(); httpServerOptions.setPort(this.getPort()); this.server = Vertx.factory.vertx().createHttpServer(httpServerOptions).websocketHandler(ws -> { final String correlationId = UUID.randomUUID().toString(); final TcpListener listener = WebSocketServer.this.getListener(); WebSocketConnection connection = new WebSocketConnection(correlationId, ws, listener); WebSocketServer.this.getSender().addNewConnection(connection); if (ws.path().equals("/myapp")) { ws.handler(data -> { listener.onMessage(MessageBuilder.withPayload(data.toString()).setCorrelationId(correlationId) .setHeader(IpHeaders.CONNECTION_ID, correlationId).build()); }); } else { ws.reject(); } }).requestHandler(req -> { if (req.path().equals("/")) { req.response().sendFile("ws.html"); } }).listen(); this.running = true; }
From source file:se.liquidbytes.jel.web.WebserverVerticle.java
License:Apache License
/** * Method should be called when verticle should start up * * @param future Future for reporting back success or failure of execution *///from w w w .ja v a 2 s . c o m @Override public void start(Future<Void> future) { // If no API should be exposed, and thus the client won't work either, then don't start the webserver. if (Settings.get("skipapi").equals("true")) { logger.info("No API will be exposed according to the settings provided during application startup."); future.complete(); return; } systemApi = new SystemApi(vertx); pluginApi = new PluginApi(vertx); adapterApi = new AdapterApi(vertx); siteApi = new SiteApi(vertx); userApi = new UserApi(vertx); deviceApi = new DeviceApi(vertx); HttpServerOptions options = new HttpServerOptions(); options.setHost(SystemInfo.getIP()); options.setPort(Integer.parseInt(config.getString("port"))); server = vertx.createHttpServer(options); server.requestHandler(createRouter()::accept); server.listen(result -> { if (result.succeeded()) { logger.info(String.format("Jel REST-API now listening on %s port %d.", options.getHost(), options.getPort())); future.complete(); } else { future.fail(result.cause()); } }); }
From source file:suonos.httpserver.VertxHttpServer.java
License:Apache License
@Override public void run() { HttpServerOptions opts = new HttpServerOptions(); opts.setHost(host);//from w w w . j a v a2s . c o m opts.setPort(port); opts.setCompressionSupported(true); staticFileHandler.setContextPath("/res"); server = vertx.createHttpServer(opts); webApp.routes().addRouteHandler("/res/:path*", staticFileHandler); server.requestHandler(new VertxRequestHandler(vertx, webApp)); server.listen(); }