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);
}
}
Aggregations