protected void onRouteDispatch ( Request request , Response response ) { final String requestPath = request . getPath ( ) ; final String requestMethod = request . getMethod ( ) ; if ( shouldIgnorePath ( requestPath ) ) { // NOT FOUND (404) RouteContext routeContext = routeContextFactory . createRouteContext ( application , request , response , noMatches ) ; ROUTE_CONTEXT_THREAD_LOCAL . set ( routeContext ) ; errorHandler . handle ( HttpServletResponse . SC_NOT_FOUND , routeContext ) ; ROUTE_CONTEXT_THREAD_LOCAL . remove ( ) ; log . debug ( "Returned status code {} for {} '{}' (IGNORED)" , response . getStatus ( ) , requestMethod , requestPath ) ; return ; } List < RouteMatch > routeMatches = router . findRoutes ( requestMethod , requestPath ) ; RouteContext routeContext = routeContextFactory . createRouteContext ( application , request , response , routeMatches ) ; ROUTE_CONTEXT_THREAD_LOCAL . set ( routeContext ) ; try { if ( routeMatches . isEmpty ( ) ) { if ( notFoundRouteHandler != null ) { notFoundRouteHandler . handle ( routeContext ) ; } else { // NOT FOUND (404) errorHandler . handle ( HttpConstants . StatusCode . NOT_FOUND , routeContext ) ; } } else { processFlash ( routeContext ) ; } // execute the chain routeContext . next ( ) ; if ( ! response . isCommitted ( ) ) { if ( response . getStatus ( ) == 0 ) { log . debug ( "Status code not set for {} '{}'" , requestMethod , requestPath ) ; response . notFound ( ) ; } log . debug ( "Auto-committing response for {} '{}'" , requestMethod , requestPath ) ; if ( response . getStatus ( ) >= HttpServletResponse . SC_BAD_REQUEST ) { // delegate response to the error handler. // this will generate response content appropriate for the request errorHandler . handle ( response . getStatus ( ) , routeContext ) ; } else { response . commit ( ) ; } } } catch ( Exception e ) { errorHandler . handle ( e , routeContext ) ; } finally { routeContext . runFinallyRoutes ( ) ; log . debug ( "Returned status code {} for {} '{}'" , response . getStatus ( ) , requestMethod , requestPath ) ; ROUTE_CONTEXT_THREAD_LOCAL . remove ( ) ; } }
onRouteDispatch is the front - line for Route processing .