List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:org.politrons.auth.impl.MongoUser.java
License:Open Source License
/** * check wether the current user has the given role * /*ww w. ja v a 2 s . c o m*/ * @param role * the role to be checked * @param resultHandler * resultHandler gets true, if role is valid, otherwise false */ protected void doHasRole(String role, Handler<AsyncResult<Boolean>> resultHandler) { try { JsonArray roles = principal.getJsonArray(mongoAuth.getRoleField()); resultHandler.handle(Future.succeededFuture(roles != null && roles.contains(role))); } catch (Throwable e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:org.politrons.auth.impl.MongoUser.java
License:Open Source License
/** * Check wether the current user has the given permission * /* w ww . java2 s .co m*/ * @param permission * the permission to be checked * @param resultHandler * resulthandler gets true, if permission is valid, otherwise false * */ protected void doHasPermission(String permission, Handler<AsyncResult<Boolean>> resultHandler) { try { JsonArray userPermissions = principal.getJsonArray(mongoAuth.getPermissionField()); resultHandler.handle( Future.succeededFuture(userPermissions != null && userPermissions.contains(permission))); } catch (Throwable e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:org.sub.bug.BugCRUDServiceVertxEBProxy.java
License:Apache License
public void saveBug(Bug bug, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w.j a v a2 s .c o m*/ } JsonObject _json = new JsonObject(); _json.put("bug", bug == null ? null : bug.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "saveBug"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:org.sub.bug.BugCRUDServiceVertxEBProxy.java
License:Apache License
public void retrieveBug(String bugId, Handler<AsyncResult<Bug>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/* w w w .ja v a 2 s . c om*/ } JsonObject _json = new JsonObject(); _json.put("bugId", bugId); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "retrieveBug"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle( Future.succeededFuture(res.result().body() == null ? null : new Bug(res.result().body()))); } }); }
From source file:org.sub.bug.BugCRUDServiceVertxEBProxy.java
License:Apache License
public void removeBug(String bugId, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w . j a va 2s . c o m } JsonObject _json = new JsonObject(); _json.put("bugId", bugId); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "removeBug"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); }
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 w w.j a v a 2s .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:org.workspace7.k8s.auth.proxy.K8sWebProxyVerticle.java
License:Apache License
/** * @param keyCloakOAuth2//from ww w . ja va 2 s . co m * @param next */ protected void startWebApp(AsyncResult<OAuth2Auth> keyCloakOAuth2, Handler<AsyncResult<HttpServer>> next) { Router router = Router.router(vertx); final String proxyUri = "https://" + config().getString("k8s_proxy_host") + ":" + config().getInteger("k8s_proxy_port"); if (keyCloakOAuth2.succeeded()) { OAuth2AuthHandler keycloakOAuthHandler = OAuth2AuthHandler.create(keyCloakOAuth2.result(), proxyUri); keycloakOAuthHandler.setupCallback(router.get("/callback")); //router.route().handler(BodyHandler.create()); router.route("/api/*").handler(keycloakOAuthHandler); router.route("/ui/*").handler(keycloakOAuthHandler); //Handle UI Requests router.route("/ui/").handler(this::handleUIPath); //Handle API Requests router.route("/api/*").handler(this::handleApiPath); router.get("/").handler(ctx -> ctx.reroute("/ui/")); //These options are for setting up the server (k8s-proxy) HttpServerOptions httpServerOptions = new HttpServerOptions().setSsl(true); //Server HTTPS httpServerOptions.setPemKeyCertOptions(proxyPemOptions()); httpServerOptions.setTrustStoreOptions(proxyTrustOptions()); vertx.createHttpServer(httpServerOptions).requestHandler(router::accept) .listen(config().getInteger("k8s_proxy_port"), config().getString("k8s_proxy_host"), next); } else { _logger.error("Unable to start proxy : {}", keyCloakOAuth2.cause()); next.handle(Future.failedFuture(keyCloakOAuth2.cause())); } }
From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java
License:Apache License
public DatabaseConnection getSite(String id, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/* w ww . ja va 2s . c o m*/ JsonObject _json = new JsonObject(); _json.put("id", id); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "getSite"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java
License:Apache License
public DatabaseConnection getSites(Handler<AsyncResult<JsonArray>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/*from w w w . j a v a2 s . c o m*/ JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "getSites"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java
License:Apache License
public DatabaseConnection addSite(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w ww .j av a 2 s.co m JsonObject _json = new JsonObject(); _json.put("document", document); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "addSite"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }