@Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); // force compile routes compileRoutes(); List<RouteMatch> routeMatches = new ArrayList<>(); for (Route route : compiledRoutes) { boolean methodMatches = route.getRequestMethod().equals(requestMethod) || route.getRequestMethod().equals(HttpConstants.Method.ANY); if (methodMatches) { String uriPattern = route.getUriPattern(); Map<String, String> parameters = uriMatcher.match(requestUri, uriPattern); if (parameters != null) { // complete matching => add route match ro returned list routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; }
@Override public void next() { if (iterator.hasNext()) { // retrieves the next route RouteMatch routeMatch = iterator.next(); Route route = routeMatch.getRoute(); log.trace("Found {}", route); // set the new path parameters in request Map<String, String> pathParameters = routeMatch.getPathParameters(); if (pathParameters != null) { request.internalSetPathParameters(pathParameters); log.trace("Added path parameters to request"); } // remove route from chain iterator.remove(); handleRoute(route); } }
/** * Execute all routes that are flagged to run as finally. */ @Override public void runFinallyRoutes() { while (iterator.hasNext()) { Route route = iterator.next().getRoute(); if (route.isRunAsFinally()) { try { handleRoute(route); } catch (Exception e) { log.error("Unexpected error in Finally Route", e); } } else if (log.isDebugEnabled()) { if (StringUtils.isNullOrEmpty(route.getName())) { log.debug("context.next() not called, skipping handler for {} '{}'", route.getRequestMethod(), route.getUriPattern()); } else { log.debug("context.next() not called, skipping '{}' for {} '{}'", route.getName(), route.getRequestMethod(), route.getUriPattern()); } } } }
protected void processRouteInterceptors(RouteContext routeContext) { if (interceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler interceptor : interceptors) { // create a route for interceptor Route route = new Route(routeContext.getRequestMethod(), routeContext.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", Interceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); route.bindAll(routeContext.getRoute().getAttributes()); // add route in chain RouteMatch match = new RouteMatch(route, null); chain.add(match); } // TODO DefaultRouteContext is hardcoded RouteContext context = new DefaultRouteContext(routeContext.getApplication(), routeContext.getRequest(), routeContext.getResponse(), chain); context.next(); }
protected void processRouteInterceptors(Context context) { if (routeInterceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler<Context> interceptor : routeInterceptors) { Route route = new Route(context.getRequestMethod(), context.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", RouteInterceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); RouteMatch match = new RouteMatch(route, null); chain.add(match); } Context subContext = new Context(context, chain); subContext.next(); }
protected void processRouteInterceptors(Context context) { if (routeInterceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler<Context> interceptor : routeInterceptors) { Route route = new Route(context.getRequestMethod(), context.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", RouteInterceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); RouteMatch match = new RouteMatch(route, null); chain.add(match); } Context subContext = new Context(context, chain); subContext.next(); }
protected void processRouteInterceptors(RouteContext routeContext) { if (interceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler interceptor : interceptors) { // create a route for interceptor Route route = new Route(routeContext.getRequestMethod(), routeContext.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", Interceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); route.bindAll(routeContext.getRoute().getAttributes()); // add route in chain RouteMatch match = new RouteMatch(route, null); chain.add(match); } // TODO DefaultRouteContext is hardcoded RouteContext context = new DefaultRouteContext(routeContext.getApplication(), routeContext.getRequest(), routeContext.getResponse(), chain); context.next(); }