use of org.eclipse.hono.client.command.Command in project hono by eclipse.
the class AbstractMappingAndDelegatingCommandHandler method reportInvalidCommand.
/**
* Reports an invalid command.
*
* @param commandContext The context of the command to report.
* @param timer The timer indicating the amount of time used for processing the command message.
*/
protected void reportInvalidCommand(final CommandContext commandContext, final Timer.Sample timer) {
final Command command = commandContext.getCommand();
final Future<TenantObject> tenantObjectFuture = tenantClient.get(command.getTenant(), commandContext.getTracingContext());
tenantObjectFuture.recover(// ignore error here
thr -> Future.succeededFuture(null)).onSuccess(tenantObjectOrNull -> {
metrics.reportCommand(command.isOneWay() ? MetricsTags.Direction.ONE_WAY : MetricsTags.Direction.REQUEST, command.getTenant(), tenantObjectOrNull, MetricsTags.ProcessingOutcome.UNPROCESSABLE, command.getPayloadSize(), timer);
});
}
use of org.eclipse.hono.client.command.Command in project hono by eclipse.
the class HttpBasedMessageMappingTest method testMapCommandSucceedsIfNoMapperIsSet.
/**
* Verifies that the result returned by the mapping service contains the
* original payload and target address if no upstream mapper has been defined for
* the gateway.
*
* @param ctx The helper to use for running tests on vert.x.
*/
@Test
public void testMapCommandSucceedsIfNoMapperIsSet(final VertxTestContext ctx) {
config.setMapperEndpoints(Map.of("mapper", MapperEndpoint.from("host", 1234, "/uri", false)));
final Command command = mock(Command.class);
final Buffer payload = Buffer.buffer("payload");
when(command.getPayload()).thenReturn(payload);
messageMapping.mapUpstreamMessage(new RegistrationAssertion("gateway"), command).onComplete(ctx.succeeding(mappedBuffer -> {
ctx.verify(() -> {
assertThat(mappedBuffer).isEqualTo(payload);
verify(mapperWebClient, never()).post(anyInt(), anyString(), anyString());
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.client.command.Command in project hono by eclipse.
the class HttpBasedMessageMappingTest method testMapCommandSucceedsIfNoMapperEndpointIsConfigured.
/**
* Verifies that the result returned by the mapping service contains the
* original payload and target address if no upstream mapper endpoint has been configured
* for the adapter.
*
* @param ctx The helper to use for running tests on vert.x.
*/
@Test
public void testMapCommandSucceedsIfNoMapperEndpointIsConfigured(final VertxTestContext ctx) {
final RegistrationAssertion assertion = new RegistrationAssertion("gateway").setUpstreamMessageMapper("mapper");
final Command command = mock(Command.class);
final Buffer payload = Buffer.buffer("payload");
when(command.getPayload()).thenReturn(payload);
messageMapping.mapUpstreamMessage(assertion, command).onComplete(ctx.succeeding(mappedBuffer -> {
ctx.verify(() -> {
assertThat(mappedBuffer).isEqualTo(payload);
verify(mapperWebClient, never()).post(anyInt(), anyString(), anyString());
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.client.command.Command in project hono by eclipse.
the class SigfoxProtocolAdapter method setNonEmptyResponsePayload.
@Override
protected void setNonEmptyResponsePayload(final HttpServerResponse response, final CommandContext commandContext, final Span currentSpan) {
currentSpan.log("responding with: payload");
final Command command = commandContext.getCommand();
response.setStatusCode(HttpURLConnection.HTTP_OK);
final Buffer payload = convertToResponsePayload(command);
LOG.debug("Setting response for ACK: {}", payload);
HttpUtils.setResponseBody(response, payload, HttpUtils.CONTENT_TYPE_JSON);
}
Aggregations