List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
private Future<EventBusMessage> processUpdateRequest(final EventBusMessage request) { final String tenantId = request.getTenant(); final JsonObject payload = getRequestPayload(request.getJsonPayload()); if (tenantId == null) { log.debug("request does not contain mandatory property [{}]", MessageHelper.APP_PROPERTY_TENANT_ID); return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); } else if (isValidRequestPayload(payload)) { log.debug("updating tenant [{}]", tenantId); final Future<TenantResult<JsonObject>> updateResult = Future.future(); addNotPresentFieldsWithDefaultValuesForTenant(payload); update(tenantId, payload, updateResult.completer()); return updateResult.map(tr -> { return request.getResponse(tr.getStatus()).setJsonPayload(tr.getPayload()) .setCacheDirective(tr.getCacheDirective()); });//from w w w . ja v a2 s . c o m } else { log.debug("request contains malformed payload"); return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); } }
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
private Future<EventBusMessage> processRemoveRequest(final EventBusMessage request) { final String tenantId = request.getTenant(); if (tenantId == null) { log.debug("request does not contain mandatory property [{}]", MessageHelper.APP_PROPERTY_TENANT_ID); return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); } else {/*from ww w .j av a 2 s . c o m*/ log.debug("deleting tenant [{}]", tenantId); final Future<TenantResult<JsonObject>> removeResult = Future.future(); remove(tenantId, removeResult.completer()); return removeResult.map(tr -> { return request.getResponse(tr.getStatus()).setJsonPayload(tr.getPayload()) .setCacheDirective(tr.getCacheDirective()); }); } }
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
/** * Processes a request for a non-standard operation. * <p>// w w w . ja va2 s. co m * Subclasses should override this method in order to support additional, custom * operations that are not defined by Hono's Tenant API. * <p> * This default implementation simply returns a future that is failed with a * {@link ClientErrorException} with an error code <em>400 Bad Request</em>. * * @param request The request to process. * @return A future indicating the outcome of the service invocation. */ protected Future<EventBusMessage> processCustomTenantMessage(final EventBusMessage request) { log.debug("invalid operation in request message [{}]", request.getOperation()); return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); }
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
/** * Handles an unimplemented operation by failing the given handler * with a {@link ClientErrorException} having a <em>501 Not Implemented</em> status code. * // w w w. jav a 2 s .c o m * @param resultHandler The handler. */ protected void handleUnimplementedOperation( final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) { resultHandler.handle(Future.failedFuture(new ServerErrorException(HttpURLConnection.HTTP_NOT_IMPLEMENTED))); }
From source file:org.eclipse.hono.util.AggregatingInvocationResultHandler.java
License:Open Source License
@Override public void handle(final Boolean succeeded) { if (succeeded) { successfulResponses.incrementAndGet(); } else {/* w w w. j a v a 2 s .c om*/ unsuccessfulResponses.incrementAndGet(); } if (successfulResponses.get() + unsuccessfulResponses.get() == expectedNoOfResults) { if (unsuccessfulResponses.get() > 0) { overallResultHandler.handle(Future.failedFuture( String.format("%d invocations have been unsuccessful", unsuccessfulResponses.get()))); } else { LOG.debug("all invocations have succeeded"); overallResultHandler.handle(Future.succeededFuture()); } } }
From source file:org.eclipse.hono.vertx.example.base.HonoConsumerBase.java
License:Open Source License
/** * Create the message consumer that handles the downstream messages and invokes the notification callback * {@link #handleCommandReadinessNotification(TimeUntilDisconnectNotification)} if the message indicates that it * stays connected for a specified time. Supported are telemetry or event MessageConsumer. * * @return Future A succeeded future that contains the MessageConsumer if the creation was successful, a failed * Future otherwise.// ww w .j ava 2 s. c o m */ private Future<MessageConsumer> createConsumer() { switch (mode) { case EVENT: // create the eventHandler by using the helper functionality for demultiplexing messages to callbacks final Consumer<Message> eventHandler = MessageTap.getConsumer(this::handleEventMessage, this::handleCommandReadinessNotification); return honoClient.createEventConsumer(HonoExampleConstants.TENANT_ID, eventHandler, closeHook -> System.err.println("remotely detached consumer link")); case TELEMETRY: // create the telemetryHandler by using the helper functionality for demultiplexing messages to callbacks final Consumer<Message> telemetryHandler = MessageTap.getConsumer(this::handleTelemetryMessage, this::handleCommandReadinessNotification); return honoClient.createTelemetryConsumer(HonoExampleConstants.TENANT_ID, telemetryHandler, closeHook -> System.err.println("remotely detached consumer link")); default: return Future.failedFuture("No valid mode set for consumer."); } }
From source file:org.etourdot.vertx.marklogic.http.impl.DefaultRestService.java
License:Open Source License
@Override public void isAvalaible(Handler<AsyncResult<Void>> resultHandler) { newMarklogicRequest().head(PING_URL).execute(response -> { if (response instanceof ErrorResponse || HttpResponseStatus.UNAUTHORIZED.code() == response.statusCode()) { logger.debug("RestService unavailable !!!"); resultHandler.handle(Future.failedFuture(response.statusMessage())); } else {/*from w w w .j a va 2s .co m*/ logger.debug("RestService available"); resultHandler.handle(Future.succeededFuture()); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicAdminImpl.java
License:Open Source License
void createRESTAppServer(RestApiOptions restApiOption, Handler<AsyncResult<Void>> resultHandler) { requireNonNull(restApiOption, "restApiOption cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); MarkLogicRequest marklogicRequest = restService.newMarklogicRequest(); marklogicRequest.post(REST_APIS).withBody(restApiOption.toJson()).execute(response -> { if (HttpResponseStatus.CREATED.code() == response.statusCode()) { resultHandler.handle(Future.succeededFuture()); } else {//from www .jav a 2s . c o m response.contentHandler( buffer -> resultHandler.handle(Future.failedFuture(buffer.toJsonObject().encode()))); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicAdminImpl.java
License:Open Source License
void deleteRESTAppServer(RestApiOptions restApiOption, Handler<AsyncResult<String>> resultHandler) { requireNonNull(restApiOption, "restApiOption cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); requireNonNull(restApiOption.getRetrieveInstance(), "rettrieve-instance cannot be null"); String removeServerString = REST_APIS + "/" + restApiOption.getRetrieveInstance(); MarkLogicRequest marklogicRequest = restService.newMarklogicRequest(); if (restApiOption.isRemoveContent()) { marklogicRequest.addParam(INCLUDE, CONTENT); }// www. j av a2s .c o m if (restApiOption.isRemoveModules()) { marklogicRequest.addParam(INCLUDE, MODULES); } marklogicRequest.delete(removeServerString).withBody(restApiOption.toJson()).execute(response -> { if (HttpResponseStatus.ACCEPTED.code() == response.statusCode()) { // Todo: is it a convienient return ? resultHandler.handle(Future.succeededFuture("deleted")); } else { resultHandler.handle(Future.failedFuture(response.statusMessage())); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicAdminImpl.java
License:Open Source License
void getRESTAppServerConfig(RestApiOptions restApiOption, Handler<AsyncResult<JsonObject>> resultHandler) { requireNonNull(restApiOption, "restApiOption cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); String getServerString = REST_APIS; if (restApiOption.hasRetrieveInstance()) { getServerString += "/" + restApiOption.getRetrieveInstance(); }/*from w ww .jav a 2 s. c o m*/ MarkLogicRequest marklogicRequest = restService.newMarklogicRequest(); if (restApiOption.hasRetrieveDatabase()) { marklogicRequest.addParam(DATABASE, restApiOption.getRetrieveDatabase()); } marklogicRequest.get(getServerString).execute(response -> { if (HttpResponseStatus.OK.code() == response.statusCode()) { response.contentHandler( buffer -> resultHandler.handle(Future.succeededFuture(buffer.toJsonObject()))); } else { resultHandler.handle(Future.failedFuture(response.statusMessage())); } }); }