Search in sources :

Example 1 with AppHandle

use of cn.cerc.jbean.core.AppHandle 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;
    }
}
Also used : AppConfig(cn.cerc.jbean.core.AppConfig) ErrorPage(cn.cerc.jmis.page.ErrorPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) IForm(cn.cerc.jbean.form.IForm) AppHandle(cn.cerc.jbean.core.AppHandle) PageException(cn.cerc.jbean.core.PageException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) IAppLogin(cn.cerc.jbean.tools.IAppLogin)

Example 2 with AppHandle

use of cn.cerc.jbean.core.AppHandle in project summer-mis by cn-cerc.

the class StartApp method doFilter.

// private static final Logger log = Logger.getLogger(AppStart.class);
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 (uri.equals("/")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        AppConfig conf = Application.getAppConfig();
        resp.sendRedirect(String.format("/%s/%s", conf.getPathForms(), conf.getFormWelcome()));
        return;
    } else if (uri.equals("/MobileConfig")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        try {
            IForm form = Application.getBean("MobileConfig", IForm.class);
            form.setRequest((HttpServletRequest) request);
            form.setResponse((HttpServletResponse) response);
            try (AppHandle handle = new AppHandle()) {
                handle.setProperty(Application.sessionId, req.getSession().getId());
                form.setHandle(handle);
            }
            IPage page = form.execute();
            page.execute();
        } catch (Exception e) {
            resp.getWriter().print(e.getMessage());
        }
        return;
    }
    chain.doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AppConfig(cn.cerc.jbean.core.AppConfig) IPage(cn.cerc.jbean.form.IPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) IForm(cn.cerc.jbean.form.IForm) AppHandle(cn.cerc.jbean.core.AppHandle) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with AppHandle

use of cn.cerc.jbean.core.AppHandle in project summer-bean by cn-cerc.

the class StartServices method doProcess.

private void doProcess(String method, HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException, IOException {
    String uri = req.getRequestURI();
    AppConfig conf = Application.getAppConfig();
    if (!uri.startsWith("/" + conf.getPathServices()))
        return;
    req.setCharacterEncoding("UTF-8");
    resp.setContentType("text/html;charset=UTF-8");
    ResponseData respData = new ResponseData();
    // 将restPath转成service代码
    DataSet dataIn = new DataSet();
    String str = getParams(req);
    if (null != str && !"[{}]".equals(str))
        dataIn.setJSON(str);
    String serviceCode = getServiceCode(method, req.getRequestURI().substring(1), dataIn.getHead());
    log.info(req.getRequestURI() + " => " + serviceCode);
    if (serviceCode == null) {
        respData.setMessage("restful not find: " + req.getRequestURI());
        resp.getWriter().write(respData.toString());
        return;
    }
    log.debug(serviceCode);
    log.info(dataIn);
    try (AppHandle handle = new AppHandle()) {
        // 执行指定函数
        handle.init(req.getParameter("token"));
        handle.setProperty(sessionId, req.getSession().getId());
        IService bean = Application.getService(handle, serviceCode);
        if (bean == null) {
            respData.setMessage(String.format("service(%s) is null.", serviceCode));
            resp.getWriter().write(respData.toString());
            return;
        }
        if (!bean.checkSecurity(handle)) {
            respData.setMessage("请您先登入系统");
            resp.getWriter().write(respData.toString());
            return;
        }
        DataSet dataOut = new DataSet();
        IStatus status = bean.execute(dataIn, dataOut);
        respData.setResult(status.getResult());
        respData.setMessage(status.getMessage());
        respData.setData(bean.getJSON(dataOut));
    } catch (Exception e) {
        Throwable err = e.getCause() != null ? e.getCause() : e;
        log.error(err.getMessage(), err);
        respData.setResult(false);
        respData.setMessage(err.getMessage());
    }
    resp.getWriter().write(respData.toString());
}
Also used : AppConfig(cn.cerc.jbean.core.AppConfig) IStatus(cn.cerc.jbean.core.IStatus) DataSet(cn.cerc.jdb.core.DataSet) AppHandle(cn.cerc.jbean.core.AppHandle) IService(cn.cerc.jbean.core.IService) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with AppHandle

use of cn.cerc.jbean.core.AppHandle in project summer-mis by cn-cerc.

the class YunpianSMS method sendText.

public boolean sendText(String text) {
    // 生成调用参数
    Map<String, String> params = new HashMap<String, String>();
    params.put("apikey", apikey);
    params.put("text", text);
    params.put("mobile", mobile);
    // 编码格式。发送编码格式统一用UTF-8
    String ENCODING = "UTF-8";
    CloseableHttpClient client = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    try {
        HttpPost method = new HttpPost(apiurl);
        if (params != null) {
            List<NameValuePair> paramList = new ArrayList<NameValuePair>();
            for (Map.Entry<String, String> param : params.entrySet()) {
                NameValuePair pair = new BasicNameValuePair(param.getKey(), param.getValue());
                paramList.add(pair);
            }
            method.setEntity(new UrlEncodedFormEntity(paramList, ENCODING));
        }
        response = client.execute(method);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String msg = EntityUtils.toString(entity, ENCODING);
            log.debug("msg: " + msg);
            JSONObject json = JSONObject.fromObject(msg);
            if (json.has("code") && json.getInt("code") == 0) {
                log.info("sendSMS: " + json.getString("msg") + ", " + mobile + "," + text);
                return true;
            } else {
                this.message = json.getString("msg");
                return false;
            }
        } else {
            this.message = R.asString(new AppHandle(), "网络故障,简讯发送请求失败!");
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        this.message = e.getMessage();
        return false;
    } finally {
        try {
            response.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AppHandle(cn.cerc.jbean.core.AppHandle) JSONObject(net.sf.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AppHandle

use of cn.cerc.jbean.core.AppHandle in project summer-mis by cn-cerc.

the class AbstractTask method run.

/**
 * 外部执行入口
 */
public void run() {
    try (AppHandle handle = new AppHandle()) {
        this.setHandle(handle);
        handle.setProperty(Application.userCode, "admin");
        this.execute();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : AppHandle(cn.cerc.jbean.core.AppHandle)

Aggregations

AppHandle (cn.cerc.jbean.core.AppHandle)5 AppConfig (cn.cerc.jbean.core.AppConfig)3 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 IForm (cn.cerc.jbean.form.IForm)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 IService (cn.cerc.jbean.core.IService)1 IStatus (cn.cerc.jbean.core.IStatus)1 PageException (cn.cerc.jbean.core.PageException)1 IPage (cn.cerc.jbean.form.IPage)1 IAppLogin (cn.cerc.jbean.tools.IAppLogin)1 DataSet (cn.cerc.jdb.core.DataSet)1 ErrorPage (cn.cerc.jmis.page.ErrorPage)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (net.sf.json.JSONObject)1 HttpEntity (org.apache.http.HttpEntity)1