use of cn.cerc.jbean.core.PageException 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