Search in sources :

Example 11 with RegistrationResult

use of org.eclipse.hono.util.RegistrationResult in project hono by eclipse.

the class BaseRegistrationService method processUpdateRequest.

private Future<EventBusMessage> processUpdateRequest(final EventBusMessage request) {
    final String tenantId = request.getTenant();
    final String deviceId = request.getDeviceId();
    final JsonObject payload = getRequestPayload(request.getJsonPayload());
    if (tenantId == null || deviceId == null) {
        return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
    } else {
        log.debug("updating registration information for device [{}] of tenant [{}]", deviceId, tenantId);
        final Future<RegistrationResult> result = Future.future();
        updateDevice(tenantId, deviceId, payload, result.completer());
        return result.map(res -> {
            return request.getResponse(res.getStatus()).setDeviceId(deviceId).setCacheDirective(res.getCacheDirective());
        });
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RegistrationResult(org.eclipse.hono.util.RegistrationResult)

Example 12 with RegistrationResult

use of org.eclipse.hono.util.RegistrationResult in project hono by eclipse.

the class BaseRegistrationService method processRegisterRequest.

private Future<EventBusMessage> processRegisterRequest(final EventBusMessage request) {
    final String tenantId = request.getTenant();
    final String deviceId = request.getDeviceId();
    final JsonObject payload = getRequestPayload(request.getJsonPayload());
    if (tenantId == null || deviceId == null) {
        return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
    } else {
        log.debug("registering device [{}] for tenant [{}]", deviceId, tenantId);
        final Future<RegistrationResult> result = Future.future();
        addDevice(tenantId, deviceId, payload, result.completer());
        return result.map(res -> {
            return request.getResponse(res.getStatus()).setDeviceId(deviceId).setCacheDirective(res.getCacheDirective());
        });
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RegistrationResult(org.eclipse.hono.util.RegistrationResult)

Aggregations

RegistrationResult (org.eclipse.hono.util.RegistrationResult)12 JsonObject (io.vertx.core.json.JsonObject)7 ClientErrorException (org.eclipse.hono.client.ClientErrorException)6 Test (org.junit.Test)5 Handler (io.vertx.core.Handler)3 HttpURLConnection (java.net.HttpURLConnection)3 CacheDirective (org.eclipse.hono.util.CacheDirective)3 RegistrationConstants (org.eclipse.hono.util.RegistrationConstants)3 AsyncResult (io.vertx.core.AsyncResult)2 CompositeFuture (io.vertx.core.CompositeFuture)2 Future (io.vertx.core.Future)2 Objects (java.util.Objects)2 EventBusService (org.eclipse.hono.service.EventBusService)2 EventBusMessage (org.eclipse.hono.util.EventBusMessage)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 Jwts (io.jsonwebtoken.Jwts)1 SignatureAlgorithm (io.jsonwebtoken.SignatureAlgorithm)1 Context (io.vertx.core.Context)1 Vertx (io.vertx.core.Vertx)1