io.vertx.ext.web.sstore.ClusteredSessionStore Java Examples
The following examples show how to use
io.vertx.ext.web.sstore.ClusteredSessionStore.
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: WebExamples.java From vertx-web with Apache License 2.0 | 6 votes |
public void example32() { // a clustered Vert.x Vertx.clusteredVertx(new VertxOptions(), res -> { Vertx vertx = res.result(); // Create a clustered session store using defaults SessionStore store1 = ClusteredSessionStore.create(vertx); // Create a clustered session store specifying the distributed map name to use // This might be useful if you have more than one application in the cluster // and want to use different maps for different applications SessionStore store2 = ClusteredSessionStore.create( vertx, "myclusteredapp3.sessionmap"); }); }
Example #2
Source File: NearCacheSessionStoreImpl.java From vertx-vaadin with MIT License | 5 votes |
public NearCacheSessionStoreImpl(Vertx vertx, String sessionMapName, long retryTimeout, long reaperInterval) { this.vertx = vertx; this.reaperInterval = reaperInterval; this.clusteredSessionStore = ClusteredSessionStore.create(vertx, sessionMapName, retryTimeout); this.localMap = vertx.sharedData().getLocalMap(sessionMapName); this.setTimer(); }
Example #3
Source File: NearCacheSessionStoreImpl.java From vertx-vaadin with MIT License | 5 votes |
public NearCacheSessionStoreImpl(Vertx vertx, String sessionMapName, long retryTimeout, long reaperInterval) { this.vertx = vertx; this.reaperInterval = reaperInterval; this.clusteredSessionStore = ClusteredSessionStore.create(vertx, sessionMapName, retryTimeout); this.localMap = vertx.sharedData().getLocalMap(sessionMapName); this.setTimer(); }
Example #4
Source File: VertxWrappedSessionWithClusteredSessionStoreUT.java From vertx-vaadin with MIT License | 4 votes |
@Before public void setUp(TestContext context) { vertx = Vertx.vertx(); sessionStore = ClusteredSessionStore.create(vertx); }
Example #5
Source File: VertxWrappedSessionWithClusteredSessionStoreUT.java From vertx-vaadin with MIT License | 4 votes |
@Before public void setUp(TestContext context) { vertx = Vertx.vertx(); sessionStore = ClusteredSessionStore.create(vertx); }
Example #6
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 4 votes |
/** * 创建http服务器 * * @param createHttp */ public void createHttpServer(Handler<AsyncResult<Void>> createHttp) { this.httpRouter = Router.router(vertx); httpRouter.route().handler(this::filterBlackIP); httpRouter.route().handler(CookieHandler.create()); SessionStore sessionStore = null; if (vertx.isClustered()) { sessionStore = ClusteredSessionStore.create(vertx); } else { sessionStore = LocalSessionStore.create(vertx); } SessionHandler sessionHandler = SessionHandler.create(sessionStore); sessionHandler.setSessionCookieName(appOption.getSessionCookieName()); sessionHandler.setSessionTimeout(appOption.getSessionTimeOut()); httpRouter.route().handler(sessionHandler); // 跨域处理 if (corsOptions != null) { CorsHandler corsHandler = CorsHandler.create(corsOptions.getAllowedOrigin()); if (corsOptions.getAllowedHeaders() != null) { corsHandler.allowedHeaders(corsOptions.getAllowedHeaders()); } corsHandler.allowCredentials(corsOptions.isAllowCredentials()); if (corsOptions.getExposedHeaders() != null) { corsHandler.exposedHeaders(corsOptions.getExposedHeaders()); } if (corsOptions.getAllowedMethods() != null) { corsHandler.allowedMethods(corsOptions.getAllowedMethods()); } corsHandler.maxAgeSeconds(corsOptions.getMaxAgeSeconds()); httpRouter.route().handler(corsHandler); } // 如果在linux系统开启epoll if (vertx.isNativeTransportEnabled()) { serverOptions.setTcpFastOpen(true).setTcpCork(true).setTcpQuickAck(true).setReusePort(true); } // 404页面 httpRouter.route().order(999999).handler(rct -> { if (LOG.isDebugEnabled()) { LOG.debug("用户: " + rct.request().remoteAddress().host() + "请求的了不存的路径: " + rct.request().method() + ":" + rct.request().path()); } HttpServerResponse response = rct.response(); if (appOption.getNotFoundContentType() != null) { response.putHeader("Content-Type", appOption.getNotFoundContentType()); } response.end(appOption.getNotFoundResult()); }); // 创建http服务器 vertx.createHttpServer(serverOptions).requestHandler(httpRouter::accept).listen(serverOptions.getHttpPort(), res -> { if (res.succeeded()) { System.out.println( MessageFormat.format("{0} Running on port {1} by HTTP", appOption.getAppName(), Integer.toString(serverOptions.getHttpPort()))); createHttp.handle(Future.succeededFuture()); } else { System.out.println("create HTTP Server failed : " + res.cause()); createHttp.handle(Future.failedFuture(res.cause())); } }); }
Example #7
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 4 votes |
/** * 创建https服务器 * * @param createHttp */ public void createHttpsServer(Handler<AsyncResult<Void>> createHttps) { this.httpsRouter = Router.router(vertx); httpsRouter.route().handler(this::filterBlackIP); httpsRouter.route().handler(CookieHandler.create()); SessionStore sessionStore = null; if (vertx.isClustered()) { sessionStore = ClusteredSessionStore.create(vertx); } else { sessionStore = LocalSessionStore.create(vertx); } SessionHandler sessionHandler = SessionHandler.create(sessionStore); sessionHandler.setSessionCookieName(appOption.getSessionCookieName()); sessionHandler.setSessionTimeout(appOption.getSessionTimeOut()); httpsRouter.route().handler(sessionHandler); // 跨域处理 if (corsOptions != null) { CorsHandler corsHandler = CorsHandler.create(corsOptions.getAllowedOrigin()); if (corsOptions.getAllowedHeaders() != null) { corsHandler.allowedHeaders(corsOptions.getAllowedHeaders()); } corsHandler.allowCredentials(corsOptions.isAllowCredentials()); if (corsOptions.getExposedHeaders() != null) { corsHandler.exposedHeaders(corsOptions.getExposedHeaders()); } if (corsOptions.getAllowedMethods() != null) { corsHandler.allowedMethods(corsOptions.getAllowedMethods()); } corsHandler.maxAgeSeconds(corsOptions.getMaxAgeSeconds()); httpsRouter.route().handler(corsHandler); } // 创建https服务器 serverOptions.setSsl(true); VxApiCertOptions certOptions = serverOptions.getCertOptions(); if (certOptions.getCertType().equalsIgnoreCase("pem")) { serverOptions .setPemKeyCertOptions(new PemKeyCertOptions().setCertPath(certOptions.getCertPath()).setKeyPath(certOptions.getCertKey())); } else if (certOptions.getCertType().equalsIgnoreCase("pfx")) { serverOptions.setPfxKeyCertOptions(new PfxOptions().setPath(certOptions.getCertPath()).setPassword(certOptions.getCertKey())); } else { LOG.error("创建https服务器-->失败:无效的证书类型,只支持pem/pfx格式的证书"); createHttps.handle(Future.failedFuture("创建https服务器-->失败:无效的证书类型,只支持pem/pfx格式的证书")); return; } Future<Boolean> createFuture = Future.future(); vertx.fileSystem().exists(certOptions.getCertPath(), createFuture); createFuture.setHandler(check -> { if (check.succeeded()) { if (check.result()) { // 404页面 httpsRouter.route().order(999999).handler(rct -> { if (LOG.isDebugEnabled()) { LOG.debug( "用户: " + rct.request().remoteAddress().host() + "请求的了不存的路径: " + rct.request().method() + ":" + rct.request().path()); } HttpServerResponse response = rct.response(); if (appOption.getNotFoundContentType() != null) { response.putHeader("Content-Type", appOption.getNotFoundContentType()); } response.end(appOption.getNotFoundResult()); }); // 如果在linux系统开启epoll if (vertx.isNativeTransportEnabled()) { serverOptions.setTcpFastOpen(true).setTcpCork(true).setTcpQuickAck(true).setReusePort(true); } vertx.createHttpServer(serverOptions).requestHandler(httpsRouter::accept).listen(serverOptions.getHttpsPort(), res -> { if (res.succeeded()) { System.out.println(appOption.getAppName() + " Running on port " + serverOptions.getHttpsPort() + " by HTTPS"); createHttps.handle(Future.succeededFuture()); } else { System.out.println("create HTTPS Server failed : " + res.cause()); createHttps.handle(Future.failedFuture(res.cause())); } }); } else { LOG.error("执行创建https服务器-->失败:无效的证书或者错误的路径:如果证书存放在conf/cert中,路径可以从cert/开始,示例:cert/XXX.XXX"); createHttps.handle(Future.failedFuture("无效的证书或者错误的路径")); } } else { LOG.error("执行创建https服务器-->失败:无效的证书或者错误的路径:如果证书存放在conf/cert中,路径可以从cert/开始,示例:cert/XXX.XXX", check.cause()); createHttps.handle(Future.failedFuture(check.cause())); } }); }
Example #8
Source File: ClientVerticle.java From VX-API-Gateway with MIT License | 4 votes |
@Override public void start(Promise<Void> fut) throws Exception { LOG.info("start Client Verticle ..."); thisVertxName = System.getProperty("thisVertxName", "VX-API"); Router router = Router.router(vertx); router.route().handler(FaviconHandler.create(getFaviconPath())); router.route().handler(BodyHandler.create().setUploadsDirectory(getUploadsDirectory())); if (vertx.isClustered()) { router.route().handler( SessionHandler.create(ClusteredSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME)); } else { router.route() .handler(SessionHandler.create(LocalSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME)); } // 通过html的方式管理应用网关 // TemplateEngine create = FreeMarkerTemplateEngine.create(vertx); // TemplateHandler tempHandler = TemplateHandler.create(create, getTemplateRoot(), CONTENT_VALUE_HTML_UTF8); TemplateHandler tempHandler = new FreeMarkerTemplateHander(vertx, getTemplateRoot(), CONTENT_VALUE_HTML_UTF8); router.getWithRegex(".+\\.ftl").handler(tempHandler); // 权限相关 router.route("/static/*").handler(VxApiClientStaticAuth.create()); router.route("/static/*").handler(this::staticAuth); router.route("/loginOut").handler(this::loginOut); router.route("/static/CreateAPI.html").handler(this::staticAPI); router.route("/static/CreateAPP.html").handler(this::staticAPP); router.route("/static/*").handler(StaticHandler.create(getStaticRoot())); // 查看系统信息 router.route("/static/sysInfo").handler(this::sysInfo); router.route("/static/sysReplaceIpList").handler(this::sysReplaceIpList); // Application相关 router.route("/static/findAPP").handler(this::findAPP); router.route("/static/getAPP/:name").handler(this::getAPP); router.route("/static/addAPP").handler(this::addAPP); router.route("/static/delAPP/:name").handler(this::delAPP); router.route("/static/updtAPP/:name").handler(this::loadUpdtAPP); router.route("/static/updtAPP").handler(this::updtAPP); router.route("/static/deployAPP/:name").handler(this::deployAPP); router.route("/static/unDeployAPP/:name").handler(this::unDeployAPP); // API相关 router.route("/static/findAPI/:name").handler(this::findAPI); router.route("/static/getAPI/:name").handler(this::getAPI); router.route("/static/addAPI").handler(this::addAPI); router.route("/static/updtAPI/:name").handler(this::loadUpdtAPI); router.route("/static/updtAPI").handler(this::updtAPI); router.route("/static/delAPI/:appName/:apiName").handler(this::delAPI); router.route("/static/startAllAPI/:appName").handler(this::startAllAPI); router.route("/static/startAPI/:apiName").handler(this::startAPI); router.route("/static/stopAPI/:appName/:apiName").handler(this::stopAPI); router.route("/static/trackInfo/:appName/:apiName").handler(this::getTrackInfo); // 欢迎页 router.route("/").handler(this::welcome); vertx.createHttpServer().requestHandler(router).listen(config().getInteger("clientPort", 5256), res -> { if (res.succeeded()) { LOG.info("start Clinet Verticle successful"); fut.complete(); } else { LOG.info("start Clinet Verticle unsuccessful"); fut.fail(res.cause()); } }); }
Example #9
Source File: RestAPIVerticle.java From vertx-blueprint-microservice with Apache License 2.0 | 4 votes |
/** * Enable clustered session storage in requests. * * @param router router instance */ protected void enableClusteredSession(Router router) { router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create( ClusteredSessionStore.create(vertx, "shopping.user.session"))); }
Example #10
Source File: WebExamples.java From vertx-web with Apache License 2.0 | 3 votes |
public void example33(Vertx vertx) { Router router = Router.router(vertx); // Create a clustered session store using defaults SessionStore store = ClusteredSessionStore.create(vertx); SessionHandler sessionHandler = SessionHandler.create(store); // the session handler controls the cookie used for the session // this includes configuring, for example, the same site policy // like this, for strict same site policy. sessionHandler.setCookieSameSite(CookieSameSite.STRICT); // Make sure all requests are routed through the session handler too router.route().handler(sessionHandler); // Now your application handlers router.route("/somepath/blah/").handler(ctx -> { Session session = ctx.session(); session.put("foo", "bar"); // etc }); }