@Override public DefaultRouteContext createRouteContext(Application application, Request request, Response response, List<RouteMatch> routeMatches) { return new DefaultRouteContext(application, request, response, routeMatches); }
@Override public <T> T setSession(String name, T value) { getSession().put(name, value); return value; }
@Override public void redirect(String nameOrUriPattern, Map<String, Object> parameters) { String uri = uriFor(nameOrUriPattern, parameters); String applicationPath = application.getRouter().getApplicationPath(); if (!applicationPath.isEmpty()) { // remove application path uri = StringUtils.removeStart(uri.substring(applicationPath.length()), "/"); } redirect(uri); }
@Override @SuppressWarnings("unchecked") public <T> T getSession(String name) { return hasSession() ? (T) request.getSession().get(name) : null; }
@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); } }
@Override @SuppressWarnings("unchecked") public <T> T removeSession(String name) { return hasSession() ? (T) request.getSession().remove(name) : null; }
/** * 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(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(); }