数据格式异常时status码设置为400,服务异常时status码设置为500,并细化服务异常业务状态码

This commit is contained in:
zhangdongxu
2018-08-03 18:08:46 +08:00
parent 4a353a3975
commit 0a10522bae
11 changed files with 498 additions and 263 deletions

View File

@@ -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));
}

View File

@@ -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; //错误原因

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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());
}
}

View File

@@ -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);
if (exception instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"Maat 规则存储异常" + exception.getMessage(), CompileVal.getBusinessCode());
"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);
if (exception instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"MAAT规则状态更新时出现异常" + exception.getMessage(),CompileVal.getBusinessCode());
"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);
if (exception instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则存储异常" + exception.getMessage(), CompileVal.getBusinessCode());
"回调规则存储异常:" + 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);
if (exception instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则状态更新异常" + exception.getMessage(), CompileVal.getBusinessCode());
"回调规则状态更新异常:" + 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(), CompileVal.getBusinessCode());
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());
}
}
JSONObject jsonObj = new JSONObject();
// jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
@@ -438,20 +465,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(), CompileVal.getBusinessCode());
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());
}
}
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);
}

View File

@@ -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());
}
}

View File

@@ -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;
/**
* <p>Title: FileManager.java</p>
// * <p>Description: 上传文件到fdfs的工具类</p>
@@ -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<byte[]>(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;

View File

@@ -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<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
@@ -558,7 +560,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
compileId);// 11代表是分组配置
}
} else {
throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确");
throw new ServiceRuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确",RestBusinessCode.NotFoundGroupInfo.getValue());
}
List<Map<String, String>> ipRegionMapList = maatConfig.getIpRegionMapList();
@@ -641,7 +643,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());
}
if (type == 11 && keyStr.toLowerCase().equals("group_id")) {
keyBF.append(compileId);
@@ -653,8 +655,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);
}
@@ -703,7 +705,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
valBF.append(val);
} else {
// 所有在maat.xml中配置的属性都不可以为空
throw new RuntimeException("未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
throw new ServiceRuntimeException("未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确",RestBusinessCode.NotFoundValueByKey.getValue());
}
} else if (valStr.equals("&nbsp")) {
valBF.append(" ");
@@ -748,9 +750,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
} else {
if (maatXmlConfig == null) {
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则,请检查maat.xml");
throw new ServiceRuntimeException(
"无法从applicationConfig-maatRedis.xml配置文件中,获取service为" + service + "对应的规则,请检查业务类型是否正确",RestBusinessCode.NotFoundRedisRule.getValue());
} else {
throw new RuntimeException("后台组装的配置信息有误,请联系管理员检查");
throw new ServiceRuntimeException("向redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
}
@@ -775,8 +778,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDBIndex);
if (maatVersionStr == null) {
throw new RuntimeException("" + redisDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException("" + redisDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",RestBusinessCode.GetMaatVersionFailure.getValue());
}
if (maatVersionStr != null) {
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
@@ -814,9 +817,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);
}
@@ -842,8 +845,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
maatKey.toString().toUpperCase());
break;
} else {
throw new RuntimeException(redisDBIndex + "号redis库中不存在key="
+ oldKey + "请检查id映射关系是否正确");
throw new ServiceRuntimeException(redisDBIndex + "号redis库中不存在key="
+ oldKey + "请检查id映射关系是否正确",RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
}
@@ -898,8 +901,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);
@@ -908,14 +911,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service
+ "的配置id信息,请检查配置参数是否正确");
throw new ServiceRuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service
+ "的配置id信息,请检查配置参数是否正确",RestBusinessCode.CompileIdListIsNull.getValue());
}
}
}
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
throw new ServiceRuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ServiceAndCompileMapIsNull.getValue());
}
}
@@ -926,20 +929,20 @@ 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.DeleteDataInError.getValue());
} finally {
// 释放连接到连接池
JedisUtils.returnResource(resource);
}
} else {
throw new RuntimeException("后台错误:参数信息有误,请检查!");
throw new ServiceRuntimeException("状态更新操作Map参数信息不能为空,请检查!",RestBusinessCode.ConfigInfoMapIsNull.getValue());
}
return false;
}
@@ -953,14 +956,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
try {
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
for (Integer redisDBIndex : idMap.keySet()) {
//按序号选择Redis数据库
transaction.select(redisDBIndex);
Map<Integer, List<Long>> serviceConfigMap = idMap.get(redisDBIndex);
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDBIndex);
if (maatVersionStr == null) {
throw new RuntimeException("" + redisDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
}
if (maatVersionStr != null) {
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
for (Integer service : serviceConfigMap.keySet()) {
@@ -973,9 +973,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1);
count++;
}else{
throw new ServiceRuntimeException("" + redisDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",RestBusinessCode.GetMaatVersionFailure.getValue());
}
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
throw new ServiceRuntimeException("" + redisDBIndex + "号redis库删除配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
if (count == idMap.size()) {
@@ -988,20 +991,25 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
} 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);
// logger.error(error);
int businessCode = RestBusinessCode.service_runtime_error.getValue();
if (e instanceof ServiceRuntimeException) {
businessCode = ((ServiceRuntimeException) e).getErrorCode();
}
throw new ServiceRuntimeException("删除maat配置发生了异常,"+ e.getMessage(),businessCode);
} finally {
// 释放连接到连接池
JedisUtils.returnResource(resource);
}
} else {
throw new RuntimeException("后台错误:参数信息有误,请检查!");
throw new ServiceRuntimeException("Map参数信息不能为空,请检查!",RestBusinessCode.ConfigInfoMapIsNull.getValue());
}
return false;
}
@@ -1020,10 +1028,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
if (idList != null && idList.size() > 0 && maatXmlConfig != null) {
for (Long id : idList) {
//删除(重命名)编译配置
removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion.doubleValue(), service, transaction,
redisDBIndex, null);// 10代表是编译配置
//拼接编译与分组关系的Redis Key
String compileStr = redisDBIndex + ":COMPILEGROUP:" + id;
// 获取当前编译下所有的分组id
//获取当前编译配置与分组配置的关联关系
String groupCompileStrs = JedisUtils.get(compileStr, idRelaRedisDBIndex);
if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {
String[] split = groupCompileStrs.split(";");
@@ -1039,34 +1049,38 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
if (regionStr != null && !regionStr.trim().equals("")) {
String[] regionKeyArr = regionStr.split(";");
if (regionKeyArr != null && regionKeyArr.length > 0) {
//根据分组与域关联关系找到对应域配置然后删除(重命名)
removeRegionConfig(maatXmlConfig, regionKeyArr,
maatVersion.doubleValue(), service, transaction, redisDBIndex);
}
} else {
throw new RuntimeException(
"" + idRelaRedisDBIndex + "号redis库中获取" + groupRegionKey
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系key为"+groupRegionKey,RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
}
}
//根据分组与域关联关系找到对应域配置然后删除(重命名)
removeCompileAndGroupConfig(maatXmlConfig,
groupId.replace(redisDBIndex + ":GROUPCOMPILE:", ""), 11, maatVersion.doubleValue(),
service, transaction, redisDBIndex, id + "");// 11代表是分组配置
} else {
throw new RuntimeException("" + idRelaRedisDBIndex + "号redis库中获取" + groupId
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"+groupId,RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
} else {
throw new RuntimeException("" + idRelaRedisDBIndex + "号redis库中获取" + compileStr
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系key为"+compileStr,RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
} else {
throw new RuntimeException("无法获取内存中记录的id映射关系,无法获取业务类型" + service + "对应的maat规则或传入的配置id有误,请检查!");
if (StringUtils.isEmpty(maatXmlConfig)) {
throw new ServiceRuntimeException(
"无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",RestBusinessCode.NotFoundRedisRule.getValue());
}else {
throw new ServiceRuntimeException("删除redis库中配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
}
@@ -1097,8 +1111,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
if (keyStr.toLowerCase().contains("table_name")) {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type, null);
if (maatTableName == null) {
throw new RuntimeException(
"未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
throw new ServiceRuntimeException(
"无法从applicationConfig-rule.properties配置文件中,找到回调类配置service为" + service
+ "对应的真实表名",RestBusinessCode.NotFoundTableName.getValue());
} else {
keyBF.append(maatTableName);
}
@@ -1119,8 +1134,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
maatKey.toUpperCase());
break;
} else {
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey
+ "请检查id映射关系是否正确,或该配置已经被取消,已经被取消的配置不可再次取消,否则将抛出异常");
throw new ServiceRuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey
+ "请检查id映射关系是否正确,或该配置已经被取消,已经被取消的配置不可再次取消,否则将抛出异常",RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
}
@@ -1153,7 +1168,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
}
} else {
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则,请检查!");
throw new ServiceRuntimeException(
"无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",RestBusinessCode.NotFoundRedisRule.getValue());
}
}
@@ -1178,7 +1194,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.rename(oldKey, maatKey.toUpperCase());
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase());
} else {
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
throw new ServiceRuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + ",请检查id映射关系是否正确",RestBusinessCode.KeyNotExistsInRedis.getValue());
}
for (MaatXmlExpr maatXmlExpr : expressionList) {
@@ -1211,16 +1227,15 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
}
} else {
if (maatXmlConfig == null) {
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则,请检查maat.xml");
} else {
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
throw new RuntimeException(idRelaRedisDBIndex + "号redis库中存储的分组和域关系有误,请联系管理员检查数据");
throw new ServiceRuntimeException(
"无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",RestBusinessCode.NotFoundRedisRule.getValue());
}
}
}
/**
* 编译配置用于实时统计
* 取消分类性质,标签等信息
*/
private void delStatisticsReal(Map<Integer, Map<Integer, List<Long>>> idMap, Transaction transaction) {
@@ -1229,8 +1244,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.select(redisStatisticsRealDBIndex);
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisStatisticsRealDBIndex);
if (maatVersionStr == null) {
throw new RuntimeException("" + redisStatisticsRealDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException("" + redisStatisticsRealDBIndex
+ "号redis库中获取MAAT_VERSION失败",RestBusinessCode.KeyNotExistsInRedis.getValue());
}
double maatVersion = Double.valueOf(maatVersionStr) + 1D;
for (Integer redisDBIndex : idMap.keySet()) {
@@ -1257,15 +1272,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisStatisticsRealDBIndex, zset.toUpperCase(), maatVersion);
} else {
throw new RuntimeException("" + redisStatisticsRealDBIndex + "号redis中判断"
+ effectiveRuleKey.toUpperCase()
+ "组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException("" + redisStatisticsRealDBIndex + "号redisDB中判断" + effectiveRuleKey.toUpperCase() + "是否存在失败", RestBusinessCode.ExistsKeyFailed.getValue());
}
}
} else {
throw new RuntimeException("删除配置时,配置id不能为空,请联系开发人员检查删除逻辑是否正确");
throw new ServiceRuntimeException("取消配置时,未发现配置Id信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
@@ -1274,11 +1286,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
Integer.valueOf(maatVersionStr) + 1);
} else {
throw new RuntimeException("删除配置时,配置id不能为空,请联系开发人员检查删除逻辑是否正确");
throw new ServiceRuntimeException("删除redis库中配置时,未发现对应的配置信息,请检查配置参数是否正确",RestBusinessCode.ConfigSourceIsNull.getValue());
}
} else {
throw new RuntimeException("redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号");
throw new ServiceRuntimeException("redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号",RestBusinessCode.DbIndexNotInRange.getValue());
}
break;// 因为所有的value都是相同的所以只取消一次就可以了
}
@@ -1322,23 +1334,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
.equals(compileStr.toUpperCase())) {
String groupRegion = groupCompile.replaceAll("GROUPCOMPILE",
"GROUPREGION");
//删除分组与域的关联关系
if (JedisUtils.exists(groupRegion, idRelaRedisDBIndex)) {
transaction.del(groupRegion);// 删除组对应的域
transaction.del(groupRegion);
} else {
throw new RuntimeException("" + idRelaRedisDBIndex
+ "号redis库中判断" + groupRegion
+ "组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系key为"+groupRegion,RestBusinessCode.KeyNotExistsInRedis.getValue());
}
//删除分组与编译的关联关系
if (JedisUtils.exists(groupCompile.toUpperCase(),
idRelaRedisDBIndex)) {
transaction.del(groupCompile.toUpperCase());// 删除当前组所对应的编译
} else {
throw new RuntimeException("" + idRelaRedisDBIndex
+ "号redis库中判断" + groupCompile.toUpperCase()
+ "组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"+groupCompile.toUpperCase(),RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
@@ -1358,19 +1367,17 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.set(groupCompile, sb.substring(0, sb.length() - 1));
}
} else {
throw new RuntimeException("" + idRelaRedisDBIndex + "号redis库中获取"
+ groupCompile.toUpperCase()
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"+groupCompile.toUpperCase(),RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
if (JedisUtils.exists(compileStr.toUpperCase(), idRelaRedisDBIndex)) {
transaction.del(compileStr.toUpperCase());// 删除编译下面所有的组
transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
}
} else {
throw new RuntimeException("" + idRelaRedisDBIndex + "号redis库中获取" + compileStr
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new ServiceRuntimeException("" + idRelaRedisDBIndex + "号redis库中获取" + compileStr
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
@@ -1378,11 +1385,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("状态更新操作Map参数信息不能为空,请检查配置参数是否正确",RestBusinessCode.ConfigInfoMapIsNull.getValue());
}
}
}

View File

@@ -19,7 +19,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.nis.web.service.AuditLogThread;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.ExecutorType;
@@ -43,6 +42,7 @@ import com.nis.domain.restful.NumRegion;
import com.nis.domain.restful.StrRegion;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.BasicProvingUtil;
import com.nis.util.CamelUnderlineUtil;
import com.nis.util.CompileVal;
@@ -59,6 +59,7 @@ import com.nis.web.dao.ConfigGroupRelationDao;
import com.nis.web.dao.IpRegionDao;
import com.nis.web.dao.NumRegionDao;
import com.nis.web.dao.StrRegionDao;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.BaseService;
import com.nis.web.service.SpringContextHolder;
@@ -129,9 +130,7 @@ public class ConfigSourcesService extends BaseService {
for (ConfigCompile config : configSource) {
String msg = CompileVal.compileIsOk(config, true, sb);
if (!"ok".equals(msg)) {
thread.setExceptionInfo(msg + sb.toString());
throw new RestServiceException(thread,
System.currentTimeMillis() - start, msg
throw new RestServiceException(msg
+ sb.toString(),
CompileVal.getBusinessCode());
}
@@ -140,9 +139,7 @@ public class ConfigSourcesService extends BaseService {
}
} else {
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
throw new RestServiceException(thread,
System.currentTimeMillis() - start, "编译配置不能为空"
throw new RestServiceException("编译配置不能为空"
+ sb.toString(),
CompileVal.getBusinessCode());
}
@@ -156,7 +153,6 @@ public class ConfigSourcesService extends BaseService {
throw new RestServiceException(thread, System.currentTimeMillis()
- start, e.getMessage() + sb.toString(), e.getErrorCode());
} catch (Exception e) {
logger.error("Exception", e);
String errorCode = OracleErrorCodeUtil.getOraCode(e);
if (!StringUtils.isEmpty(errorCode)) {
@@ -244,7 +240,7 @@ public class ConfigSourcesService extends BaseService {
|| queryCompileGroupByPID.size() == 0) {
throw new RestServiceException(thread, System.currentTimeMillis()
- start, "配置id为" + config.getCompileId()
+ "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(),
+ "的配置,在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(),
RestBusinessCode.config_integrity_error.getValue());
}
if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效
@@ -1023,21 +1019,14 @@ public class ConfigSourcesService extends BaseService {
MaatConfig maatConfig = new MaatConfig();
String msg = CompileVal.compileIsOk(configCompile, false, sb);
if (!"ok".equals(msg)) {
logger.error(msg);
thread.setExceptionInfo(msg + sb.toString());
thread.setBusinessCode(CompileVal.getBusinessCode());
throw new RestServiceException(thread,
System.currentTimeMillis() - start, msg
throw new RestServiceException(msg
+ sb.toString(),
CompileVal.getBusinessCode());
}
if (!(null != configCompile.getGroupRelationList() && configCompile
.getGroupRelationList().size() > 0)) {
logger.error("配置分组列表不能为空" + sb.toString());
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
throw new RestServiceException(thread,
System.currentTimeMillis() - start, "配置分组列表不能为空"
throw new RestServiceException("配置分组列表不能为空"
+ sb.toString(),
RestBusinessCode.CompileGroupIsNull.getValue());
}
@@ -1048,11 +1037,7 @@ public class ConfigSourcesService extends BaseService {
String errorMsg = "字符类域配置id不能为空 ,表名---"
+ strRegion.getTableName() + ""
+ sb.toString();
logger.error(errorMsg);
thread.setExceptionInfo(errorMsg);
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
errorMsg,
throw new RestServiceException(errorMsg,
RestBusinessCode.RegionIdIsNull.getValue());
}
}
@@ -1065,10 +1050,7 @@ public class ConfigSourcesService extends BaseService {
String errorMsg = "ip类域配置id不能为空 ,表名---"
+ ipRegion.getTableName() + ""
+ sb.toString();
logger.error(errorMsg);
thread.setExceptionInfo(errorMsg);
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
throw new RestServiceException(
errorMsg,
RestBusinessCode.RegionIdIsNull.getValue());
}
@@ -1082,11 +1064,7 @@ public class ConfigSourcesService extends BaseService {
String errorMsg = "数值类域配置id不能为空 ,表名---"
+ numRegion.getTableName() + ""
+ sb.toString();
logger.error(errorMsg);
thread.setExceptionInfo(errorMsg);
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
errorMsg,
throw new RestServiceException(errorMsg,
RestBusinessCode.RegionIdIsNull.getValue());
}
}
@@ -1099,11 +1077,7 @@ public class ConfigSourcesService extends BaseService {
String errorMsg = "摘要类域配置id不能为空 ,表名---"
+ digestRegion.getTableName() + ""
+ sb.toString();
logger.error(errorMsg);
thread.setExceptionInfo(errorMsg);
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
errorMsg,
throw new RestServiceException(errorMsg,
RestBusinessCode.RegionIdIsNull.getValue());
}
}
@@ -1117,11 +1091,7 @@ public class ConfigSourcesService extends BaseService {
String errorMsg = "生效范围IP域类域配置id不能为空 ,表名---"
+ ipRegion.getTableName() + ""
+ sb.toString();
logger.error(errorMsg);
thread.setExceptionInfo(errorMsg);
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
errorMsg,
throw new RestServiceException(errorMsg,
RestBusinessCode.RegionIdIsNull.getValue());
}
}
@@ -1298,9 +1268,9 @@ public class ConfigSourcesService extends BaseService {
newMaatConfig);
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("未找到域列表,请检查配置文件中域类型是否正确!");
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
e = new RuntimeException(
"未找到域列表,请检查域类型是否正确!");
e = new ServiceRuntimeException("未找到域列表,请检查域类型是否正确!",RestBusinessCode.service_runtime_error.getValue());
msgList.add(e);
return "error";
}
@@ -1320,20 +1290,21 @@ public class ConfigSourcesService extends BaseService {
}
} else {
RuntimeException e = new RuntimeException(
"service与写入数据库序号映射关系不存在");
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
ServiceRuntimeException e = new ServiceRuntimeException(RestBusinessCode.ServiceNoFoundDBIndex.getErrorReason(),RestBusinessCode.ServiceNoFoundDBIndex.getValue());
CompileVal.setBusinessCode(RestBusinessCode.ServiceNoFoundDBIndex.getValue());
msgList.add(e);
return "error";
}
}
}catch (RestServiceException e ){
}catch (RuntimeException e){
logger.error(e.getMessage());
msgList.add(e);
return "error";
}catch (Exception e) {
// TODO: handle exception
e = new ServiceRuntimeException("服务器内部异常:"+e.getMessage(),RestBusinessCode.service_runtime_error.getValue());
msgList.add(e);
CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue());
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
return "error";
}
try {
@@ -1342,8 +1313,10 @@ public class ConfigSourcesService extends BaseService {
} catch (Exception e) {
// TODO: handle exception
CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue());
if (e.getMessage().startsWith("后台错误:")) {
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
if (e instanceof RestServiceException) {
CompileVal.setBusinessCode(((RestServiceException)e).getErrorCode());
}else if (e instanceof ServiceRuntimeException ) {
CompileVal.setBusinessCode(((ServiceRuntimeException)e).getErrorCode());
}
logger.error(e.getMessage());
msgList.add(e);
@@ -1412,6 +1385,7 @@ public class ConfigSourcesService extends BaseService {
- start, "编译配置不能为空" + sb.toString(),
RestBusinessCode.CompileIsNull.getValue());
}
//Map<DBIndex,Map<Service,List<CompileId>>
Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
Iterator serviceIterator = compileMap.keySet().iterator();
while (serviceIterator.hasNext()) {
@@ -1431,17 +1405,17 @@ public class ConfigSourcesService extends BaseService {
}
}
} else {
RuntimeException e = new RuntimeException("service值为" + service
+ ",与写入数据库序号映射关系不存在");
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
ServiceRuntimeException e = new ServiceRuntimeException("service值为" + service
+ ",与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue());
CompileVal.setBusinessCode(RestBusinessCode.ServiceNoFoundDBIndex.getValue());
msgList.add(e);
return "error";
}
}
try {
if (!configRedisService.delMaatConfig(restMap)) {
RuntimeException e = new RuntimeException("不存在映射关系");
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
ServiceRuntimeException e = new ServiceRuntimeException("取消MAAT配置时出现异常具体原因不详请联系管理员",RestBusinessCode.service_runtime_error.getValue());
msgList.add(e);
return "error";
}
@@ -1449,8 +1423,10 @@ public class ConfigSourcesService extends BaseService {
// 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) {
CompileVal.setBusinessCode(((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) {
CompileVal.setBusinessCode(((ServiceRuntimeException) e).getErrorCode());
}
msgList.add(e);
return "error";
@@ -2726,8 +2702,19 @@ public class ConfigSourcesService extends BaseService {
public String saveCommonSources(AuditLogThread thread, long start,
String jsonString) {
CompileVal.setBusinessCode(null);
JsonArray jsonObjectList = new JsonParser().parse(jsonString)
JsonArray jsonObjectList = null;
try {
jsonObjectList = new JsonParser().parse(jsonString)
.getAsJsonArray();
} catch (Exception e) {
// TODO: handle exception
logger.error(RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage());
CompileVal.setBusinessCode(RestBusinessCode.CBParamFormateError.getValue());
e =new RestServiceException (RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue());
msgList.add(e);
return "error";
}
Map<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>();
for (int i = 0; i < jsonObjectList.size(); i++) {
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
@@ -3036,8 +3023,8 @@ public class ConfigSourcesService extends BaseService {
} catch (Exception e) {
logger.error(e.getMessage());
CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue());
if (e.getMessage().startsWith("后台错误:")) {
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
if (e instanceof ServiceRuntimeException) {
CompileVal.setBusinessCode(((ServiceRuntimeException) e).getErrorCode());
}
msgList.add(e);
return "error";
@@ -3054,12 +3041,11 @@ public class ConfigSourcesService extends BaseService {
.getAsJsonArray();
} catch (Exception e) {
// TODO: handle exception
logger.error(e.getMessage());
CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue());
thread.setExceptionInfo(e.getMessage() + sb.toString());
throw new RestServiceException(thread, System.currentTimeMillis()
- start, e.getMessage() + sb.toString(),
CompileVal.getBusinessCode());
logger.error(RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage());
CompileVal.setBusinessCode(RestBusinessCode.CBParamFormateError.getValue());
e =new RestServiceException (RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue());
msgList.add(e);
return "error";
}
// <service,cfgIdList>
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();

View File

@@ -234,7 +234,8 @@
<bean class="com.nis.restful.DefaultRestErrorResolver">
<property name="exceptionMappingDefinitions">
<map>
<entry key="com.nis.restful.RestServiceException" value="404" />
<entry key="com.nis.restful.RestServiceException" value="400" />
<entry key="com.nis.restful.ServiceRuntimeException" value="500" />
<entry key="Throwable" value="500" />
</map>
</property>