@Override public Route findRoute( String name, Router router ) { return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().orElse( null ); } }
/** * Returns the first route match for a given call. * * @param request * The request to score. * @param response * The response to score. * @param requiredScore * The minimum score required to have a match. * @return The first route match or null. */ public Route getFirst(Request request, Response response, float requiredScore) { for (Route current : this) { if (current.score(request, response) >= requiredScore) { return current; } } // No match found return null; }
for (final Route route : component.getDefaultHost() .getRoutes()) { if (route.getTemplate().getPattern() == null) { addFullServletPath = true; continue; if (!route.getTemplate().getPattern().startsWith( uriPattern)) { if (!route.getTemplate().getPattern() .startsWith(request.getServletPath())) { addFullServletPath = true; for (final Route route : virtualHost .getRoutes()) { if (route.getTemplate().getPattern() == null) { addFullServletPath = true; continue; if (!route.getTemplate().getPattern() .startsWith(uriPattern)) { if (!route .getTemplate() .getPattern() .startsWith( .getDefaultRoute(); if (defaultRoute != null) { defaultRoute.getTemplate().setPattern( offsetPath
/** * Sets the next virtual host. * * @param next * The next virtual host. */ public void setNext(VirtualHost next) { super.setNext(next); } }
/** * Sets the next client. * * @param next * The next client. */ public void setNext(Client next) { super.setNext(next); } }
private static void collectForRoute(CollectInfo collectInfo, String basePath, Route route, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); collect(collectInfo, basePath + path, route.getNext(), scheme, introspectionHelper); } else { LOGGER.fine("Route type ignored. Class " + route.getClass()); } }
/** * Returns the best route match for a given call. * * @param request * The request to score. * @param response * The response to score. * @param requiredScore * The minimum score required to have a match. * @return The best route match or null. */ public Route getBest(Request request, Response response, float requiredScore) { Route result = null; float bestScore = 0F; float score; for (Route current : this) { score = current.score(request, response); if ((score > bestScore) && (score >= requiredScore)) { bestScore = score; result = current; } } return result; }
private static void collectForRoute(CollectInfo collectInfo, String basePath, Route route, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); collect(collectInfo, basePath + path, route.getNext(), scheme, introspectionHelper); } else { LOGGER.fine("Route type ignored. Class " + route.getClass()); } }
private static void collectForRoute(CollectInfo collectInfo, String basePath, Route route, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); collect(collectInfo, basePath + path, route.getNext(), scheme, introspectionHelper); } else { LOGGER.fine("Route type ignored. Class " + route.getClass()); } }
/** * Returns the last route match for a given call. * * @param request * The request to score. * @param response * The response to score. * @param requiredScore * The minimum score required to have a match. * @return The last route match or null. */ public synchronized Route getLast(Request request, Response response, float requiredScore) { for (int j = size() - 1; (j >= 0); j--) { final Route route = get(j); if (route.score(request, response) >= requiredScore) { return route; } } // No match found return null; }
private static void collectForRoute(CollectInfo collectInfo, String basePath, Route route, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); collect(collectInfo, basePath + path, route.getNext(), scheme, introspectionHelper); } else { LOGGER.fine("Route type ignored. Class " + route.getClass()); } }
/** * Returns a next route match in a round robin mode for a given call. * * @param request * The request to score. * @param response * The response to score. * @param requiredScore * The minimum score required to have a match. * @return A next route or null. */ public synchronized Route getNext(Request request, Response response, float requiredScore) { if (!isEmpty()) { for (final int initialIndex = this.lastIndex++; initialIndex != this.lastIndex; this.lastIndex++) { if (this.lastIndex >= size()) { this.lastIndex = 0; } final Route route = get(this.lastIndex); if (route.score(request, response) >= requiredScore) { return route; } } } // No match found return null; }
private static void collectForRoute(CollectInfo collectInfo, String basePath, Route route, ChallengeScheme scheme, List<? extends IntrospectionHelper> introspectionHelper) { if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); collect(collectInfo, basePath + path, route.getNext(), scheme, introspectionHelper); } else { LOGGER.fine("Route type ignored. Class " + route.getClass()); } }
&& (getDefaultRoute().score(request, response) >= getRequiredScore())) { result = getDefaultRoute(); } else {
private void describeRoutes(StringBuilder b, Router router, String path) { RouteList routes = router.getRoutes(); b.append("[").append(path).append("] = Router: ").append(router.getName()).append(": ").append(router.getDescription()).append("\n"); for (Route r : routes) { if (r instanceof TemplateRoute) { describe(b, r.getNext(), path + ((TemplateRoute)r).getTemplate().getPattern()); } } }
/** * Returns the WADL data about the given Route instance. * * @param applicationInfo * The parent application. * @param route * The Route instance to document. * @param basePath * The base path. * @param request * The current request. * @param response * The current response. * @return The WADL data about the given Route instance. */ private ResourceInfo getResourceInfo(ApplicationInfo applicationInfo, Route route, String basePath, Request request, Response response) { ResourceInfo result = null; if (route instanceof TemplateRoute) { TemplateRoute templateRoute = (TemplateRoute) route; String path = templateRoute.getTemplate().getPattern(); // WADL requires resource paths to be relative to parent path if (path.startsWith("/") && basePath.endsWith("/")) { path = path.substring(1); } result = getResourceInfo(applicationInfo, route.getNext(), path, request, response); } return result; }
/** * Removes all routes routing to a given target. * * @param target * The target Restlet to detach. */ public synchronized void removeAll(Restlet target) { for (int i = size() - 1; i >= 0; i--) { if (get(i).getNext() == target) { remove(i); } } }
/** * Detaches the target from this router. All routes routing to this target * Restlet are removed from the list of routes and the default route is set * to null. * * @param targetClass * The target class to detach. */ public void detach(Class<?> targetClass) { for (int i = getRoutes().size() - 1; i >= 0; i--) { Restlet target = getRoutes().get(i).getNext(); if (target != null && Finder.class.isAssignableFrom(target.getClass())) { Finder finder = (Finder) target; if (finder.getTargetClass().equals(targetClass)) { getRoutes().remove(i); } } } if (getDefaultRoute() != null) { Restlet target = getDefaultRoute().getNext(); if (target != null && Finder.class.isAssignableFrom(target.getClass())) { Finder finder = (Finder) target; if (finder.getTargetClass().equals(targetClass)) { setDefaultRoute(null); } } } }