Search in sources :

Example 11 with LoraProvider

use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.

the class LoraProtocolAdapterTest method getLoraProviderMock.

private LoraProvider getLoraProviderMock(final LoraMessage message) {
    final LoraProvider provider = mock(LoraProvider.class);
    when(provider.getProviderName()).thenReturn(TEST_PROVIDER);
    when(provider.pathPrefixes()).thenReturn(Set.of("/bumlux"));
    when(provider.getMessage(any(RoutingContext.class))).thenReturn(message);
    return provider;
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) LoraProvider(org.eclipse.hono.adapter.lora.providers.LoraProvider)

Example 12 with LoraProvider

use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.

the class LoraProtocolAdapterTest method handleProviderRouteDiscardsOtherMessages.

/**
 * Verifies that the provider route discards other messages.
 */
@Test
public void handleProviderRouteDiscardsOtherMessages() {
    givenATelemetrySenderForAnyTenant();
    final LoraMessage message = mock(LoraMessage.class);
    when(message.getType()).thenReturn(LoraMessageType.UNKNOWN);
    final LoraProvider providerMock = getLoraProviderMock(message);
    final HttpContext httpContext = newHttpContext();
    adapter.handleProviderRoute(httpContext, providerMock);
    verify(httpContext.getRoutingContext()).put(LoraConstants.APP_PROPERTY_ORIG_LORA_PROVIDER, TEST_PROVIDER);
    assertNoTelemetryMessageHasBeenSentDownstream();
    verify(httpContext.response()).setStatusCode(HttpResponseStatus.ACCEPTED.code());
    verify(processMessageSpan).finish();
}
Also used : LoraProvider(org.eclipse.hono.adapter.lora.providers.LoraProvider) HttpContext(org.eclipse.hono.service.http.HttpContext) Test(org.junit.jupiter.api.Test)

Example 13 with LoraProvider

use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.

the class LoraProtocolAdapter method addRoutes.

@Override
protected void addRoutes(final Router router) {
    // the LoraWAN adapter always requires network providers to authenticate
    setupAuthorization(router);
    for (final LoraProvider provider : loraProviders) {
        for (final String pathPrefix : provider.pathPrefixes()) {
            router.route(HttpMethod.OPTIONS, pathPrefix).handler(this::handleOptionsRoute);
            router.route(provider.acceptedHttpMethod(), pathPrefix).consumes(provider.acceptedContentType()).handler(ctx -> this.handleProviderRoute(HttpContext.from(ctx), provider));
            router.route(provider.acceptedHttpMethod(), pathPrefix).handler(ctx -> {
                LOG.debug("request does not contain content-type header, will return 400 ...");
                handle400(ctx, ERROR_MSG_MISSING_OR_UNSUPPORTED_CONTENT_TYPE);
            });
        }
    }
}
Also used : LoraProvider(org.eclipse.hono.adapter.lora.providers.LoraProvider)

Aggregations

LoraProvider (org.eclipse.hono.adapter.lora.providers.LoraProvider)13 HttpContext (org.eclipse.hono.service.http.HttpContext)10 Test (org.junit.jupiter.api.Test)8 RoutingContext (io.vertx.ext.web.RoutingContext)5 CommandConsumer (org.eclipse.hono.client.command.CommandConsumer)5 CommandEndpoint (org.eclipse.hono.util.CommandEndpoint)5 Buffer (io.vertx.core.buffer.Buffer)4 JsonObject (io.vertx.core.json.JsonObject)4 LoraProviderMalformedPayloadException (org.eclipse.hono.adapter.lora.providers.LoraProviderMalformedPayloadException)4 Command (org.eclipse.hono.client.command.Command)4 CommandContext (org.eclipse.hono.client.command.CommandContext)4 TracingHandler (org.eclipse.hono.service.http.TracingHandler)4 Sample (io.micrometer.core.instrument.Timer.Sample)3 Span (io.opentracing.Span)3 SpanContext (io.opentracing.SpanContext)3 Future (io.vertx.core.Future)3 HttpRequest (io.vertx.ext.web.client.HttpRequest)3 WebClient (io.vertx.ext.web.client.WebClient)3 HttpURLConnection (java.net.HttpURLConnection)3 ArrayList (java.util.ArrayList)3