use of cn.cerc.jbean.core.AppConfig 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.jbean.core.AppConfig 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);
}
use of cn.cerc.jbean.core.AppConfig in project summer-mis by cn-cerc.
the class AppLoginPage method init.
@Override
public void init(IForm form) {
this.setForm(form);
AppConfig conf = Application.getAppConfig();
this.setJspFile(conf.getJspLoginFile());
this.add("homePage", conf.getFormWelcome());
this.add("needVerify", "false");
}
use of cn.cerc.jbean.core.AppConfig 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());
}
use of cn.cerc.jbean.core.AppConfig in project summer-mis by cn-cerc.
the class StartForms method getRequestCode.
protected String getRequestCode(HttpServletRequest req) {
String url = null;
String[] args = req.getServletPath().split("/");
if (args.length == 2 || args.length == 3) {
if (args[0].equals("") && !args[1].equals("")) {
if (args.length == 3)
url = args[2];
else {
String sid = (String) req.getAttribute(RequestData.appSession_Key);
AppConfig conf = Application.getAppConfig();
if (sid != null && !"".equals(sid))
url = conf.getFormDefault();
else
url = conf.getFormWelcome();
}
}
}
return url;
}
Aggregations