From 4fe5672623212f5f6ac50009c4dc88d5c517dbb4 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 17 八月 2022 16:45:06 +0800 Subject: [PATCH] 处理获取消息体内容为空时造成的空指针异常 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java | 27 ++++++ src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java | 15 ++- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java | 29 ++++++ src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java | 27 ++++-- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java | 4 + src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java | 3 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java | 9 + src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java | 3 /dev/null | 88 ---------------------- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java | 3 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java | 25 +++++ src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java | 2 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java | 5 + 13 files changed, 127 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java index 56078f1..8f3ba0a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java @@ -231,6 +231,9 @@ byte destBye = (byte) despChar; List<Byte> result = new ArrayList<>(); byte[] rawContent = request.getRawContent(); + if (rawContent == null) { + return null; + } for (int i = 0; i < rawContent.length; i++) { if (rawContent[i] == destBye) { boolean resul = false; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java index 3dd8fcb..ac39dd6 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java @@ -41,7 +41,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; /** - * SIP鍛戒护绫诲瀷锛� NOTIFY璇锋眰 + * SIP鍛戒护绫诲瀷锛� NOTIFY璇锋眰,杩欐槸浣滀负涓婄骇鍙戦�佽闃呰姹傚悗锛岃澶囨墠浼氬搷搴旂殑 */ @Component public class NotifyRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { @@ -198,6 +198,7 @@ } storager.updateChannelPosition(deviceChannel); + // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖� JSONObject jsonObject = new JSONObject(); jsonObject.put("time", time); @@ -237,6 +238,10 @@ return; } rootElement = getRootElement(evt, device.getCharset()); + if (rootElement == null) { + logger.warn("[ NotifyAlarm ] content cannot be null"); + return; + } DeviceAlarm deviceAlarm = new DeviceAlarm(); deviceAlarm.setDeviceId(deviceId); deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); @@ -272,8 +277,6 @@ mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - - // 鏇存柊device channel 鐨勭粡绾害 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); @@ -294,6 +297,18 @@ } storager.updateChannelPosition(deviceChannel); + // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖� + JSONObject jsonObject = new JSONObject(); + jsonObject.put("time", mobilePosition.getTime()); + jsonObject.put("serial", deviceChannel.getDeviceId()); + jsonObject.put("code", deviceChannel.getChannelId()); + jsonObject.put("longitude", mobilePosition.getLongitude()); + jsonObject.put("latitude", mobilePosition.getLatitude()); + jsonObject.put("altitude", mobilePosition.getAltitude()); + jsonObject.put("direction", mobilePosition.getDirection()); + jsonObject.put("speed", mobilePosition.getSpeed()); + redisCatchStorage.sendMobilePositionMsg(jsonObject); + } // TODO: 闇�瑕佸疄鐜板瓨鍌ㄦ姤璀︿俊鎭�佹姤璀﹀垎绫� @@ -322,6 +337,10 @@ return; } Element rootElement = getRootElement(evt, device.getCharset()); + if (rootElement == null) { + logger.warn("[ 鏀跺埌鐩綍璁㈤槄 ] content cannot be null"); + return; + } Element deviceListElement = rootElement.element("DeviceList"); if (deviceListElement == null) { return; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java index c8be504..bb34189 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; /** - * 鍛戒护绫诲瀷锛� 閫氱煡鍛戒护 + * 鍛戒护绫诲瀷锛� 閫氱煡鍛戒护锛� 鍙傜湅 A.2.5 閫氱煡鍛戒护 * 鍛戒护绫诲瀷锛� 鐘舵�佷俊鎭�(蹇冭烦)鎶ラ��, 鎶ヨ閫氱煡, 濯掍綋閫氱煡, 绉诲姩璁惧浣嶇疆鏁版嵁锛岃闊冲箍鎾�氱煡(TODO), 璁惧棰勭疆浣�(TODO) * @author lin */ diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java index 20316e7..2a653eb 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; +import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.*; @@ -32,6 +33,9 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; +/** + * 鎶ヨ浜嬩欢鐨勫鐞嗭紝鍙傝�冿細9.4 + */ @Component public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -73,12 +77,8 @@ // 鍥炲200 OK try { responseAck(evt, Response.OK); - } catch (SipException e) { - throw new RuntimeException(e); - } catch (InvalidArgumentException e) { - throw new RuntimeException(e); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (SipException | InvalidArgumentException | ParseException e) { + logger.error("[鏀跺埌鎶ヨ閫氱煡], 鍥炲200OK澶辫触", e); } Element deviceIdElement = rootElement.element("DeviceID"); @@ -124,7 +124,6 @@ mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - // 鏇存柊device channel 鐨勭粡绾害 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); @@ -144,6 +143,18 @@ storager.insertMobilePosition(mobilePosition); } storager.updateChannelPosition(deviceChannel); + + // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖� + JSONObject jsonObject = new JSONObject(); + jsonObject.put("time", mobilePosition.getTime()); + jsonObject.put("serial", deviceChannel.getDeviceId()); + jsonObject.put("code", deviceChannel.getChannelId()); + jsonObject.put("longitude", mobilePosition.getLongitude()); + jsonObject.put("latitude", mobilePosition.getLatitude()); + jsonObject.put("altitude", mobilePosition.getAltitude()); + jsonObject.put("direction", mobilePosition.getDirection()); + jsonObject.put("speed", mobilePosition.getSpeed()); + redisCatchStorage.sendMobilePositionMsg(jsonObject); } } if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) { @@ -159,7 +170,6 @@ alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); alarmChannelMessage.setGbId(channelId); redisCatchStorage.sendAlarmMsg(alarmChannelMessage); - return; } @@ -168,7 +178,6 @@ if (sipConfig.isAlarm()) { deviceAlarmService.add(deviceAlarm); } - if (redisCatchStorage.deviceIsOnline(device.getDeviceId())) { publisher.deviceAlarmEventPublish(deviceAlarm); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java deleted file mode 100644 index 0b27855..0000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; - -import com.genersoft.iot.vmp.gb28181.bean.*; -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; -import com.genersoft.iot.vmp.storager.IVideoManagerStorage; -import org.dom4j.Element; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.sip.InvalidArgumentException; -import javax.sip.RequestEvent; -import javax.sip.SipException; -import javax.sip.header.FromHeader; -import javax.sip.message.Response; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -@Component -public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { - - private final String cmdType = "Catalog"; - - @Autowired - private NotifyMessageHandler notifyMessageHandler; - - @Autowired - private IVideoManagerStorage storage; - - @Autowired - private SIPCommanderFroPlatform cmderFroPlatform; - - @Override - public void afterPropertiesSet() throws Exception { - notifyMessageHandler.addHandler(cmdType, this); - } - - @Override - public void handForDevice(RequestEvent evt, Device device, Element element) { - - } - - @Override - public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { - - String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + parentPlatform.getServerGBId(); - FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); - try { - // 鍥炲200 OK - responseAck(evt, Response.OK); - Element snElement = rootElement.element("SN"); - String sn = snElement.getText(); - // 鍑嗗鍥炲閫氶亾淇℃伅 - List<DeviceChannelInPlatform> deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); - // 鏌ヨ鍏宠仈鐨勭洿鎾�氶亾 - List<DeviceChannel> gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); - // 鍥炲鐩綍淇℃伅 - List<DeviceChannel> catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId()); - - List<DeviceChannel> allChannels = new ArrayList<>(); - if (catalogs.size() > 0) { - allChannels.addAll(catalogs); - } - // 鍥炲绾ц仈鐨勯�氶亾 - if (deviceChannels.size() > 0) { - allChannels.addAll(deviceChannels); - } - // 鍥炲鐩存挱鐨勯�氶亾 - if (gbStreams.size() > 0) { - allChannels.addAll(gbStreams); - } - if (allChannels.size() > 0) { - cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag()); - }else { - // 鍥炲鏃犻�氶亾 - cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), 0); - } - } catch (SipException | InvalidArgumentException | ParseException e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java index c429457..c3f19cb 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java @@ -25,6 +25,9 @@ import javax.sip.message.Response; import java.text.ParseException; +/** + * 鐘舵�佷俊鎭�(蹇冭烦)鎶ラ�� + */ @Component public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java index 8a5ef79..5e724e7 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java @@ -29,6 +29,9 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 濯掍綋閫氱煡 + */ @Component public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java index 2402494..a061eb6 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java @@ -1,16 +1,16 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; +import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; -import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.service.IDeviceChannelService; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; -import com.genersoft.iot.vmp.utils.GpsUtil; import org.dom4j.DocumentException; import org.dom4j.Element; import org.slf4j.Logger; @@ -28,6 +28,9 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 绉诲姩璁惧浣嶇疆鏁版嵁閫氱煡锛岃澶囦富鍔ㄥ彂璧凤紝涓嶉渶瑕佷笂绾ц闃� + */ @Component public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -44,6 +47,9 @@ private IVideoManagerStorage storager; @Autowired + private IRedisCatchStorage redisCatchStorage; + + @Autowired private IDeviceChannelService deviceChannelService; @Override @@ -56,7 +62,11 @@ try { rootElement = getRootElement(evt, device.getCharset()); - + if (rootElement == null) { + logger.warn("[ 绉诲姩璁惧浣嶇疆鏁版嵁閫氱煡 ] content cannot be null"); + responseAck(evt, Response.BAD_REQUEST); + return; + } MobilePosition mobilePosition = new MobilePosition(); mobilePosition.setCreateTime(DateUtil.getNow()); if (!StringUtils.isEmpty(device.getName())) { @@ -106,6 +116,19 @@ storager.updateChannelPosition(deviceChannel); //鍥炲 200 OK responseAck(evt, Response.OK); + + // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖� + JSONObject jsonObject = new JSONObject(); + jsonObject.put("time", mobilePosition.getTime()); + jsonObject.put("serial", deviceChannel.getDeviceId()); + jsonObject.put("code", deviceChannel.getChannelId()); + jsonObject.put("longitude", mobilePosition.getLongitude()); + jsonObject.put("latitude", mobilePosition.getLatitude()); + jsonObject.put("altitude", mobilePosition.getAltitude()); + jsonObject.put("direction", mobilePosition.getDirection()); + jsonObject.put("speed", mobilePosition.getSpeed()); + redisCatchStorage.sendMobilePositionMsg(jsonObject); + } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { e.printStackTrace(); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java index a278c08..e7d8d34 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java @@ -95,12 +95,16 @@ HandlerCatchData take = taskQueue.poll(); try { Element rootElement = getRootElement(take.getEvt(), take.getDevice().getCharset()); + if (rootElement == null) { + logger.warn("[ 鏀跺埌閫氶亾 ] content cannot be null"); + continue; + } Element deviceListElement = rootElement.element("DeviceList"); Element sumNumElement = rootElement.element("SumNum"); Element snElement = rootElement.element("SN"); if (snElement == null || sumNumElement == null || deviceListElement == null) { responseAck(take.getEvt(), Response.BAD_REQUEST, "xml error"); - return; + continue; } int sumNum = Integer.parseInt(sumNumElement.getText()); @@ -129,7 +133,8 @@ catalogDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, take.getDevice(), channelList); logger.info("[鏀跺埌閫氶亾]璁惧: {} -> {}涓紝{}/{}", take.getDevice().getDeviceId(), channelList.size(), catalogDataCatch.get(take.getDevice().getDeviceId()) == null ? 0 :catalogDataCatch.get(take.getDevice().getDeviceId()).size(), sumNum); if (catalogDataCatch.get(take.getDevice().getDeviceId()).size() == sumNum) { - // 鏁版嵁宸茬粡瀹屾暣鎺ユ敹 + // 鏁版嵁宸茬粡瀹屾暣鎺ユ敹锛� 姝ゆ椂鍙兘瀛樺湪鏌愪釜璁惧绂荤嚎鍙樹笂绾跨殑鎯呭喌锛屼絾鏄�冭檻鍒版�ц兘锛屾澶勪笉鍋氬鐞嗭紝 + // 鐩墠鏀寔璁惧閫氶亾涓婄嚎閫氱煡鏃跺拰璁惧涓婄嚎鏃跺悜涓婄骇閫氱煡 boolean resetChannelsResult = storager.resetChannels(take.getDevice().getDeviceId(), catalogDataCatch.get(take.getDevice().getDeviceId())); if (!resetChannelsResult) { String errorMsg = "鎺ユ敹鎴愬姛锛屽啓鍏ュけ璐ワ紝鍏�" + sumNum + "鏉★紝宸叉帴鏀�" + catalogDataCatch.get(take.getDevice().getDeviceId()).size() + "鏉�"; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java index f5d04be..c6d029f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java @@ -75,6 +75,11 @@ } try { rootElement = getRootElement(evt, device.getCharset()); + if (rootElement == null) { + logger.warn("[ 鎺ユ敹鍒癉eviceInfo搴旂瓟娑堟伅 ] content cannot be null"); + responseAck(evt, Response.BAD_REQUEST); + return; + } Element deviceIdElement = rootElement.element("DeviceID"); String channelId = deviceIdElement.getTextTrim(); String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + device.getDeviceId() + channelId; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java index 4c723ab..9923f7c2 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; +import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; @@ -8,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.service.IDeviceChannelService; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.GpsUtil; @@ -28,6 +30,10 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 绉诲姩璁惧浣嶇疆鏁版嵁鏌ヨ鍥炲 + * @author lin + */ @Component public class MobilePositionResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -44,6 +50,9 @@ private IVideoManagerStorage storager; @Autowired + private IRedisCatchStorage redisCatchStorage; + + @Autowired private IDeviceChannelService deviceChannelService; @Override @@ -56,7 +65,11 @@ try { rootElement = getRootElement(evt, device.getCharset()); - + if (rootElement == null) { + logger.warn("[ 绉诲姩璁惧浣嶇疆鏁版嵁鏌ヨ鍥炲 ] content cannot be null"); + responseAck(evt, Response.BAD_REQUEST); + return; + } MobilePosition mobilePosition = new MobilePosition(); mobilePosition.setCreateTime(DateUtil.getNow()); if (!StringUtils.isEmpty(device.getName())) { @@ -103,6 +116,18 @@ storager.insertMobilePosition(mobilePosition); } storager.updateChannelPosition(deviceChannel); + + // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖� + JSONObject jsonObject = new JSONObject(); + jsonObject.put("time", mobilePosition.getTime()); + jsonObject.put("serial", deviceChannel.getDeviceId()); + jsonObject.put("code", deviceChannel.getChannelId()); + jsonObject.put("longitude", mobilePosition.getLongitude()); + jsonObject.put("latitude", mobilePosition.getLatitude()); + jsonObject.put("altitude", mobilePosition.getAltitude()); + jsonObject.put("direction", mobilePosition.getDirection()); + jsonObject.put("speed", mobilePosition.getSpeed()); + redisCatchStorage.sendMobilePositionMsg(jsonObject); //鍥炲 200 OK responseAck(evt, Response.OK); } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java index 45265c5..df4dccf 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java @@ -26,6 +26,9 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 璁惧棰勭疆浣嶆煡璇㈠簲绛� + */ @Component public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -49,7 +52,11 @@ Element rootElement = null; try { rootElement = getRootElement(evt, device.getCharset()); - + if (rootElement == null) { + logger.warn("[ 璁惧棰勭疆浣嶆煡璇㈠簲绛� ] content cannot be null"); + responseAck(evt, Response.BAD_REQUEST); + return; + } Element presetListNumElement = rootElement.element("PresetList"); Element snElement = rootElement.element("SN"); //璇ュ瓧娈靛彲鑳戒负閫氶亾鎴栧垯璁惧鐨刬d @@ -61,11 +68,7 @@ } int sumNum = Integer.parseInt(presetListNumElement.attributeValue("Num")); List<PresetQuerySipReq> presetQuerySipReqList = new ArrayList<>(); - if (sumNum == 0) { - // 鏁版嵁鏃犻缃綅淇℃伅 - - - }else { + if (sumNum > 0) { for (Iterator<Element> presetIterator = presetListNumElement.elementIterator();presetIterator.hasNext();){ Element itemListElement = presetIterator.next(); PresetQuerySipReq presetQuerySipReq = new PresetQuerySipReq(); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java index 7915319..480ea73 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java @@ -80,6 +80,10 @@ try { HandlerCatchData take = taskQueue.poll(); Element rootElementForCharset = getRootElement(take.getEvt(), take.getDevice().getCharset()); + if (rootElement == null) { + logger.warn("[ 鍥芥爣褰曞儚 ] content cannot be null"); + continue; + } String sn = getText(rootElementForCharset, "SN"); String channelId = getText(rootElementForCharset, "DeviceID"); RecordInfo recordInfo = new RecordInfo(); -- Gitblit v1.8.0