Search in sources :

Example 31 with ClientErrorException

use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.

the class BaseTenantService method processUpdateRequest.

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());
        });
    } else {
        log.debug("request contains malformed payload");
        return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TenantResult(org.eclipse.hono.util.TenantResult) TenantConstants(org.eclipse.hono.util.TenantConstants) ServerErrorException(org.eclipse.hono.client.ServerErrorException) ClientErrorException(org.eclipse.hono.client.ClientErrorException) EventBusMessage(org.eclipse.hono.util.EventBusMessage) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Objects(java.util.Objects) EventBusService(org.eclipse.hono.service.EventBusService) JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) JsonObject(io.vertx.core.json.JsonObject) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Future(io.vertx.core.Future)

Example 32 with ClientErrorException

use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.

the class BaseTenantService method processRemoveRequest.

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 {
        log.debug("deleting tenant [{}]", tenantId);
        final Future<TenantResult<JsonObject>> removeResult = Future.future();
        remove(tenantId, removeResult.completer());
        return removeResult.map(tr -> {
            return EventBusMessage.forStatusCode(tr.getStatus()).setJsonPayload(tr.getPayload()).setTenant(tenantId).setCacheDirective(tr.getCacheDirective());
        });
    }
}
Also used : ClientErrorException(org.eclipse.hono.client.ClientErrorException) TenantResult(org.eclipse.hono.util.TenantResult)

Aggregations

ClientErrorException (org.eclipse.hono.client.ClientErrorException)32 JsonObject (io.vertx.core.json.JsonObject)19 Future (io.vertx.core.Future)16 HttpURLConnection (java.net.HttpURLConnection)16 Handler (io.vertx.core.Handler)14 AsyncResult (io.vertx.core.AsyncResult)13 Objects (java.util.Objects)12 ServerErrorException (org.eclipse.hono.client.ServerErrorException)10 TenantConstants (org.eclipse.hono.util.TenantConstants)9 EventBusService (org.eclipse.hono.service.EventBusService)8 EventBusMessage (org.eclipse.hono.util.EventBusMessage)8 Vertx (io.vertx.core.Vertx)6 Buffer (io.vertx.core.buffer.Buffer)6 ProtonDelivery (io.vertx.proton.ProtonDelivery)6 HonoClient (org.eclipse.hono.client.HonoClient)6 MqttEndpoint (io.vertx.mqtt.MqttEndpoint)5 MqttServer (io.vertx.mqtt.MqttServer)5 Optional (java.util.Optional)5 TimeUnit (java.util.concurrent.TimeUnit)5 Message (org.apache.qpid.proton.message.Message)5