use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.
the class UploadSupportUtils method getRealFile.
public static File getRealFile(String uploadOid) throws ServiceException, IOException, Exception {
if (StringUtils.isBlank(uploadOid)) {
throw new Exception("parameter is blank!");
}
SysUploadVO uploadObj = findUpload(uploadOid);
File packageFile = null;
if (!YesNo.YES.equals(uploadObj.getIsFile())) {
File dir = new File(Constants.getWorkTmpDir() + "/" + UploadSupportUtils.class.getSimpleName());
if (!dir.exists() || !dir.isDirectory()) {
FileUtils.forceMkdir(dir);
}
String tmpFileName = dir.getPath() + "/" + SimpleUtils.getUUIDStr() + "." + getFileExtensionName(uploadObj.getShowName());
dir = null;
OutputStream fos = null;
try {
packageFile = new File(tmpFileName);
fos = new FileOutputStream(packageFile);
IOUtils.write(uploadObj.getContent(), fos);
fos.flush();
} catch (IOException e) {
throw e;
} finally {
if (fos != null) {
fos.close();
}
fos = null;
}
} else {
String uploadDir = getUploadFileDir(uploadObj.getSystem(), uploadObj.getSubDir(), uploadObj.getType());
packageFile = new File(uploadDir + "/" + uploadObj.getFileName());
}
if (!packageFile.exists()) {
throw new Exception("File is missing: " + uploadObj.getFileName());
}
return packageFile;
}
use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.
the class HessianServiceProxyAspect method proxyProcess.
private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
String serviceId = AspectConstants.getServiceId(annotations);
/**
* 不需要被遠端代理的 service-bean
*/
if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
//logger.info( "reject proxy service: " + serviceId );
return pjp.proceed();
}
String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
/**
* 沒使用者資訊不能處理遠端代理的 service-bean
*/
if (StringUtils.isBlank(userId)) {
logger.warn("no userId");
pjp.proceed();
}
/**
* 此使用者不能存取遠端代理的 service-bean
*/
if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
return pjp.proceed();
}
}
String serviceInterfacesName = "";
Class<?>[] serviceInterfaces = pjp.getTarget().getClass().getInterfaces();
for (Class<?> clazz : serviceInterfaces) {
if (clazz.getName().indexOf(".service.") > -1) {
serviceInterfacesName = clazz.getName();
}
}
if (StringUtils.isBlank(serviceInterfacesName)) {
logger.error("error no service interface: " + serviceId);
throw new Exception("error no service interface: " + serviceId);
}
String url = GreenStepHessianUtils.getServiceUrl(serviceId);
String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem());
/**
* 不要自己呼叫遠端代理的自己, 會造成 HessianServiceProxyAspect 一直重複觸發 (客戶端與server-remote同一台的情況下)
* 如客戶端是 http://127.0.0.1:8080/
* 但是客戶端有開啟 hessian.enable=Y 呼叫遠端代理, 然後遠端url設定為 hessian.serverUrl=http://127.0.0.1:8080/
*
*/
if (url.indexOf(theSystemPath) > -1) {
logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
}
logger.info("proxy url = " + url);
HessianProxyFactory factory = null;
Object proxyServiceObject = null;
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
// 一般要checkValue模式
factory = new GreenStepHessianProxyFactory();
((GreenStepHessianProxyFactory) factory).setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
proxyServiceObject = ((GreenStepHessianProxyFactory) factory).createForHeaderMode(Class.forName(serviceInterfacesName), url);
} else {
// 不使用checkValue模式
factory = new HessianProxyFactory();
proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
}
Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
Method proxyObjectMethod = null;
if (null == proxyObjectMethods) {
logger.error("error no find proxy method: " + serviceId);
throw new Exception("error no find proxy method: " + serviceId);
}
for (Method m : proxyObjectMethods) {
if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
proxyObjectMethod = m;
}
}
if (null == proxyObjectMethod) {
logger.error("error no execute proxy method: " + serviceId);
throw new Exception("error no execute proxy method: " + serviceId);
}
Object resultObj = null;
try {
resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
} catch (InvocationTargetException e) {
if (e.getMessage() != null) {
throw new ServiceException(e.getMessage().toString());
}
if (e.getTargetException().getMessage() != null) {
throw new ServiceException(e.getTargetException().getMessage().toString());
}
throw e;
} catch (Exception e) {
logger.error(e.getMessage().toString());
throw e;
}
logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
return resultObj;
}
use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.
the class SysUploadServiceImpl method updateTypeOnly.
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> updateTypeOnly(String oid, String type) throws ServiceException, Exception {
if (StringUtils.isBlank(oid) || StringUtils.isBlank(type)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
DefaultResult<Boolean> result = new DefaultResult<Boolean>();
result.setValue(Boolean.FALSE);
if (this.sysUploadDAO.updateTypeOnly(oid, type, this.getAccountId()) == 1) {
result.setValue(Boolean.TRUE);
result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
} else {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_FAIL));
}
return result;
}
use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.
the class SysUploadServiceImpl method findForNoByteContent.
@Override
public DefaultResult<SysUploadVO> findForNoByteContent(String oid) throws ServiceException, Exception {
if (StringUtils.isBlank(oid)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
SysUploadVO upload = this.sysUploadDAO.findForNoByteContent(oid);
DefaultResult<SysUploadVO> result = new DefaultResult<SysUploadVO>();
if (upload != null && !StringUtils.isBlank(upload.getOid())) {
result.setValue(upload);
} else {
result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST)));
}
return result;
}
use of com.netsteadfast.greenstep.base.exception.ServiceException in project bamboobsc by billchen198318.
the class ClearTempDataJobImpl method executeInternal.
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
if (ContextLoader.getCurrentWebApplicationContext() == null) {
log.warn("ApplicationContext no completed, AppContext.getApplicationContext() == null");
return;
}
log.info("begin....");
try {
/**
* document reference:
* com.netsteadfast.greenstep.support.CleanTempUploadForContextInitAndDestroy.java
*/
this.loginForBackgroundProgram();
List<SysVO> systems = ApplicationSiteUtils.getSystems();
if (systems == null || systems.size() < 1) {
return;
}
for (SysVO sys : systems) {
UploadSupportUtils.cleanTempUpload(sys.getSysId());
}
/**
* document reference:
* com.netsteadfast.greenstep.bsc.support.CleanJasperReportTempDataForContextInitAndDestroy.java
*
*/
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
Map<String, Object> paramMap = new HashMap<String, Object>();
namedParameterJdbcTemplate.update("delete from bb_swot_report_mst", paramMap);
namedParameterJdbcTemplate.update("delete from bb_swot_report_dtl", paramMap);
} catch (ServiceException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
this.logoutForBackgroundProgram();
} catch (Exception e) {
e.printStackTrace();
}
}
log.info("end....");
}
Aggregations