Search in sources :

Example 1 with PageException

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);
        }
    }
}
Also used : PageException(cn.cerc.jbean.core.PageException) ErrorPage(cn.cerc.jmis.page.ErrorPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) Method(java.lang.reflect.Method) JspPage(cn.cerc.jmis.page.JspPage) PageException(cn.cerc.jbean.core.PageException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(cn.cerc.jbean.form.IPage) Webpage(cn.cerc.jmis.form.Webpage) RedirectPage(cn.cerc.jmis.page.RedirectPage)

Aggregations

PageException (cn.cerc.jbean.core.PageException)1 IPage (cn.cerc.jbean.form.IPage)1 Webpage (cn.cerc.jmis.form.Webpage)1 ErrorPage (cn.cerc.jmis.page.ErrorPage)1 JspPage (cn.cerc.jmis.page.JspPage)1 RedirectPage (cn.cerc.jmis.page.RedirectPage)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1