RequestContext requestContext = new RequestContext();
requestContext.setControllerBasePackage(Dispatcher.getControllerBasePackage());
requestContext.setControllerPaths(Dispatcher.getControllerPaths());
requestContext.setRequest(req);
RouteResult routeResult = null;
try{
routeResult = RouteTable.selectRoute(requestContext);
}
catch(Exception ex){
throw new ServletException(ex);
}
if (routeResult == null){
chain.doFilter(request, response);
}
else{
String controllerPackage = Dispatcher.getControllerBasePackage();
if (!routeResult.getSubPackageName().equals("")){
controllerPackage += "." + routeResult.getSubPackageName();
}
String controllerClassName = controllerPackage + "." + toControllerClassName(routeResult.getControllerName());
Controller controller;
try{
controller = (Controller)getController(controllerClassName);
req = wrapRequest(req, routeResult.getParams());
controller.init(this.filterConfig.getServletContext(), req, res, routeResult);
}
catch(Exception ex){
// ex.printStackTrace();
chain.doFilter(request, response);