@Test public void testFindRoutes() throws Exception { Route route = Route.GET("/contact", emptyHandler); router.addRoute(route); List<RouteMatch> routeMatches = router.findRoutes(HttpConstants.Method.GET, "/contact"); assertNotNull(routeMatches); assertEquals(1, routeMatches.size()); routeMatches = router.findRoutes(HttpConstants.Method.POST, "/contact"); assertNotNull(routeMatches); assertEquals(0, routeMatches.size()); routeMatches = router.findRoutes(HttpConstants.Method.GET, "/"); assertNotNull(routeMatches); assertEquals(0, routeMatches.size()); }
@Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); 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) { routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; }
DefaultRouter implements Router { @Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); 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) { routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; } }
DefaultRouter implements Router { @Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); 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) { routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; } DefaultRouter(); }
DefaultRouter implements Router { @Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); 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) { routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; } DefaultRouter(); @Override String getContextPath(); @Override void setContextPath(String contextPath); @Override Set<String> getIgnorePaths(); @Override void ignorePaths(String... pathPrefixes); @Override final List<Route> getRoutes(); @Override void compileRoutes(); List<Route> getRoutes(String requestMethod); @Override List<RouteMatch> findRoutes(String requestMethod, String requestUri); @Override void addRoute(Route route); @Override void removeRoute(Route route); @Override void addRouteGroup(RouteGroup routeGroup); @Override void removeRouteGroup(RouteGroup routeGroup); @Override String uriFor(String relativeUri); @Override String uriFor(String nameOrUriPattern, Map<String, Object> parameters); @Override String uriPatternFor(Class<? extends ResourceHandler> resourceHandlerClass); @Override String getApplicationPath(); @Override void setApplicationPath(String applicationPath); @Override void addRouteTransformer(RouteTransformer transformer); @Override List<RouteTransformer> getRouteTransformers(); }
DefaultRouter implements Router { @Override public List<RouteMatch> findRoutes(String requestMethod, String requestUri) { log.trace("Finding route matches for {} '{}'", requestMethod, requestUri); 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) { routeMatches.add(new RouteMatch(route, parameters)); } } } log.debug("Found {} route matches for {} '{}'", routeMatches.size(), requestMethod, requestUri); return routeMatches; } DefaultRouter(); @Override String getContextPath(); @Override void setContextPath(String contextPath); @Override Set<String> getIgnorePaths(); @Override void ignorePaths(String... pathPrefixes); @Override final List<Route> getRoutes(); @Override void compileRoutes(); List<Route> getRoutes(String requestMethod); @Override List<RouteMatch> findRoutes(String requestMethod, String requestUri); @Override void addRoute(Route route); @Override void removeRoute(Route route); @Override void addRouteGroup(RouteGroup routeGroup); @Override void removeRouteGroup(RouteGroup routeGroup); @Override String uriFor(String relativeUri); @Override String uriFor(String nameOrUriPattern, Map<String, Object> parameters); @Override String uriPatternFor(Class<? extends ResourceHandler> resourceHandlerClass); @Override String getApplicationPath(); @Override void setApplicationPath(String applicationPath); @Override void addRouteTransformer(RouteTransformer transformer); @Override List<RouteTransformer> getRouteTransformers();  }