List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:com.englishtown.vertx.elasticsearch.ElasticSearchServiceVertxEBProxy.java
License:Apache License
public void delete(String index, String type, String id, DeleteOptions options, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;// ww w. j a v a 2 s. c o m } JsonObject _json = new JsonObject(); _json.put("index", index); _json.put("type", type); _json.put("id", id); _json.put("options", options == null ? null : options.toJson()); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "delete"); _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())); } }); }
From source file:com.englishtown.vertx.mail.MailServiceVertxEBProxy.java
License:Apache License
public void send(SendOptions options, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w . j a va 2s . co m } JsonObject _json = new JsonObject(); _json.put("options", options == null ? null : options.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "send"); _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:com.englishtown.vertx.solr.SolrServiceVertxEBProxy.java
License:Apache License
public void query(JsonObject query, QueryOptions options, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*w ww . j a v a 2s .co m*/ } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("options", options == null ? null : options.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "query"); _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())); } }); }
From source file:com.example.myservice.services.ProductServiceVertxEBProxy.java
License:Apache License
public void list(Handler<AsyncResult<JsonArray>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from www .j ava 2 s . co m*/ } JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = new DeliveryOptions(); _deliveryOptions.addHeader("action", "list"); _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())); } }); }
From source file:com.github.ithildir.airbot.server.SingleUserAuthProvider.java
License:Open Source License
@Override public void authenticate(JsonObject authInfoJsonObject, Handler<AsyncResult<User>> handler) { String username = authInfoJsonObject.getString("username"); if (username == null) { handler.handle(Future.failedFuture("Unable to get username in authentication info")); return;/*w w w .ja va 2 s.c om*/ } String password = authInfoJsonObject.getString("password"); if (password == null) { handler.handle(Future.failedFuture("Unable to get password in authentication info")); return; } if (!_username.equals(username) || !_password.equals(password)) { handler.handle(Future.failedFuture("Invalid username/password")); return; } handler.handle(Future.succeededFuture(_user)); }
From source file:com.github.ithildir.airbot.service.GeoServiceVertxEBProxy.java
License:Apache License
public void getLocationByCoordinates(double latitude, double longitude, Handler<AsyncResult<Location>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from ww w . j a va 2 s .co m } JsonObject _json = new JsonObject(); _json.put("latitude", latitude); _json.put("longitude", longitude); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getLocationByCoordinates"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future .succeededFuture(res.result().body() == null ? null : new Location(res.result().body()))); } }); }
From source file:com.github.ithildir.airbot.service.GeoServiceVertxEBProxy.java
License:Apache License
public void getLocationByQuery(String query, Handler<AsyncResult<Location>> handler) { if (closed) { handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;/*from w w w.j a va2s .c om*/ } JsonObject _json = new JsonObject(); _json.put("query", query); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getLocationByQuery"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { handler.handle(Future .succeededFuture(res.result().body() == null ? null : new Location(res.result().body()))); } }); }
From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }// w w w. j a va 2 s . c o m HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { handler.handle(ServiceException.fail(statusCode, httpResponse.statusMessage())); return null; } return httpResponse; }
From source file:com.github.ithildir.airbot.service.impl.MapQuestGeoServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }/*from ww w . ja va2s . c om*/ HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { handler.handle(ServiceException.fail(statusCode, httpResponse.bodyAsString())); return null; } return httpResponse; }
From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }// www . j a v a 2 s. co m HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { JsonObject jsonObject = httpResponse.bodyAsJsonObject(); handler.handle(ServiceException.fail(statusCode, jsonObject.getString("message"), jsonObject)); return null; } return httpResponse; }