use of cn.cerc.jmis.page.ErrorPage in project summer-mis by cn-cerc.
the class StartForms method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String uri = req.getRequestURI();
// 遇到静太文件直接输出
if (isStatic(uri)) {
chain.doFilter(req, resp);
return;
}
log.info(uri);
String childCode = getRequestCode(req);
if (childCode == null) {
req.setAttribute("message", "无效的请求:" + childCode);
req.getRequestDispatcher(Application.getAppConfig().getJspErrorFile()).forward(req, resp);
return;
}
String[] params = childCode.split("\\.");
String formId = params[0];
String funcCode = params.length == 1 ? "execute" : params[1];
req.setAttribute("logon", false);
// 验证菜单是否启停
if (Application.containsBean("AppFormFilter")) {
IFormFilter formFilter = Application.getBean("AppFormFilter", IFormFilter.class);
if (formFilter != null) {
if (formFilter.doFilter(resp, formId, funcCode)) {
return;
}
}
}
IForm form = null;
try {
form = createForm(req, resp, formId);
if (form == null) {
req.setAttribute("message", "error servlet:" + req.getServletPath());
AppConfig conf = createConfig();
req.getRequestDispatcher(conf.getJspErrorFile()).forward(req, resp);
return;
}
// 设备讯息
ClientDevice info = new ClientDevice(form);
info.setRequest(req);
req.setAttribute("_showMenu_", !ClientDevice.device_ee.equals(info.getDevice()));
form.setClient(info);
// 建立数据库资源
try (AppHandle handle = createHandle(req)) {
try {
handle.setProperty(Application.sessionId, req.getSession().getId());
handle.setProperty(Application.deviceLanguage, info.getLanguage());
req.setAttribute("myappHandle", handle);
form.setHandle(handle);
log.debug("进行安全检查,若未登录则显示登录对话框");
IAppLogin page = createLogin(form);
if (page.checkSecurity(info.getSid())) {
String corpNo = handle.getCorpNo();
if (null != corpNo && !"".equals(corpNo)) {
String tempStr = String.format("调用菜单: %s(%s), 用户:%s", form.getTitle(), formId, handle.getUserName());
log.info(tempStr);
}
// 进行维护检查,在每月的最后一天晚上11点到下个月的第一天早上5点,不允许使用系统
if (checkEnableTime())
callForm(form, funcCode);
}
} catch (Exception e) {
Throwable err = e.getCause();
if (err == null)
err = e;
req.setAttribute("msg", err.getMessage());
ErrorPage opera = new ErrorPage(form, err);
opera.execute();
}
}
} catch (Exception e) {
log.error(childCode + ":" + e.getMessage());
req.setAttribute("message", e.getMessage());
AppConfig conf = Application.getAppConfig();
req.getRequestDispatcher(conf.getJspErrorFile()).forward(req, resp);
return;
}
}
use of cn.cerc.jmis.page.ErrorPage in project summer-mis by cn-cerc.
the class StartForms method callForm.
// 调用页面控制器指定的函数
protected void callForm(IForm form, String funcCode) throws ServletException, IOException {
HttpServletResponse response = form.getResponse();
HttpServletRequest request = form.getRequest();
if ("excel".equals(funcCode)) {
response.setContentType("application/vnd.ms-excel; charset=UTF-8");
response.addHeader("Content-Disposition", "attachment; filename=excel.csv");
} else
response.setContentType("text/html;charset=UTF-8");
Object pageOutput = "";
String sid = request.getParameter(RequestData.appSession_Key);
if (sid == null || sid.equals(""))
sid = request.getSession().getId();
Method method = null;
long startTime = System.currentTimeMillis();
try {
String CLIENTVER = request.getParameter("CLIENTVER");
if (CLIENTVER != null)
request.getSession().setAttribute("CLIENTVER", CLIENTVER);
// 是否拥有此菜单调用权限
if (!Application.getPassport(form.getHandle()).passForm(form)) {
log.warn(String.format("无权限执行 %s", request.getRequestURL()));
throw new RuntimeException("对不起,您没有权限执行此功能!");
}
// 若是iphone应用商店测试,则跳过设备认证的判断,用于专用测试账号
if (getIphoneAppstoreAccount().equals(request.getParameter("login_usr"))) {
try {
if (form.getClient().isPhone()) {
try {
method = form.getClass().getMethod(funcCode + "_phone");
} catch (NoSuchMethodException e) {
method = form.getClass().getMethod(funcCode);
}
} else
method = form.getClass().getMethod(funcCode);
pageOutput = method.invoke(form);
} catch (PageException e) {
form.setParam("message", e.getMessage());
pageOutput = e.getViewFile();
}
} else {
// 检验此设备是否需要设备验证码
if (form.getHandle().getProperty(Application.userId) == null || form.passDevice() || passDevice(form)) {
try {
if (form.getClient().isPhone()) {
try {
method = form.getClass().getMethod(funcCode + "_phone");
} catch (NoSuchMethodException e) {
method = form.getClass().getMethod(funcCode);
}
} else {
method = form.getClass().getMethod(funcCode);
}
pageOutput = method.invoke(form);
} catch (PageException e) {
form.setParam("message", e.getMessage());
pageOutput = e.getViewFile();
}
} else {
log.debug("没有进行认证过,跳转到设备认证页面");
pageOutput = new RedirectPage(form, Application.getAppConfig().getFormVerifyDevice());
}
}
// 处理返回值
if (pageOutput != null) {
if (pageOutput instanceof IPage) {
IPage output = (IPage) pageOutput;
output.execute();
} else {
log.warn(String.format("%s pageOutput is not IPage: %s", funcCode, pageOutput));
JspPage output = new JspPage(form);
output.setJspFile((String) pageOutput);
output.execute();
}
}
} catch (Exception e) {
Throwable err = e.getCause();
if (err == null)
err = e;
ErrorPage opera = new ErrorPage(form, err);
opera.execute();
} finally {
if (method != null) {
long timeout = 1000;
Webpage webpage = method.getAnnotation(Webpage.class);
if (webpage != null)
timeout = webpage.timeout();
checkTimeout(form, funcCode, startTime, timeout);
}
}
}
Aggregations