Search in sources :

Example 6 with UriRoute

use of io.micronaut.web.router.UriRoute in project micronaut-aws by micronaut-projects.

the class MicronautRequestReader method readRequest.

@Override
public MicronautAwsProxyRequest<?> readRequest(AwsProxyRequest request, SecurityContext securityContext, Context lambdaContext, ContainerConfig config) throws InvalidRequestEventException {
    try {
        final String path = config.isStripBasePath() ? stripBasePath(request.getPath(), config) : getPathNoBase(request);
        final MicronautAwsProxyRequest<?> containerRequest = new MicronautAwsProxyRequest<>(path, request, securityContext, lambdaContext, config);
        List<UriRouteMatch<Object, Object>> uriRoutes = environment.getRouter().findAllClosest(containerRequest);
        if (!uriRoutes.isEmpty()) {
            UriRouteMatch<Object, Object> finalRoute = uriRoutes.get(0);
            final UriRoute route = finalRoute.getRoute();
            containerRequest.setAttribute(HttpAttributes.ROUTE, route);
            containerRequest.setAttribute(HttpAttributes.ROUTE_MATCH, finalRoute);
            containerRequest.setAttribute(HttpAttributes.ROUTE_INFO, finalRoute);
            containerRequest.setAttribute(HttpAttributes.URI_TEMPLATE, route.getUriMatchTemplate().toString());
        }
        return containerRequest;
    } catch (Exception e) {
        throw new InvalidRequestEventException("Invalid Request: " + e.getMessage(), e);
    }
}
Also used : UriRoute(io.micronaut.web.router.UriRoute) UriRouteMatch(io.micronaut.web.router.UriRouteMatch) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException)

Aggregations

UriRoute (io.micronaut.web.router.UriRoute)6 UriTemplate (io.micronaut.http.uri.UriTemplate)3 InvalidRequestEventException (com.amazonaws.serverless.exceptions.InvalidRequestEventException)1 ExecutableMethodProcessor (io.micronaut.context.processor.ExecutableMethodProcessor)1 Argument (io.micronaut.core.type.Argument)1 FunctionBean (io.micronaut.function.FunctionBean)1 MediaType (io.micronaut.http.MediaType)1 Consumes (io.micronaut.http.annotation.Consumes)1 Produces (io.micronaut.http.annotation.Produces)1 UriRouteMatch (io.micronaut.web.router.UriRouteMatch)1 OnMessage (io.micronaut.websocket.annotation.OnMessage)1 OnOpen (io.micronaut.websocket.annotation.OnOpen)1 ServerWebSocket (io.micronaut.websocket.annotation.ServerWebSocket)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1 BiFunction (java.util.function.BiFunction)1 Consumer (java.util.function.Consumer)1