request.setCharacterEncoding("UTF-8");
} catch(Exception ex) {
LogUtils.log(Level.WARNING, "Cannot set character encoding to UTF-8");
}
HttpRequest httpRequest = requestParser.parseRequest(new HttpRequest(request));
HttpResponse httpResponse = new HttpResponse(response);
Exception exception = null;
try {
boolean found = false;
for(IRouter router: routers) {
IModule module = router.route(httpRequest);
if (module != null) {
found = true;
exception = dispatchModule(module, httpRequest, httpResponse, httpRequest.getTaskName());
break;
}
}
if (!found)
throw new NotFoundException("No routers match for request: "+request.getRequestURL().toString());
} catch (IceException ex) {
httpResponse.setException(ex);
httpResponse.setStatus(ex.status);
exception = ex;
}
if (Config.get("errorHandler") != null && exception != null) {
Class<? extends IErrorHandler> c = (Class<? extends IErrorHandler>) Config.get("errorHandler").getClass();
try {
IErrorHandler handler = (IErrorHandler) c.newInstance();
handler.setException(exception);
httpResponse.clearContent();
dispatchModule(handler, httpRequest, httpResponse, "error");
} catch (Exception ex) {
httpResponse.setStatus(500);
httpResponse.setException(ex);
}
}
httpResponse.sendResponse();
httpResponse = null;
}