use of cn.cerc.jbean.core.IStatus in project summer-bean by cn-cerc.
the class AutoService method exec.
public boolean exec() throws ServiceException, UserNotFindException, ServiceException {
if (service.getService() == null)
throw new RuntimeException("没有指定 service");
handle.init(service.getCorpNo(), service.getUserCode(), "127.0.0.1");
IService bean = Application.getService(this, service.getService());
if (bean == null)
throw new RuntimeException("无法创建服务:" + service.getService());
IStatus status = bean.execute(service.getDataIn(), dataOut);
boolean result = status.getResult();
this.setMessage(status.getMessage());
return result;
}
use of cn.cerc.jbean.core.IStatus in project summer-bean by cn-cerc.
the class LocalService method execute.
// 不带缓存调用服务
public IStatus execute(Object... args) {
if (args.length > 0) {
Record headIn = getDataIn().getHead();
if (args.length % 2 != 0)
return new ServiceStatus(false, "传入的参数数量必须为偶数!");
for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
}
if (handle == null)
return new ServiceStatus(false, "handle is null.");
if (serviceCode == null)
return new ServiceStatus(false, "service is null.");
IService bean = Application.getService(handle, serviceCode);
if (bean == null)
return new ServiceStatus(false, String.format("bean %s not find", serviceCode));
if ((bean instanceof Microservice) && ((Microservice) bean).getService() == null)
((Microservice) bean).setService(serviceCode);
try {
log.info(this.serviceCode);
IStatus status = bean.execute(dataIn, dataOut);
message = status.getMessage();
return status;
} catch (Exception e) {
Throwable err = e;
if (e.getCause() != null)
err = e.getCause();
log.error(err.getMessage(), err);
message = err.getMessage();
return new ServiceStatus(false, message);
}
}
use of cn.cerc.jbean.core.IStatus in project summer-bean by cn-cerc.
the class LocalService method exec.
// 带缓存调用服务
@Override
public boolean exec(Object... args) {
if (args.length > 0) {
Record headIn = getDataIn().getHead();
if (args.length % 2 != 0)
throw new RuntimeException("传入的参数数量必须为偶数!");
for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
}
if (handle == null)
throw new RuntimeException("handle is null.");
if (serviceCode == null)
throw new RuntimeException("service is null.");
IService bean = Application.getService(handle, serviceCode);
if (bean == null) {
this.message = String.format("bean %s not find", serviceCode);
return false;
}
if ((bean instanceof Microservice) && ((Microservice) bean).getService() == null)
((Microservice) bean).setService(serviceCode);
try {
if (!"AppSessionRestore.byUserCode".equals(this.serviceCode))
log.info(this.serviceCode);
if (ServerConfig.getAppLevel() == ServerConfig.appRelease) {
IStatus status = bean.execute(dataIn, dataOut);
boolean result = status.getResult();
message = status.getMessage();
return result;
}
IMemcache buff = Application.getMemcache();
// 制作临时缓存Key
String key = MD5.get(handle.getUserCode() + this.serviceCode + dataIn.getJSON());
if (bufferRead) {
String buffValue = (String) buff.get(key);
if (buffValue != null) {
log.debug("read from buffer: " + this.serviceCode);
dataOut.setJSON(buffValue);
message = dataOut.getHead().getString("_message_");
return dataOut.getHead().getBoolean("_result_");
}
}
// 没有缓存时,直接读取并存入缓存
bean.init(handle);
IStatus status = bean.execute(dataIn, dataOut);
boolean result = status.getResult();
message = status.getMessage();
if (bufferWrite) {
log.debug("write to buffer: " + this.serviceCode);
dataOut.getHead().setField("_message_", message);
dataOut.getHead().setField("_result_", result);
buff.set(key, dataOut.getJSON());
}
return result;
} catch (Exception e) {
Throwable err = e;
if (e.getCause() != null)
err = e.getCause();
log.error(err.getMessage(), err);
message = err.getMessage();
return false;
}
}
use of cn.cerc.jbean.core.IStatus 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());
}
Aggregations