use of com.blade.mvc.route.Route in project blade by biezhi.
the class AbstractFileRouteLoader method load.
/**
* Load Route
*
* @param inputStream route inputstream
* @return return route list
* @throws ParseException parse exception
* @throws IOException io exception
*/
private List<Route> load(InputStream inputStream) throws ParseException, IOException {
int line = 0;
List<Route> routes = new ArrayList<Route>();
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(inputStream));
String input;
while ((input = in.readLine()) != null) {
line++;
input = input.trim();
if (!input.equals("") && !input.startsWith(".")) {
Route route = parse(input, line);
routes.add(route);
}
}
} finally {
IOKit.closeQuietly(in);
}
return routes;
}
use of com.blade.mvc.route.Route in project blade by biezhi.
the class DispatcherHandler method handle.
public void handle(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
// Create Response
Response response = new ServletResponse(httpResponse);
response.contentType("text/html;charset=utf-8");
try {
// http method, GET/POST ...
String method = httpRequest.getMethod();
// reuqest uri
String uri = Path.getRelativePath(httpRequest.getRequestURI(), httpRequest.getContextPath());
LOGGER.info("{}\t{}\t{}", method, uri, httpRequest.getProtocol());
Request request = new ServletRequest(httpRequest);
WebContextHolder.init(request, response);
Route route = routeMatcher.getRoute(method, uri);
if (null != route) {
if (route.getHttpMethod() != HttpMethod.valueOf(method) && route.getHttpMethod() != HttpMethod.ALL) {
render405(response, uri);
} else {
request.setRoute(route);
// before inteceptor
List<Route> befores = routeMatcher.getBefore(uri);
boolean result = invokeInterceptor(request, response, befores);
if (result) {
// execute
this.routeHandle(request, response, route);
if (!request.isAbort()) {
// after inteceptor
List<Route> afters = routeMatcher.getAfter(uri);
invokeInterceptor(request, response, afters);
}
}
}
} else {
// Not found
render404(response, uri);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
DispatchKit.printError(e, 500, response);
}
}
use of com.blade.mvc.route.Route in project blade by biezhi.
the class AbstractFileRouteLoader method buildRoute.
/**
* Construct a routing object
*
* @param httpMethod request httpMethod
* @param path route path
* @param controllerName controller name
* @param methodName method name
* @return return route object
* @throws RouteException
*/
private Route buildRoute(String httpMethod, String path, String controllerName, String methodName) throws RouteException {
Object controller = controllerLoader.load(controllerName);
Class<?> controllerType = controller.getClass();
Method method = getMethod(controllerType, methodName);
return new Route(HttpMethod.valueOf(httpMethod.toUpperCase()), path, controller, controllerType, method);
}
Aggregations