use of com.blade.mvc.http.wrapper.ServletResponse 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);
}
}
Aggregations