use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class ProtonBasedDownstreamSenderTest method testSenderClientCreationErrorIsMappedToServerErrorOnSendTelemetry.
/**
* Verifies that a ClientErrorException that occurs when creating an AMQP sender link is mapped to a
* ServerErrorException with status 503 by the <em>sendTelemetry</em> method.
*
* @param ctx The vert.x test context.
*/
@Test
public void testSenderClientCreationErrorIsMappedToServerErrorOnSendTelemetry(final VertxTestContext ctx) {
final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true);
final RegistrationAssertion device = new RegistrationAssertion("4711");
testSenderClientCreationErrorIsMappedToServerErrorOnSending(ctx, () -> sender.sendTelemetry(tenant, device, QoS.AT_MOST_ONCE, null, null, null, span.context()));
}
use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class ProtonBasedDownstreamSenderTest method testSenderClientCreationErrorIsMappedToServerErrorOnSendEvent.
/**
* Verifies that a ClientErrorException that occurs when creating an AMQP sender link is mapped to a
* ServerErrorException with status 503 by the <em>sendEvent</em> method.
*
* @param ctx The vert.x test context.
*/
@Test
public void testSenderClientCreationErrorIsMappedToServerErrorOnSendEvent(final VertxTestContext ctx) {
final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true);
final RegistrationAssertion device = new RegistrationAssertion("4711");
testSenderClientCreationErrorIsMappedToServerErrorOnSending(ctx, () -> sender.sendEvent(tenant, device, null, null, null, span.context()));
}
use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class ProtonBasedDownstreamSenderTest method testSendEventMarksMessageAsDurable.
/**
* Verifies that the proton message being transferred when sending an event is marked as durable.
*/
@Test
public void testSendEventMarksMessageAsDurable() {
// WHEN sending an event
final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true);
final RegistrationAssertion device = new RegistrationAssertion("4711");
sender.sendEvent(tenant, device, "text/plain", Buffer.buffer("hello"), null, span.context());
verify(protonSender).send(argThat(Message::isDurable), VertxMockSupport.anyHandler());
}
use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class AbstractProtocolAdapterBase method getRegistrationAssertion.
@Override
public final Future<RegistrationAssertion> getRegistrationAssertion(final String tenantId, final String deviceId, final Device authenticatedDevice, final SpanContext context) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
final Future<String> gatewayId = getGatewayId(tenantId, deviceId, authenticatedDevice);
return gatewayId.compose(gwId -> getRegistrationClient().assertRegistration(tenantId, deviceId, gwId, context)).onSuccess(assertion -> {
// the updateLastGateway invocation shouldn't delay or possibly fail the surrounding operation
// so don't wait for the outcome here
updateLastGateway(assertion, tenantId, deviceId, authenticatedDevice, context).onFailure(t -> {
log.warn("failed to update last gateway [tenantId: {}, deviceId: {}]", tenantId, deviceId, t);
});
}).recover(error -> {
final int errorCode = ServiceInvocationException.extractStatusCode(error);
if (errorCode == HttpURLConnection.HTTP_NOT_FOUND) {
return Future.failedFuture(new DeviceDisabledOrNotRegisteredException(tenantId, errorCode));
} else if (errorCode == HttpURLConnection.HTTP_FORBIDDEN) {
return Future.failedFuture(new GatewayDisabledOrNotRegisteredException(tenantId, errorCode));
} else {
return Future.failedFuture(error);
}
});
}
use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class AbstractMessageSenderConnectionEventProducer method sendNotificationEvent.
private Future<Void> sendNotificationEvent(final Context context, final Device authenticatedDevice, final String protocolAdapter, final String remoteId, final String cause, final JsonObject data, final SpanContext spanContext) {
if (authenticatedDevice == null) {
// we only handle authenticated devices
return Future.succeededFuture();
}
final String tenantId = authenticatedDevice.getTenantId();
final String deviceId = authenticatedDevice.getDeviceId();
return context.getTenantClient().get(tenantId, spanContext).compose(tenant -> {
final JsonObject payload = new JsonObject();
payload.put("cause", cause);
payload.put("remote-id", remoteId);
payload.put("source", protocolAdapter);
if (data != null) {
payload.put("data", data);
}
return Optional.ofNullable(context.getMessageSenderClient()).map(client -> client.sendEvent(tenant, new RegistrationAssertion(deviceId), EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE, payload.toBuffer(), null, spanContext)).orElseGet(Future::succeededFuture);
});
}
Aggregations