处理获取消息体内容为空时造成的空指针异常

This commit is contained in:
648540858 2022-08-17 17:06:33 +08:00
parent 4fe5672623
commit 59bda74e88
9 changed files with 29 additions and 8 deletions

View File

@ -101,6 +101,10 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
try {
HandlerCatchData take = taskQueue.poll();
Element rootElement = getRootElement(take.getEvt());
if (rootElement == null) {
logger.error("处理NOTIFY消息时未获取到消息体,{}", take.getEvt().getRequest());
continue;
}
String cmd = XmlUtil.getText(rootElement, "CmdType");
if (CmdType.CATALOG.equals(cmd)) {
@ -142,6 +146,10 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
// 回复 200 OK
Element rootElement = getRootElement(evt);
if (rootElement == null) {
logger.error("处理MobilePosition移动位置Notify时未获取到消息体,{}", evt.getRequest());
return;
}
MobilePosition mobilePosition = new MobilePosition();
mobilePosition.setCreateTime(DateUtil.getNow());
@ -229,6 +237,10 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
String deviceId = SipUtils.getUserIdFromFromHeader(fromHeader);
Element rootElement = getRootElement(evt);
if (rootElement == null) {
logger.error("处理alarm设备报警Notify时未获取到消息体{}", evt.getRequest());
return;
}
Element deviceIdElement = rootElement.element("DeviceID");
String channelId = deviceIdElement.getText().toString();
@ -239,7 +251,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
}
rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ NotifyAlarm ] content cannot be null");
logger.warn("[ NotifyAlarm ] content cannot be null, {}", evt.getRequest());
return;
}
DeviceAlarm deviceAlarm = new DeviceAlarm();
@ -338,7 +350,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
}
Element rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ 收到目录订阅 ] content cannot be null");
logger.warn("[ 收到目录订阅 ] content cannot be null, {}", evt.getRequest());
return;
}
Element deviceListElement = rootElement.element("DeviceList");

View File

@ -84,6 +84,10 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
Request request = evt.getRequest();
try {
Element rootElement = getRootElement(evt);
if (rootElement == null) {
logger.error("处理SUBSCRIBE请求 未获取到消息体{}", evt.getRequest());
return;
}
String cmd = XmlUtil.getText(rootElement, "CmdType");
if (CmdType.MOBILE_POSITION.equals(cmd)) {
processNotifyMobilePosition(evt, rootElement);

View File

@ -108,6 +108,11 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
Element rootElement = null;
try {
rootElement = getRootElement(evt);
if (rootElement == null) {
logger.error("处理SUBSCRIBE请求 未获取到消息体{}", evt.getRequest());
responseAck(evt, Response.BAD_REQUEST, "content is null");
return;
}
} catch (DocumentException e) {
logger.warn("解析XML消息内容异常", e);
// 不存在则回复404

View File

@ -63,7 +63,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
try {
rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ 移动设备位置数据通知 ] content cannot be null");
logger.warn("[ 移动设备位置数据通知 ] content cannot be null, {}", evt.getRequest());
responseAck(evt, Response.BAD_REQUEST);
return;
}

View File

@ -96,7 +96,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
try {
Element rootElement = getRootElement(take.getEvt(), take.getDevice().getCharset());
if (rootElement == null) {
logger.warn("[ 收到通道 ] content cannot be null");
logger.warn("[ 收到通道 ] content cannot be null, {}", evt.getRequest());
continue;
}
Element deviceListElement = rootElement.element("DeviceList");

View File

@ -76,7 +76,7 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
try {
rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null");
logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null, {}", evt.getRequest());
responseAck(evt, Response.BAD_REQUEST);
return;
}

View File

@ -66,7 +66,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
try {
rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ 移动设备位置数据查询回复 ] content cannot be null");
logger.warn("[ 移动设备位置数据查询回复 ] content cannot be null, {}", evt.getRequest());
responseAck(evt, Response.BAD_REQUEST);
return;
}

View File

@ -53,7 +53,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent
try {
rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) {
logger.warn("[ 设备预置位查询应答 ] content cannot be null");
logger.warn("[ 设备预置位查询应答 ] content cannot be null, {}", evt.getRequest());
responseAck(evt, Response.BAD_REQUEST);
return;
}

View File

@ -81,7 +81,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
HandlerCatchData take = taskQueue.poll();
Element rootElementForCharset = getRootElement(take.getEvt(), take.getDevice().getCharset());
if (rootElement == null) {
logger.warn("[ 国标录像 ] content cannot be null");
logger.warn("[ 国标录像 ] content cannot be null, {}", evt.getRequest());
continue;
}
String sn = getText(rootElementForCharset, "SN");