/** * Verifies that a route is NOT handled. * * For instance you would call this route to make sure _test routes are not handled * in production mode. */ public void isNotHandledByRoutesInRouter() { assertTrue(router.getRouteFor(httpMethod, url) == null); }
/** * The worker method used internally. Checks if that route is active. * * @param router The router to ask. * @param httpMethod The method to use (GET, POST...) * @param url The url to use ("/_test" or "/profile/myId" ...) * @param controllerClass The controller class supposed to handle the url. * @param controllerMethodName The controller method supposed to handle the url * @return true if handled by given configuration / false if not. */ private static boolean isHttpMethodAndUrlMatchedByControllerClassAndControllerMethod( Router router, String httpMethod, String url, Class controllerClass, String controllerMethodName) { if (!router.getRouteFor(httpMethod, url).getControllerClass().equals(controllerClass)) { return false; } if (!router.getRouteFor(httpMethod, url).getControllerMethod().getName().equals( controllerMethodName)) { return false; } return true; }
@Override @Timed public void onRouteRequest(Context.Impl context) { activeRequests.inc(); String httpMethod = context.getMethod(); Route route = router.getRouteFor(httpMethod, context.getRequestPath()); context.setRoute(route); if (route != null) { allRequestsMeter.mark(); try { Result result = route.getFilterChain().next(context); resultHandler.handleResult(result, context); } catch (Exception exception) { if (exception instanceof BadRequestException) { badRequests.mark(); } else { internalServerErrors.mark(); } Result result = onException(context, exception); renderErrorResultAndCatchAndLogExceptions(result, context); } } else { // throw a 404 "not found" because we did not find the route routesNotFound.mark(); Result result = getNotFoundResult(context); renderErrorResultAndCatchAndLogExceptions(result, context); } activeRequests.dec(); }
Route route = router.getRouteFor(httpMethod, context.getRequestPath());