String api = request.getParameter("api");
if(api == null) {
throw new ServletException(Constants.SESSION_MANAGER + " parameter not found (please set module name)");
}
Module module = manager.getModule(api);
if(module != null) {
//logger.trace("Call module: " + module.getInfo().getName());
try {
XWebUser user = (XWebUser) request.getSession().getAttribute(Constants.SESSION_USER);
module.process(getServletContext(), request, response, user == null ? null : user.getRole());
} catch (ModuleException ex) {
//int errorCode = ex.getErrorCode();
int responseCode = ex.getReponseCode();
if(responseCode == HttpServletResponse.SC_NOT_FOUND) {
logger.trace("Data not found. " +
"Module: " + module.getInfo().getName() +
" Code: " + ex.getErrorCode(), ex);
} else if(module.redirectAuthFail() && responseCode == HttpServletResponse.SC_UNAUTHORIZED) {
// OK!
// When Authentication exception happen, we it be possible (module have this feature and
// redirect URL was available) we will redirect connection to authentication page
// TODO: Not support after modular Authentication
/*String redirect = manager.getProperty(Constants.AUTHENTICATION_REDIRECT);
if(redirect != null) {
String uri = request.getRequestURI().substring(request.getContextPath().length());
response.sendRedirect(getServletContext().getContextPath()
+ redirect + "?url="
+ getServletContext().getContextPath()
+ URLEncoder.encode(uri + "?" + request.getQueryString(), "UTF-8"));
return;
}*/
} else {
logger.error("Error in module process." +
" Module: " + module.getInfo().getName() +
" Code: " + ex.getErrorCode(), ex);
}
if(!response.isCommitted()) {
response.addHeader("xweb-error-code", Integer.toString(ex.getErrorCode()));
response.sendError(
responseCode > 0 ? responseCode: HttpServletResponse.SC_BAD_REQUEST,
"Error in module: " + api + " Cause: " + ex.getMessage());
}
} catch (Exception ex) {
logger.error("Error in module process. Module: "
+ module.getInfo().getName()
+ " : " + ex.getMessage(), ex);
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Error in module: " + api + " Cause: " + ex.getMessage());
}
} else {