作者 王勇

完善,备份

... ... @@ -96,10 +96,9 @@ public class RabbitController {
.build();
// 2、校验格式、数据
ResultJson resultJson = xmlUtils.checkFormatAndData(xmlData);
if (!"200".equals(resultJson.getCode())) {
if (!RESULT_SUCCESS.equals(resultJson.getCode())) {
return resultJson;
}
log.info(""+xmlData);
XmlData sentData = (XmlData) resultJson.getData();
// 3、通过格式校验之后,进行配置校验
Boolean binding = userMessageBindingService.validateXmlBinding(sentData);
... ...
... ... @@ -13,6 +13,7 @@ public enum CustomExceptionType {
RECEIVE_SERVER_EXCEPTION("20500", "服务器异常,接收消息失败!请联系管理员处理"),
SERVER_EXCEPTION("10500", "服务器异常,发送消息失败!"),
CLIENT_EXCEPTION("10400", "报文格式错误,请检查报文格式!"),
FORMAT_EXCEPTION("10400", "参数不得为空,请检查报文格式!"),
BINDING_ERROR("10501", "配置信息,未进行绑定!"),
SENDER_ERROR("10401", "报文格式错误,发送者不能为空!"),
... ...
... ... @@ -75,36 +75,52 @@ public class XmlUtils {
}
/**
* 对发送消息的格式进行校验
* <p>
* 为提升性能,对于格式(某一个而不是具体到每一个)进行是否为空进行判断
*
* @param xmlData {@link XmlData} 需要被检查的 xml 报文数据与格式
* @return
*/
public ResultJson checkFormatAndData(XmlData xmlData)
{
if (StringUtil.isNullOrEmpty(xmlData.getSendContent())) {
// 消息内容为空
return ResultJson.error(CustomExceptionType.CONTENT_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getSender())) {
// 发送者名称为空
return ResultJson.error(CustomExceptionType.SERVER_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getServerName())) {
// 服务器名称为空
return ResultJson.error(CustomExceptionType.SERVER_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getVirtualHostName())) {
// 虚拟主机为空
return ResultJson.error(CustomExceptionType.HOST_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getExchangeName())) {
// 交换机为空
return ResultJson.error(CustomExceptionType.EXCHANGE_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getRoutingKeyName())) {
// 路由键为空
return ResultJson.error(CustomExceptionType.ROUTING_KEY_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getSequence())) {
// 序列为空
return ResultJson.error(CustomExceptionType.SEQUENCE_ERROR);
} else if (StringUtil.isNullOrEmpty(xmlData.getToken())) {
// token为空
return ResultJson.error(CustomExceptionType.TOKEN_ERROR);
}
if (StringUtil.isNullOrEmpty(xmlData.getSendContent())
|| StringUtil.isNullOrEmpty(xmlData.getSender())
|| StringUtil.isNullOrEmpty(xmlData.getServerName())
|| StringUtil.isNullOrEmpty(xmlData.getVirtualHostName())
|| StringUtil.isNullOrEmpty(xmlData.getExchangeName())
|| StringUtil.isNullOrEmpty(xmlData.getRoutingKeyName())
) {
return ResultJson.error(CustomExceptionType.FORMAT_EXCEPTION);
}
// if (StringUtil.isNullOrEmpty(xmlData.getSendContent())) {
// // 消息内容为空
// return ResultJson.error(CustomExceptionType.CONTENT_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getSender())) {
// // 发送者名称为空
// return ResultJson.error(CustomExceptionType.SERVER_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getServerName())) {
// // 服务器名称为空
// return ResultJson.error(CustomExceptionType.SERVER_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getVirtualHostName())) {
// // 虚拟主机为空
// return ResultJson.error(CustomExceptionType.HOST_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getExchangeName())) {
// // 交换机为空
// return ResultJson.error(CustomExceptionType.EXCHANGE_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getRoutingKeyName())) {
// // 路由键为空
// return ResultJson.error(CustomExceptionType.ROUTING_KEY_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getSequence())) {
// // 序列为空
// return ResultJson.error(CustomExceptionType.SEQUENCE_ERROR);
// } else if (StringUtil.isNullOrEmpty(xmlData.getToken())) {
// // token为空
// return ResultJson.error(CustomExceptionType.TOKEN_ERROR);
// }
List<UserInfo> userList = userInfoService.selectUserExist(xmlData.getSender());
if (userList.size() == 0) {
// 发送者不存在
... ...