diff --git a/src/main/java/com/nis/restful/DefaultRestErrorResolver.java b/src/main/java/com/nis/restful/DefaultRestErrorResolver.java
index 9256b41..bb7c52f 100644
--- a/src/main/java/com/nis/restful/DefaultRestErrorResolver.java
+++ b/src/main/java/com/nis/restful/DefaultRestErrorResolver.java
@@ -47,6 +47,12 @@ public class DefaultRestErrorResolver implements RestErrorResolver,InitializingB
error.setTraceCode(((RestServiceException) ex).getTraceCode());
int errorCode = ((RestServiceException) ex).getErrorCode();
error.setBusinessCode(RestBusinessCode.valueOf(errorCode));
+ } else if(ex instanceof ServiceRuntimeException){
+ //获取日志源[只有日志需要返回日志源和ActiveSys]
+ int logSource = ((ServiceRuntimeException) ex).getLogSource();
+ error.setTraceCode(((ServiceRuntimeException) ex).getTraceCode());
+ int errorCode = ((ServiceRuntimeException) ex).getErrorCode();
+ error.setBusinessCode(RestBusinessCode.valueOf(errorCode));
} else {
error.setBusinessCode(RestBusinessCode.valueOf(998));
}
diff --git a/src/main/java/com/nis/restful/RestBusinessCode.java b/src/main/java/com/nis/restful/RestBusinessCode.java
index de4fded..dd3661b 100644
--- a/src/main/java/com/nis/restful/RestBusinessCode.java
+++ b/src/main/java/com/nis/restful/RestBusinessCode.java
@@ -448,7 +448,135 @@ public enum RestBusinessCode {
*/
ValueInWrongRegexp(4002605,"属性值与正则表达式不匹配"),
+ /**
+ * isValid属性格式不正确
+ */
IsValidInWrongRange(4002606,"isValid属性格式不正确"),
+
+ /**
+ * 回调类配置请求参数格式不正确
+ */
+ CBParamFormateError(4002607,"回调类配置请求参数格式不正确"),
+
+ //服务内部异常业务码
+ /**
+ * 回调类配置Service不存在或未配置tableName
+ */
+ CBServiceOrTableNameNotFound(5001001,"回调类配置Service不存在或未配置tableName"),
+ /**
+ * service与写入数据库序号映射关系不存在
+ */
+ ServiceNoFoundDBIndex(5001002,"service与写入数据库序号映射关系不存在"),
+
+ /**
+ * 向服务器上传文件失败
+ */
+ FileUploadFailure(5001003,"向服务器上传文件失败"),
+
+ /**
+ * FastDfs文件服务器出现异常
+ */
+ FastDfsServerException(5001004,"FastDfs文件服务器出现异常"),
+ /**
+ * 摘要获取失败
+ */
+ GetFileDigestFailure(5001005,"摘要获取失败"),
+
+ /**
+ * Redis数据库编号不在有效范围内
+ */
+ DbIndexNotInRange(5002001,"Redis数据库编号不在有效范围内"),
+
+ /**
+ * 配置信息不能为空
+ */
+ ConfigSourceIsNull(5002002,"配置信息不能为空"),
+
+ /**
+ * 无法连接Redis数据库
+ */
+ CannotConnectionRedis(5002003,"无法连接Redis数据库"),
+
+ /**
+ * 向Redis数据库保存配置时发生错误
+ */
+ SaveDataInError(5002004,"向Redis数据库保存配置时发生错误"),
+
+ /**
+ * key在Redis中不存在
+ */
+ KeyNotExistsInRedis(5002005,"key在Redis中不存在"),
+
+ /**
+ * 删除Redis数据库中配置时发生错误
+ */
+ DeleteDataInError(5002006,"删除Redis数据库中配置时发生错误"),
+
+ /**
+ * 向Redis数据库中设置值失败
+ */
+ ZsetFailed(5002007,"向Redis数据库中设置值失败"),
+
+ /**
+ * redisTemplate为空
+ */
+ RedisTemplateIsNull(5002008,"redisTemplate为空"),
+
+ /**
+ * 判断key是否存在失败
+ */
+ ExistsKeyFailed(5002008,"判断key是否存在失败"),
+
+ /**
+ * 无法从Map中获取配置的属性值
+ */
+ GetMaatVersionFailure(5003001,"无法从Map中获取配置的属性值"),
+
+ /**
+ * 在配置文件中未找到service对应的表名
+ */
+ NotFoundTableName(5003002,"未找到service对应的表名"),
+
+ /**
+ * 在配置文件中未找到service对应的Redis入库规则
+ */
+ NotFoundRedisRule(5003003,"未找到service对应的Redis入库规则"),
+ /**
+ * Redis数据库中MAAT配置的对应关系不存在
+ */
+ RelationNotExistsInRedis(5003004,"Redis数据库中MAAT配置的对应关系不存在"),
+
+ /**
+ * Map中缺少编译配置信息
+ */
+ NotFoundCompileInfo(5004001,"Map中缺少编译配置信息"),
+
+ /**
+ * Map中缺少分组配置信息
+ */
+ NotFoundGroupInfo(5004002,"Map中缺少分组配置信息"),
+
+ /**
+ * 无法从Map中获取配置的属性值
+ */
+ NotFoundValueByKey(5004003,"无法从Map中获取配置的属性值"),
+
+ /**
+ * 状态更新操作中service与配置ID的应对关系不能为空
+ */
+ ServiceAndCompileMapIsNull(5004004,"状态更新操作中service与配置Id的应对关系不能为空"),
+
+ /**
+ * 状态更新操作中与service对应的配置Id列表不能为空
+ */
+ CompileIdListIsNull(5004005,"状态更新操作中与service对应的配置Id列表不能为空"),
+
+ /**
+ * 状态更新操作中更新内容Map不能为空
+ */
+ ConfigInfoMapIsNull(5004005,"状态更新操作中更新内容Map不能为空"),
+
+
;
@@ -463,13 +591,6 @@ public enum RestBusinessCode {
-
-
-
-
-
-
-
private final int value; //错误码
private final String errorReason; //错误原因
diff --git a/src/main/java/com/nis/restful/ServiceRuntimeException.java b/src/main/java/com/nis/restful/ServiceRuntimeException.java
new file mode 100644
index 0000000..c0f2995
--- /dev/null
+++ b/src/main/java/com/nis/restful/ServiceRuntimeException.java
@@ -0,0 +1,74 @@
+package com.nis.restful;
+
+import com.nis.web.service.AuditLogThread;
+import org.springframework.util.StringUtils;
+
+public class ServiceRuntimeException extends RuntimeException{
+
+ private static final long serialVersionUID = -4340771633400022100L;
+
+ private int errorCode;
+
+ private int logSource;
+
+ private String traceCode;
+
+ public ServiceRuntimeException(){
+ }
+
+ public ServiceRuntimeException(AuditLogThread thread, long time, String message) {
+ super(message);
+ this.errorCode = RestBusinessCode.unknow_error.getValue(); //未知错误
+ this.traceCode = thread.getTraceCode();
+ thread.setConsumerTime(time);
+ thread.setBusinessCode(this.getErrorCode());
+ if(StringUtils.isEmpty(thread.getExceptionInfo())) {
+ thread.setExceptionInfo(message);
+ }
+
+ new Thread(thread).start();
+ }
+
+ public ServiceRuntimeException(String message,int errorCode) {
+ super(message);
+ this.errorCode = errorCode;
+ }
+ public ServiceRuntimeException(AuditLogThread thread, long time, String message, int errorCode) {
+ super(message);
+ this.errorCode = errorCode;
+ this.traceCode = thread.getTraceCode();
+ thread.setConsumerTime(time);
+ thread.setBusinessCode(this.getErrorCode());
+ if(StringUtils.isEmpty(thread.getExceptionInfo())) {
+ thread.setExceptionInfo(message);
+ }
+
+ new Thread(thread).start();
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public int getLogSource() {
+ return logSource;
+ }
+
+ public void setLogSource(int logSource) {
+ this.logSource = logSource;
+ }
+
+ public String getTraceCode() {
+ return traceCode;
+ }
+
+ public void setTraceCode(String traceCode) {
+ this.traceCode = traceCode;
+ }
+
+}
diff --git a/src/main/java/com/nis/util/JedisUtils.java b/src/main/java/com/nis/util/JedisUtils.java
index 2baf23e..36bb6be 100644
--- a/src/main/java/com/nis/util/JedisUtils.java
+++ b/src/main/java/com/nis/util/JedisUtils.java
@@ -5,13 +5,15 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Lists;
-import com.nis.web.service.SpringContextHolder;
-
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisException;
+import com.google.common.collect.Lists;
+import com.nis.restful.RestBusinessCode;
+import com.nis.restful.ServiceRuntimeException;
+import com.nis.web.service.SpringContextHolder;
+
public class JedisUtils {
private static Logger logger = LoggerFactory.getLogger(JedisUtils.class);
private static JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class);
@@ -32,7 +34,7 @@ public class JedisUtils {
logger.debug("get {} = {}", key, value);
}
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中获取" + key + "对应的值失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
} finally {
returnResource(jedis);
}
@@ -54,7 +56,7 @@ public class JedisUtils {
logger.debug("getObject {} = {}", key, value);
}
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中获取" + key + "对应的值失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
} finally {
returnResource(jedis);
}
@@ -95,7 +97,7 @@ public class JedisUtils {
}
logger.debug("set {} = {}", key, value);
} catch (Exception e) {
- throw new RuntimeException("后台错误:向" + redisDb + "号redisDB中设置zset失败,key=" + key + ",value=" + value, e);
+ throw new ServiceRuntimeException("向" + redisDb + "号redisDB中设置zset失败,key=" + key + ",value=" + value, RestBusinessCode.ZsetFailed.getValue());
} finally {
returnResource(jedis);
}
@@ -117,7 +119,7 @@ public class JedisUtils {
logger.debug("getList {} = {}", key, value);
}
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中获取" + key + "对应的值失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
} finally {
returnResource(jedis);
}
@@ -143,7 +145,7 @@ public class JedisUtils {
logger.debug("getObjectList {} = {}", key, value);
}
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中获取" + key + "对应的值失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
} finally {
returnResource(jedis);
}
@@ -163,7 +165,7 @@ public class JedisUtils {
result = jedis.exists(key);
logger.debug("exists {}", key);
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中判断" + key + "是否存在失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败", RestBusinessCode.ExistsKeyFailed.getValue());
} finally {
returnResource(jedis);
}
@@ -183,7 +185,7 @@ public class JedisUtils {
result = jedis.exists(getBytesKey(key));
logger.debug("existsObject {}", key);
} catch (Exception e) {
- throw new RuntimeException("后台错误:从" + redisDb + "号redisDB中判断" + key + "是否存在失败", e);
+ throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败", RestBusinessCode.ExistsKeyFailed.getValue());
} finally {
returnResource(jedis);
}
@@ -198,14 +200,14 @@ public class JedisUtils {
public static Jedis getResource(int redisDb) throws JedisException {
Jedis jedis = null;
if (jedisPool == null) {
- throw new RuntimeException("后台错误:redis连接池为空,请联系管理员检查程序");
+ throw new ServiceRuntimeException("redis连接池为空,请联系管理员检查程序",RestBusinessCode.CannotConnectionRedis.getValue());
}
try {
jedis = jedisPool.getResource();
jedis.select(redisDb);
} catch (JedisException e) {
returnBrokenResource(jedis);
- throw new RuntimeException("后台错误:获取redis连接失败,请联系管理员检查程序", e);
+ throw new ServiceRuntimeException("获取redis连接失败,请联系管理员检查程序", RestBusinessCode.CannotConnectionRedis.getValue());
}
return jedis;
diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java
index 67837cb..48992de 100644
--- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java
+++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java
@@ -9,9 +9,10 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
import com.nis.domain.MaatXmlExpr;
+import com.nis.restful.RestBusinessCode;
+import com.nis.restful.ServiceRuntimeException;
/**
*
@@ -257,7 +258,7 @@ public class ServiceAndRDBIndexReal {
if (tableName == null || tableName.trim().equals("")) {
if (tableList.size() > 1) {
logger.error("未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名", service, type, tableName);
- throw new RuntimeException("业务类型:" + service + ",配置类型:" + type + "对应多个表,请输入具体的表名");
+ throw new ServiceRuntimeException("在applicationConfig-rule.properties配置文件中,业务类型:" + service + ",配置类型:" + type + "对应多个表,请输入具体的表名",RestBusinessCode.NotFoundTableName.getValue());
} else {
return tableList.get(0);
}
@@ -274,8 +275,10 @@ public class ServiceAndRDBIndexReal {
return tableList.get(index);
} else {
logger.error("未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名", service, type, tableName);
- throw new RuntimeException(
- "后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + "表名:" + tableName + "对应的真实表名");
+ throw new ServiceRuntimeException(
+ "无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为" + service+ ",配置类型:" + type
+ + "对应的真实表名",RestBusinessCode.NotFoundTableName.getValue());
+
}
}
diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java
index 83a6c2f..25a94ec 100644
--- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java
+++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java
@@ -24,6 +24,7 @@ import com.nis.domain.restful.ConfigSource;
import com.nis.domain.restful.FileDesc;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
+import com.nis.restful.ServiceRuntimeException;
import com.nis.util.CompileVal;
import com.nis.util.Constants;
import com.nis.util.FileUtils;
@@ -86,8 +87,14 @@ public class ConfigSourcesController extends BaseRestController {
if ("error".equals(msg)) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "Maat 规则存储异常" + exception.getMessage(), CompileVal.getBusinessCode());
+ if (exception instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ "Maat 规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }else{
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ "Maat 规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }
+
}
} else {
thread.setExceptionInfo("Maat规则不能为空");
@@ -125,8 +132,14 @@ public class ConfigSourcesController extends BaseRestController {
if (msg.equals("error")) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "MAAT规则状态更新时出现异常" + exception.getMessage(),CompileVal.getBusinessCode());
+ if (exception instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ "MAAT规则状态更新时出现异常:" + exception.getMessage(),CompileVal.getBusinessCode());
+ }else {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ "MAAT规则状态更新时出现异常:" + exception.getMessage(),CompileVal.getBusinessCode());
+ }
+
}
// configSourcesService.updateConfigSource(thread, start,
// configSource.getConfigCompileList(),
@@ -248,7 +261,7 @@ public class ConfigSourcesController extends BaseRestController {
} else {
thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
}
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
throwExceptionInfo.get(errorNum), errorNum);
}
@@ -303,8 +316,14 @@ public class ConfigSourcesController extends BaseRestController {
String msg = configSourcesService.saveCommonSources(thread, start, jsonString);
if (msg.equals("error")) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "回调规则存储异常" + exception.getMessage(), CompileVal.getBusinessCode());
+ if (exception instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ "回调规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }else {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ "回调规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }
+
}
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则下发成功",
Constants.IS_DEBUG ? jsonString : null);
@@ -312,7 +331,7 @@ public class ConfigSourcesController extends BaseRestController {
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT)
- @ApiOperation(value = "回调规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收回调规则,对其状态置为失效")
+ @ApiOperation(value = "回调(通用)规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收回调规则,对其状态置为失效")
public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) {
CompileVal.setBusinessCode(null);
@@ -324,8 +343,13 @@ public class ConfigSourcesController extends BaseRestController {
String msg = configSourcesService.updateCommonSources(thread, start, jsonString, new Date(), sb);
if (msg.equals("error")) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "回调规则状态更新异常" + exception.getMessage(), CompileVal.getBusinessCode());
+ if (exception instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ "回调规则状态更新异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }else {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ "回调规则状态更新异常:" + exception.getMessage(), CompileVal.getBusinessCode());
+ }
}
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则状态更新成功",
Constants.IS_DEBUG ? jsonString : null);
@@ -374,20 +398,23 @@ public class ConfigSourcesController extends BaseRestController {
}
}catch (IOException e) {
// TODO Auto-generated catch block
- logger.error("文件上传异常:"+e.getMessage());
- Exception exception = new RuntimeException(
- "文件上传异常:"+e.getMessage());
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "文件上传异常:" + exception.getMessage(), RestBusinessCode.service_runtime_error.getValue());
+ logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage());
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
}catch (Exception e) {
// TODO: handle exception
logger.error(e.getMessage());
- CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue());
- if (e.getMessage().startsWith("后台错误:")) {
- CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
+ if (e instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), ((RestServiceException) e).getErrorCode());
+ }else if (e instanceof ServiceRuntimeException) {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
+ }else {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
}
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- e.getMessage(), CompileVal.getBusinessCode());
+
}
JSONObject jsonObj = new JSONObject();
// jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
@@ -436,22 +463,25 @@ public class ConfigSourcesController extends BaseRestController {
// resultObject.put("path", filePath.substring(filePath.indexOf("group")));
resultObject.put("accessUrl", filePath);
}
- } catch (IOException e) {
+ }catch (IOException e) {
// TODO Auto-generated catch block
- logger.error("文件上传异常:"+e.getMessage());
- Exception exception = new RuntimeException(
- "文件上传异常:"+e.getMessage());
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- "文件上传异常:" + exception.getMessage(), RestBusinessCode.service_runtime_error.getValue());
+ logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage());
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
}catch (Exception e) {
// TODO: handle exception
logger.error(e.getMessage());
- CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue());
- if (e.getMessage().startsWith("后台错误:")) {
- CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
+ if (e instanceof RestServiceException) {
+ throw new RestServiceException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), ((RestServiceException) e).getErrorCode());
+ }else if (e instanceof ServiceRuntimeException) {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
+ }else {
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
}
- throw new RestServiceException(thread, System.currentTimeMillis() - start,
- e.getMessage(), CompileVal.getBusinessCode());
+
}
try {
String tempFilePath = request.getRealPath(File.separator) + "upload" + File.separator
@@ -467,10 +497,10 @@ public class ConfigSourcesController extends BaseRestController {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
- logger.error("摘要获取过程中出现异常");
- thread.setExceptionInfo("摘要获取过程中出现异常");
- throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常",
- RestBusinessCode.unknow_error.getValue());
+ logger.error(RestBusinessCode.GetFileDigestFailure.getValue()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功");
+// thread.setExceptionInfo("摘要获取过程中出现异常");
+ throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, RestBusinessCode.GetFileDigestFailure.getValue()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功",
+ RestBusinessCode.GetFileDigestFailure.getValue());
}
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject);
}
diff --git a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java
index 02d0496..be01be9 100644
--- a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java
+++ b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java
@@ -4,6 +4,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
+import com.nis.restful.RestBusinessCode;
+import com.nis.restful.ServiceRuntimeException;
import com.nis.web.service.SpringContextHolder;
public class BaseRedisDao {
@@ -43,7 +45,7 @@ public class BaseRedisDao {
}
return hasKey;
} else {
- throw new RuntimeException("后台错误:从" + index + "号redis库中判断" + key + "是否存在时失败,失败原因:redisTemplate为null请联系开发人员");
+ throw new ServiceRuntimeException("从" + index + "号redis库中判断" + key + "是否存在时失败,失败原因:redisTemplate为null请联系开发人员",RestBusinessCode.RedisTemplateIsNull.getValue());
}
}
@@ -60,7 +62,7 @@ public class BaseRedisDao {
Long id = redisTemplate.boundValueOps(key.toUpperCase()).increment(1l);
return id;
} else {
- throw new RuntimeException("后台错误:从" + index + "号redis库中获取" + key + "的自增长值时失败,失败原因:redisTemplate为null请联系开发人员");
+ throw new ServiceRuntimeException("从" + index + "号redis库中获取" + key + "的自增长值时失败,失败原因:redisTemplate为null请联系开发人员",RestBusinessCode.RedisTemplateIsNull.getValue());
}
}
@@ -70,7 +72,7 @@ public class BaseRedisDao {
redisTemplate.setEnableTransactionSupport(false);
return redisTemplate.opsForValue().get(key);
} else {
- throw new RuntimeException("后台错误:从" + index + "号redis库中获取" + key + "的值时失败,失败原因:redisTemplate为null请联系开发人员");
+ throw new ServiceRuntimeException("从" + index + "号redis库中获取" + key + "的值时失败,失败原因:redisTemplate为null请联系开发人员",RestBusinessCode.RedisTemplateIsNull.getValue());
}
}
diff --git a/src/main/java/com/nis/web/service/fdfs/FileManager.java b/src/main/java/com/nis/web/service/fdfs/FileManager.java
index 7084971..5180286 100644
--- a/src/main/java/com/nis/web/service/fdfs/FileManager.java
+++ b/src/main/java/com/nis/web/service/fdfs/FileManager.java
@@ -15,6 +15,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import com.nis.restful.RestBusinessCode;
+import com.nis.restful.ServiceRuntimeException;
+
/**
*
Title: FileManager.java
// * Description: 上传文件到fdfs的工具类
@@ -43,7 +46,7 @@ public class FileManager extends FileManagerConfig {
storageClient = new StorageClient(trackerServer, storageServer);
} catch (Exception e) {
logger.error("创建tracker|storage失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常", e);
- throw new RuntimeException("后台错误:创建tracker|storage失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常", e);
+ throw new ServiceRuntimeException("创建tracker|storage失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常",RestBusinessCode.FastDfsServerException.getValue());
}
}
@@ -67,9 +70,9 @@ public class FileManager extends FileManagerConfig {
+ SEPARATOR + groupName + SEPARATOR + remoteFileName;
return fileAbsolutePath;
} catch (Exception e) {
- logger.error("上传文件{}到fastfds服务器失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常", file.getName(), e);
- throw new RuntimeException("后台错误:上传文件" + file.getName() + "到fastfds服务器失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
- e);
+ logger.error("上传文件到fastfds服务器失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常", file.getName(), e);
+ throw new ServiceRuntimeException("上传文件" + file.getName() + "到fastfds服务器失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
+ RestBusinessCode.FastDfsServerException.getValue());
}
}
@@ -90,8 +93,8 @@ public class FileManager extends FileManagerConfig {
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
} catch (Exception e) {
logger.error("从fastfds服务器下载文件{}失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常", remoteFileName, e);
- throw new RuntimeException("后台错误:从fastfds服务器下载文件" + remoteFileName + "失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
- e);
+ throw new ServiceRuntimeException("从fastfds服务器下载文件" + remoteFileName + "失败,请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
+ RestBusinessCode.FastDfsServerException.getValue());
}
return new ResponseEntity(content, headers, HttpStatus.CREATED);
}
@@ -108,8 +111,8 @@ public class FileManager extends FileManagerConfig {
result = storageClient.delete_file(group, filePath);
} catch (Exception e) {
logger.error("删除文件:{}失败,所属组:{},请检查fdfs配置文件或fdfs服务,nginx服务是否正常", filePath, group, e);
- throw new RuntimeException("后台错误:删除文件:" + filePath + "失败,所属组:" + group + ",请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
- e);
+ throw new ServiceRuntimeException("删除文件:" + filePath + "失败,所属组:" + group + ",请检查fdfs配置文件或fdfs服务,nginx服务是否正常",
+ RestBusinessCode.FastDfsServerException.getValue());
}
return result;
diff --git a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java
index 0d36189..57d6524 100644
--- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java
+++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java
@@ -13,19 +13,21 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.Transaction;
+import redis.clients.jedis.exceptions.JedisConnectionException;
+
import com.nis.domain.MaatXmlConfig;
import com.nis.domain.MaatXmlExpr;
import com.nis.domain.MaatXmlSeq;
import com.nis.domain.restful.MaatConfig;
+import com.nis.restful.RestBusinessCode;
+import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Configurations;
import com.nis.util.JedisUtils;
import com.nis.util.ReadMaatXmlUtil;
import com.nis.util.ServiceAndRDBIndexReal;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.Transaction;
-import redis.clients.jedis.exceptions.JedisConnectionException;
-
@Service()
public class ConfigJedisServiceimpl implements ConfigRedisService {
private static Logger logger = LoggerFactory.getLogger(ConfigJedisServiceimpl.class);
@@ -70,9 +72,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal
.getUnMaatTableName(service);
if (maatTableName == null) {
- throw new RuntimeException(
- "未从业务类型和表对应关系中,找到非maat配置业务类型:" + service
- + "对应的真实表名");
+ throw new ServiceRuntimeException(
+ "无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为" + service
+ + "对应的真实表名",RestBusinessCode.NotFoundTableName.getValue());
} else {
keyBF.append(maatTableName);
}
@@ -145,8 +147,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
} else {
- throw new RuntimeException(
- "无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
+ throw new ServiceRuntimeException(
+ "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",RestBusinessCode.NotFoundRedisRule.getValue());
}
}
transaction.incrBy("MAAT_VERSION", 1l);
@@ -155,10 +157,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
count++;
}
} else {
- throw new RuntimeException("向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
+ throw new ServiceRuntimeException("向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
} else {
- throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
+ throw new ServiceRuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号",RestBusinessCode.DbIndexNotInRange.getValue());
}
}
if (count == configMap.size()) {
@@ -168,20 +170,21 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.discard();
}
} catch (JedisConnectionException e) {
- String error = "后台错误:连接redis异常,保存非maat类配置失败," + e.getMessage();
- logger.error(error);
- throw new RuntimeException(error, e);
+ String error = "连接redis异常,保存非maat类配置失败," + e.getMessage();
+// logger.error(error);
+ throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
+
} catch (Exception e) {
transaction.discard();
- String error = "后台错误:保存非maat类配置发生了异常," + e.getMessage();
- logger.error(error);
- throw new RuntimeException(error, e);
+ String error = "保存非maat类配置发生了异常," + e.getMessage();
+// logger.error(error);
+ throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
} finally {
// 释放连接到连接池
JedisUtils.returnResource(resource);
}
} else {
- throw new RuntimeException("后台错误:参数不能为空");
+ throw new ServiceRuntimeException("向redis库添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
return false;
}
@@ -289,11 +292,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
} else {
- throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
+ throw new ServiceRuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号",RestBusinessCode.DbIndexNotInRange.getValue());
}
}
} else {
- throw new RuntimeException("参数不能为空");
+ throw new ServiceRuntimeException("向redis库中配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
@@ -338,8 +341,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
if (keyVal != null && !keyVal.equals("")) {
keyBF.append(keyVal);
} else {
- throw new RuntimeException(
- "未从map中获取到" + keyStr + "的值,无法拼接redisKey,请检查数据是否正确");
+ throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确",RestBusinessCode.NotFoundValueByKey.getValue());
}
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
keyStr = keyStr.trim().replace("{", "").replace("}", "");
@@ -348,8 +350,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(
service, 10, argTableName == null ? null : argTableName);
if (maatTableName == null) {
- throw new RuntimeException(
- "未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:10,对应的真实表名");
+ throw new ServiceRuntimeException(
+ "无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为" + service
+ + ",配置类型:10,对应的真实表名",RestBusinessCode.NotFoundTableName.getValue());
} else {
keyBF.append(maatTableName);
}
@@ -372,8 +375,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
// if (!valStr.toLowerCase().equals("service")&&!
// valStr.toLowerCase().equals("action")
// &&!valStr.toLowerCase().equals("user_region") &&type==10) {
- throw new RuntimeException(
- "未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
+ throw new ServiceRuntimeException("未从map中获取到" + valStr + "的值,请检查数据或配置文件是否正确",RestBusinessCode.NotFoundValueByKey.getValue());
}
} else if (valStr.equals("\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
@@ -397,12 +399,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.incrBy("MAAT_VERSION", 1l);
}
} else {
- throw new RuntimeException(
- "向" + redisStatisticsRealDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
+ throw new ServiceRuntimeException(
+ "向" + redisStatisticsRealDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
} else {
- throw new RuntimeException("redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号");
+ throw new ServiceRuntimeException("redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号",RestBusinessCode.DbIndexNotInRange.getValue());
}
break;// configMap中所有的value都是相同的,在记录配置新增或者取消时只记录一次即可
}
@@ -436,8 +438,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type,
argTableName == null ? null : argTableName);
if (maatTableName == null) {
- throw new RuntimeException(
- "未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
+ throw new ServiceRuntimeException("无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为"+ service + ",配置类型:" + type +
+ ",对应的真实表名",RestBusinessCode.NotFoundTableName.getValue());
} else {
keyBF.append(maatTableName);
}
@@ -496,11 +498,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
- throw new RuntimeException("向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
+ throw new ServiceRuntimeException("向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
} else {
- throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
+ throw new ServiceRuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号",RestBusinessCode.DbIndexNotInRange.getValue());
}
}
if (count == configMap.size()) {
@@ -512,20 +514,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.exec();
}
} catch (JedisConnectionException e) {
- String error = "后台错误:连接redis异常,保存maat类配置失败" + e.getMessage();
+ String error = "连接redis异常,保存maat类配置失败" + e.getMessage();
logger.error(error);
- throw new RuntimeException(error, e);
+ throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
} catch (Exception e) {
transaction.discard();
- String error = "后台错误:保存maat类配置发生了异常" + e.getMessage();
+ String error = "保存maat类配置发生了异常" + e.getMessage();
logger.error(error);
- throw new RuntimeException(error, e);
+ throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
} finally {
// 释放连接到连接池
JedisUtils.returnResource(resource);
}
} else {
- throw new RuntimeException("后台错误:参数不能为空");
+ throw new ServiceRuntimeException("写入Redis数据库中的配置信息不能为空",RestBusinessCode.ConfigSourceIsNull.getValue());
}
return false;
@@ -548,7 +550,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service, transaction,
redisDBIndex, null);// 10代表是编译配置
} else {
- throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的编译配置信息,请检查配置参数是否正确");
+ throw new ServiceRuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的编译配置信息,请检查配置参数是否正确",RestBusinessCode.NotFoundCompileInfo.getValue());
}
List