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 56078f10..8f3ba0a2 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 @@ public abstract class SIPRequestProcessorParent { byte destBye = (byte) despChar; List 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 3dd8fcbe..ac39dd65 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.Iterator; import java.util.concurrent.ConcurrentLinkedQueue; /** - * SIP命令类型: NOTIFY请求 + * SIP命令类型: NOTIFY请求,这是作为上级发送订阅请求后,设备才会响应的 */ @Component public class NotifyRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { @@ -198,6 +198,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements } storager.updateChannelPosition(deviceChannel); + // 发送redis消息。 通知位置信息的变化 JSONObject jsonObject = new JSONObject(); jsonObject.put("time", time); @@ -237,6 +238,10 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements 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 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - - // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); @@ -294,6 +297,18 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements } storager.updateChannelPosition(deviceChannel); + // 发送redis消息。 通知位置信息的变化 + 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 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements 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 c8be504c..bb34189e 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.beans.factory.annotation.Autowired; 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 20316e7e..2a653ebc 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 java.text.ParseException; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; +/** + * 报警事件的处理,参考:9.4 + */ @Component public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -73,12 +77,8 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme // 回复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 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); @@ -144,6 +143,18 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme storager.insertMobilePosition(mobilePosition); } storager.updateChannelPosition(deviceChannel); + + // 发送redis消息。 通知位置信息的变化 + 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 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); alarmChannelMessage.setGbId(channelId); redisCatchStorage.sendAlarmMsg(alarmChannelMessage); - return; } @@ -169,7 +179,6 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme 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 0b27855f..00000000 --- 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 deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); - // 查询关联的直播通道 - List gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); - // 回复目录信息 - List catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId()); - - List 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 c4294576..c3f19cb7 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.header.ViaHeader; 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 8a5ef793..5e724e71 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 java.text.ParseException; 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 2402494c..a061eb6a 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 java.text.ParseException; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 移动设备位置数据通知,设备主动发起,不需要上级订阅 + */ @Component public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -43,6 +46,9 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen @Autowired private IVideoManagerStorage storager; + @Autowired + private IRedisCatchStorage redisCatchStorage; + @Autowired private IDeviceChannelService deviceChannelService; @@ -56,7 +62,11 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen 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 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen storager.updateChannelPosition(deviceChannel); //回复 200 OK responseAck(evt, Response.OK); + + // 发送redis消息。 通知位置信息的变化 + 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 a278c082..e7d8d341 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 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp 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 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp 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 f5d04be9..c6d029f7 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 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent } try { rootElement = getRootElement(evt, device.getCharset()); + if (rootElement == null) { + logger.warn("[ 接收到DeviceInfo应答消息 ] 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 4c723abd..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.transmit.event.request.impl.message.respons 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 java.text.ParseException; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 移动设备位置数据查询回复 + * @author lin + */ @Component public class MobilePositionResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -43,6 +49,9 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar @Autowired private IVideoManagerStorage storager; + @Autowired + private IRedisCatchStorage redisCatchStorage; + @Autowired private IDeviceChannelService deviceChannelService; @@ -56,7 +65,11 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar 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 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar storager.insertMobilePosition(mobilePosition); } storager.updateChannelPosition(deviceChannel); + + // 发送redis消息。 通知位置信息的变化 + 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 45265c5b..df4dccff 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 java.util.List; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; +/** + * 设备预置位查询应答 + */ @Component public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -49,7 +52,11 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent 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"); //该字段可能为通道或则设备的id @@ -61,11 +68,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent } int sumNum = Integer.parseInt(presetListNumElement.attributeValue("Num")); List presetQuerySipReqList = new ArrayList<>(); - if (sumNum == 0) { - // 数据无预置位信息 - - - }else { + if (sumNum > 0) { for (Iterator 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 79153198..480ea738 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 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent 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();