File was renamed from src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
| | |
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.text.ParseException;
|
| | | import java.util.*;
|
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.Address;
|
| | | import javax.sip.address.SipURI;
|
| | |
|
| | | import javax.sip.header.FromHeader;
|
| | | import javax.sip.header.Header;
|
| | | import javax.sip.header.HeaderAddress;
|
| | | import javax.sip.header.ToHeader;
|
| | | import javax.sip.message.Request;
|
| | | import javax.sip.message.Response;
|
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| | |
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.genersoft.iot.vmp.VManageBootstrap;
|
| | | import com.genersoft.iot.vmp.common.StreamInfo;
|
| | | import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.conf.UserSetup;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.*;
|
| | | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
|
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| | | import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| | | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.utils.GpsUtil;
|
| | | import com.genersoft.iot.vmp.utils.SipUtils;
|
| | | import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
| | | import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
| | | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
|
| | |
|
| | | import gov.nist.javax.sip.SipStackImpl;
|
| | | import gov.nist.javax.sip.address.AddressImpl;
|
| | | import gov.nist.javax.sip.address.SipUri;
|
| | |
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.DocumentException;
|
| | | import org.dom4j.Element;
|
| | | import org.dom4j.io.SAXReader;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils;
|
| | |
|
| | | import javax.sip.*; |
| | | import javax.sip.address.SipURI; |
| | | import javax.sip.header.FromHeader; |
| | | import javax.sip.header.HeaderAddress; |
| | | import javax.sip.header.ToHeader; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| | | |
| | | /**
|
| | | * @Description:MESSAGE请求处理器
|
| | | * @author: swwheihei
|
| | | * @date: 2020年5月3日 下午5:32:41
|
| | | * @description: MESSAGE请求分发处理器, |
| | | * @author: panlinlin |
| | | * @date: 2021年11月8日 10:28 |
| | | */
|
| | | @SuppressWarnings(value={"unchecked", "rawtypes"})
|
| | | public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
| | | @Component |
| | | public class MessageRequestProcessor1 extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { |
| | |
|
| | | public static volatile List<String> threadNameList = new ArrayList();
|
| | | private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor1.class); |
| | | private static Map<String, ISIPRequestProcessor> messageHandlerMap = new ConcurrentHashMap<>(); |
| | |
|
| | | private UserSetup userSetup = (UserSetup) SpringBeanFactory.getBean("userSetup");
|
| | |
|
| | | private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
|
| | |
|
| | | private SIPCommander cmder;
|
| | |
|
| | | private SIPCommanderFroPlatform cmderFroPlatform;
|
| | |
|
| | | private IVideoManagerStorager storager;
|
| | |
|
| | | private IRedisCatchStorage redisCatchStorage;
|
| | |
|
| | | private EventPublisher publisher;
|
| | |
|
| | | private RedisUtil redis;
|
| | |
|
| | | private DeferredResultHolder deferredResultHolder;
|
| | |
|
| | | private DeviceOffLineDetector offLineDetector;
|
| | |
|
| | | private IDeviceAlarmService deviceAlarmService;
|
| | |
|
| | | private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_";
|
| | |
|
| | | private static final String MESSAGE_KEEP_ALIVE = "Keepalive";
|
| | | private static final String MESSAGE_CONFIG_DOWNLOAD = "ConfigDownload";
|
| | | private static final String MESSAGE_CATALOG = "Catalog";
|
| | |
| | | private static final String MESSAGE_DEVICE_CONTROL = "DeviceControl";
|
| | | private static final String MESSAGE_DEVICE_CONFIG = "DeviceConfig";
|
| | | private static final String MESSAGE_MOBILE_POSITION = "MobilePosition";
|
| | | // private static final String MESSAGE_MOBILE_POSITION_INTERVAL = "Interval";
|
| | | private static final String MESSAGE_PRESET_QUERY = "PresetQuery";
|
| | | private String method = "MESSAGE1111"; |
| | | |
| | | @Autowired |
| | | private UserSetup userSetup; |
| | | |
| | | @Autowired |
| | | private SIPCommander cmder; |
| | | |
| | | @Autowired |
| | | private SipConfig config; |
| | | |
| | | @Autowired |
| | | private SIPCommanderFroPlatform cmderFroPlatform; |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorager storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private EventPublisher publisher; |
| | | |
| | | @Autowired |
| | | private RedisUtil redis; |
| | | |
| | | @Autowired |
| | | private DeferredResultHolder deferredResultHolder; |
| | | |
| | | @Autowired |
| | | private DeviceOffLineDetector offLineDetector; |
| | | |
| | | @Autowired |
| | | private IDeviceAlarmService deviceAlarmService; |
| | | |
| | | @Autowired |
| | | private SIPProcessorObserver sipProcessorObserver; |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | // 添加消息处理的订阅 |
| | | sipProcessorObserver.addRequestProcessor(method, this); |
| | | } |
| | |
|
| | | /**
|
| | | * 处理MESSAGE请求
|
| | |
| | |
|
| | | try {
|
| | | Element rootElement = getRootElement(evt);
|
| | | String cmd = XmlUtil.getText(rootElement, "CmdType");
|
| | | String cmd = getText(rootElement, "CmdType"); |
| | |
|
| | | if (MESSAGE_KEEP_ALIVE.equals(cmd)) {
|
| | | logger.debug("接收到KeepAlive消息");
|
| | |
| | | processMessageBroadcast(evt);
|
| | | } else {
|
| | | logger.debug("接收到消息:" + cmd);
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | }
|
| | | } catch (DocumentException | SipException |InvalidArgumentException | ParseException e) {
|
| | | e.printStackTrace();
|
| | |
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | logger.warn("处理MobilePosition移动位置消息时未找到设备信息");
|
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | }
|
| | | Element rootElement = getRootElement(evt, device.getCharset());
|
| | |
|
| | | MobilePosition mobilePosition = new MobilePosition();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | if (!StringUtils.isEmpty(device.getName())) {
|
| | | mobilePosition.setDeviceName(device.getName());
|
| | | }
|
| | | mobilePosition.setDeviceId(deviceId);
|
| | | mobilePosition.setChannelId(XmlUtil.getText(rootElement, "DeviceID"));
|
| | | mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
|
| | | mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
| | | mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
|
| | | mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(rootElement, "Speed")));
|
| | | mobilePosition.setChannelId(getText(rootElement, "DeviceID")); |
| | | mobilePosition.setTime(getText(rootElement, "Time")); |
| | | mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); |
| | | mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); |
| | | if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { |
| | | mobilePosition.setSpeed(Double.parseDouble(getText(rootElement, "Speed"))); |
| | | } else {
|
| | | mobilePosition.setSpeed(0.0);
|
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Direction"))) {
|
| | | mobilePosition.setDirection(Double.parseDouble(XmlUtil.getText(rootElement, "Direction")));
|
| | | if (NumericUtil.isDouble(getText(rootElement, "Direction"))) { |
| | | mobilePosition.setDirection(Double.parseDouble(getText(rootElement, "Direction"))); |
| | | } else {
|
| | | mobilePosition.setDirection(0.0);
|
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Altitude"))) {
|
| | | mobilePosition.setAltitude(Double.parseDouble(XmlUtil.getText(rootElement, "Altitude")));
|
| | | if (NumericUtil.isDouble(getText(rootElement, "Altitude"))) { |
| | | mobilePosition.setAltitude(Double.parseDouble(getText(rootElement, "Altitude"))); |
| | | } else {
|
| | | mobilePosition.setAltitude(0.0);
|
| | | }
|
| | |
| | | }
|
| | | storager.insertMobilePosition(mobilePosition);
|
| | | //回复 200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | */
|
| | | private void processMessageDeviceStatus(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceStatus设备状态Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt);
|
| | | String name = rootElement.getName();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getText();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | String channelId = deviceIdElement.getText(); |
| | | if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
|
| | | logger.info("接收到DeviceStatus查询消息");
|
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
| | | String platformId = ((SipUri) fromHeader.getAddress().getURI()).getUser();
|
| | | if (platformId == null) {
|
| | | response404Ack(evt);
|
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | } else {
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | String sn = rootElement.element("SN").getText();
|
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
| | | cmderFroPlatform.deviceStatusResponse(parentPlatform, sn, fromHeader.getTag());
|
| | |
| | | // 检查设备是否存在, 不存在则不回复
|
| | | if (storager.exists(deviceId)) {
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | JSONObject json = new JSONObject();
|
| | | XmlUtil.node2Json(rootElement, json);
|
| | | if (logger.isDebugEnabled()) {
|
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS);
|
| | | msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId + channelId); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | |
|
| | | if (offLineDetector.isOnline(deviceId)) {
|
| | | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
|
| | |
| | | */
|
| | | private void processMessageDeviceControl(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceControl设备状态Message未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | //String result = XmlUtil.getText(rootElement, "Result");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | //String result = getText(rootElement, "Result"); |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (rootElement.getName().equals("Response")) {//} !StringUtils.isEmpty(result)) {
|
| | | // 此处是对本平台发出DeviceControl指令的应答
|
| | | JSONObject json = new JSONObject();
|
| | |
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL);
|
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | // 此处是上级发出的DeviceControl指令
|
| | | String platformId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
|
| | | String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
|
| | | // 远程启动功能
|
| | | if (!StringUtils.isEmpty(XmlUtil.getText(rootElement, "TeleBoot"))) {
|
| | | if (!StringUtils.isEmpty(getText(rootElement, "TeleBoot"))) { |
| | | if (deviceId.equals(targetGBId)) {
|
| | | // 远程启动本平台:需要在重新启动程序后先对SipStack解绑
|
| | | logger.info("执行远程启动本平台命令");
|
| | |
| | | }
|
| | | }
|
| | | // 云台/前端控制命令
|
| | | if (!StringUtils.isEmpty(XmlUtil.getText(rootElement,"PTZCmd")) && !deviceId.equals(targetGBId)) {
|
| | | String cmdString = XmlUtil.getText(rootElement,"PTZCmd");
|
| | | Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, deviceId);
|
| | | cmder.fronEndCmd(device, deviceId, cmdString);
|
| | | if (!StringUtils.isEmpty(getText(rootElement,"PTZCmd")) && !deviceId.equals(targetGBId)) { |
| | | String cmdString = getText(rootElement,"PTZCmd"); |
| | | Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, deviceId); |
| | | cmder.fronEndCmd(deviceForPlatform, deviceId, cmdString); |
| | | }
|
| | | }
|
| | | } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
| | |
| | | */
|
| | | private void processMessageDeviceConfig(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceConfig设备状态Message消息时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (rootElement.getName().equals("Response")) {
|
| | | // 此处是对本平台发出DeviceControl指令的应答
|
| | | JSONObject json = new JSONObject();
|
| | |
| | | if (logger.isDebugEnabled()) {
|
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; |
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG);
|
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | // 此处是上级发出的DeviceConfig指令
|
| | | }
|
| | |
| | | */
|
| | | private void processMessageConfigDownload(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理ConfigDownload设备状态Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + deviceId + channelId; |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (rootElement.getName().equals("Response")) {
|
| | | // 此处是对本平台发出DeviceControl指令的应答
|
| | | JSONObject json = new JSONObject();
|
| | |
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD);
|
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | // 此处是上级发出的DeviceConfig指令
|
| | | }
|
| | |
| | | */
|
| | | private void processMessagePresetQuery(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理PresetQuery预置位列表Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId + channelId; |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (rootElement.getName().equals("Response")) {// !StringUtils.isEmpty(result)) {
|
| | | // 此处是对本平台发出DeviceControl指令的应答
|
| | | JSONObject json = new JSONObject();
|
| | |
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY);
|
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | // 此处是上级发出的DeviceControl指令
|
| | | }
|
| | |
| | | */
|
| | | private void processMessageDeviceInfo(RequestEvent evt) {
|
| | | try {
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); |
| | | |
| | | Element rootElement = getRootElement(evt);
|
| | | String requestName = rootElement.getName();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getTextTrim();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | String channelId = deviceIdElement.getTextTrim(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + deviceId + channelId; |
| | | if (device != null ) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | | }
|
| | | if (requestName.equals("Query")) {
|
| | | logger.info("接收到DeviceInfo查询消息");
|
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
| | | String platformId = ((SipUri) fromHeader.getAddress().getURI()).getUser();
|
| | | if (platformId == null) {
|
| | | response404Ack(evt);
|
| | | if (parentPlatform == null) { |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | } else {
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | String sn = rootElement.element("SN").getText();
|
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
| | | cmderFroPlatform.deviceInfoResponse(parentPlatform, sn, fromHeader.getTag());
|
| | | }
|
| | | } else {
|
| | | logger.debug("接收到DeviceInfo应答消息");
|
| | | if (device == null) {
|
| | | logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | }
|
| | |
|
| | | device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
| | | device.setName(getText(rootElement, "DeviceName")); |
| | |
|
| | | device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
| | | device.setModel(XmlUtil.getText(rootElement, "Model"));
|
| | | device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
| | | device.setManufacturer(getText(rootElement, "Manufacturer")); |
| | | device.setModel(getText(rootElement, "Model")); |
| | | device.setFirmware(getText(rootElement, "Firmware")); |
| | | if (StringUtils.isEmpty(device.getStreamMode())) {
|
| | | device.setStreamMode("UDP");
|
| | | }
|
| | | storager.updateDevice(device);
|
| | |
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICEINFO);
|
| | | msg.setKey(key); |
| | | msg.setData(device);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (offLineDetector.isOnline(deviceId)) {
|
| | | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
|
| | | }
|
| | |
| | | */
|
| | | private void processMessageCatalogList(RequestEvent evt) {
|
| | | try {
|
| | | |
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(deviceId); |
| | | |
| | | |
| | | Element rootElement = getRootElement(evt);
|
| | | String name = rootElement.getName();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getText();
|
| | | String channelId = deviceIdElement.getText(); |
| | | Element deviceListElement = rootElement.element("DeviceList");
|
| | |
|
| | | String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId; |
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
| | | AddressImpl address = (AddressImpl) fromHeader.getAddress();
|
| | | SipUri uri = (SipUri) address.getURI();
|
| | | String platformId = uri.getUser();
|
| | | // if (deviceListElement == null) { // 存在DeviceList则为响应 catalog, 不存在DeviceList则为查询请求
|
| | | if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
|
| | | // TODO 后续将代码拆分
|
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
|
| | | if (parentPlatform == null) {
|
| | | response404Ack(evt);
|
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | } else {
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | |
|
| | | Element snElement = rootElement.element("SN");
|
| | | String sn = snElement.getText();
|
| | |
| | | deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
| | | // deviceChannel.setParentId(parentPlatform.getDeviceGBId());
|
| | | deviceChannel.setRegisterWay(1);
|
| | | deviceChannel.setCivilCode(cmder.getSipConfig().getDomain());
|
| | | deviceChannel.setCivilCode(config.getDomain()); |
| | | deviceChannel.setModel("live");
|
| | | deviceChannel.setOwner("wvp-pro");
|
| | | // deviceChannel.setAddress("test");
|
| | |
| | |
|
| | |
|
| | | } else {
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | logger.warn("收到catalog设备目录列表请求时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | }
|
| | | deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList");
|
| | |
| | | deviceChannel.setStatus(0);
|
| | | }
|
| | |
|
| | | deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
|
| | | deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
|
| | | deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
|
| | | deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
|
| | | deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
|
| | | deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
|
| | | if (XmlUtil.getText(itemDevice, "Parental") == null || XmlUtil.getText(itemDevice, "Parental") == "") {
|
| | | deviceChannel.setManufacture(getText(itemDevice, "Manufacturer")); |
| | | deviceChannel.setModel(getText(itemDevice, "Model")); |
| | | deviceChannel.setOwner(getText(itemDevice, "Owner")); |
| | | deviceChannel.setCivilCode(getText(itemDevice, "CivilCode")); |
| | | deviceChannel.setBlock(getText(itemDevice, "Block")); |
| | | deviceChannel.setAddress(getText(itemDevice, "Address")); |
| | | if (getText(itemDevice, "Parental") == null || getText(itemDevice, "Parental") == "") { |
| | | deviceChannel.setParental(0);
|
| | | } else {
|
| | | deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
|
| | | deviceChannel.setParental(Integer.parseInt(getText(itemDevice, "Parental"))); |
| | | }
|
| | | deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
|
| | | if (XmlUtil.getText(itemDevice, "SafetyWay") == null || XmlUtil.getText(itemDevice, "SafetyWay") == "") {
|
| | | deviceChannel.setParentId(getText(itemDevice, "ParentID")); |
| | | if (getText(itemDevice, "SafetyWay") == null || getText(itemDevice, "SafetyWay") == "") { |
| | | deviceChannel.setSafetyWay(0);
|
| | | } else {
|
| | | deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
|
| | | deviceChannel.setSafetyWay(Integer.parseInt(getText(itemDevice, "SafetyWay"))); |
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "RegisterWay") == null || XmlUtil.getText(itemDevice, "RegisterWay") == "") {
|
| | | if (getText(itemDevice, "RegisterWay") == null || getText(itemDevice, "RegisterWay") == "") { |
| | | deviceChannel.setRegisterWay(1);
|
| | | } else {
|
| | | deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
|
| | | deviceChannel.setRegisterWay(Integer.parseInt(getText(itemDevice, "RegisterWay"))); |
| | | }
|
| | | deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
|
| | | if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") {
|
| | | deviceChannel.setCertNum(getText(itemDevice, "CertNum")); |
| | | if (getText(itemDevice, "Certifiable") == null || getText(itemDevice, "Certifiable") == "") { |
| | | deviceChannel.setCertifiable(0);
|
| | | } else {
|
| | | deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
|
| | | deviceChannel.setCertifiable(Integer.parseInt(getText(itemDevice, "Certifiable"))); |
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") {
|
| | | if (getText(itemDevice, "ErrCode") == null || getText(itemDevice, "ErrCode") == "") { |
| | | deviceChannel.setErrCode(0);
|
| | | } else {
|
| | | deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
|
| | | deviceChannel.setErrCode(Integer.parseInt(getText(itemDevice, "ErrCode"))); |
| | | }
|
| | | deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
|
| | | deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
|
| | | deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
|
| | | if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") {
|
| | | deviceChannel.setEndTime(getText(itemDevice, "EndTime")); |
| | | deviceChannel.setSecrecy(getText(itemDevice, "Secrecy")); |
| | | deviceChannel.setIpAddress(getText(itemDevice, "IPAddress")); |
| | | if (getText(itemDevice, "Port") == null || getText(itemDevice, "Port") == "") { |
| | | deviceChannel.setPort(0);
|
| | | } else {
|
| | | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
|
| | | deviceChannel.setPort(Integer.parseInt(getText(itemDevice, "Port"))); |
| | | }
|
| | | deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {
|
| | | deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude")));
|
| | | deviceChannel.setPassword(getText(itemDevice, "Password")); |
| | | if (NumericUtil.isDouble(getText(itemDevice, "Longitude"))) { |
| | | deviceChannel.setLongitude(Double.parseDouble(getText(itemDevice, "Longitude"))); |
| | | } else {
|
| | | deviceChannel.setLongitude(0.00);
|
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) {
|
| | | deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
|
| | | if (NumericUtil.isDouble(getText(itemDevice, "Latitude"))) { |
| | | deviceChannel.setLatitude(Double.parseDouble(getText(itemDevice, "Latitude"))); |
| | | } else {
|
| | | deviceChannel.setLatitude(0.00);
|
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") {
|
| | | if (getText(itemDevice, "PTZType") == null || getText(itemDevice, "PTZType") == "") { |
| | | deviceChannel.setPTZType(0);
|
| | | } else {
|
| | | deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
| | | deviceChannel.setPTZType(Integer.parseInt(getText(itemDevice, "PTZType"))); |
| | | }
|
| | | deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
|
| | | storager.updateChannel(device.getDeviceId(), deviceChannel);
|
| | | }
|
| | |
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
|
| | | msg.setKey(key); |
| | | msg.setData(device);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (offLineDetector.isOnline(deviceId)) {
|
| | | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
|
| | | }
|
| | |
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | logger.warn("处理alarm设备报警信息未找到设备信息");
|
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return;
|
| | | }
|
| | | Element rootElement = getRootElement(evt, device.getCharset());
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String channelId = deviceIdElement.getText().toString();
|
| | | String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId + channelId; |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | |
|
| | | if (device.getCharset() != null) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | |
| | | DeviceAlarm deviceAlarm = new DeviceAlarm();
|
| | | deviceAlarm.setDeviceId(deviceId);
|
| | | deviceAlarm.setChannelId(channelId);
|
| | | deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
|
| | | deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
|
| | | deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
|
| | | if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
|
| | | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| | | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| | | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); |
| | | if (getText(rootElement, "AlarmDescription") == null) { |
| | | deviceAlarm.setAlarmDescription("");
|
| | | } else {
|
| | | deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
|
| | | deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); |
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Longitude"))) {
|
| | | deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
| | | if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { |
| | | deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); |
| | | } else {
|
| | | deviceAlarm.setLongitude(0.00);
|
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Latitude"))) {
|
| | | deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
| | | if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { |
| | | deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); |
| | | } else {
|
| | | deviceAlarm.setLatitude(0.00);
|
| | | }
|
| | |
| | | storager.insertMobilePosition(mobilePosition);
|
| | | }
|
| | | }
|
| | | System.out.println("存储报警信息、报警分类");
|
| | | logger.debug("存储报警信息、报警分类"); |
| | | // 存储报警信息、报警分类
|
| | | deviceAlarmService.add(deviceAlarm);
|
| | |
|
| | |
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_ALARM);
|
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | }
|
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
| | | e.printStackTrace();
|
| | |
| | | */
|
| | | private void processMessageKeepAlive(RequestEvent evt) {
|
| | | try {
|
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | |
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | |
| | | Element rootElement = getRootElement(evt); |
| | | String channelId = getText(rootElement, "DeviceID"); |
| | |
|
| | | // 检查设备是否存在并在线, 不在线则设置为在线
|
| | | if (device != null ) {
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
| | | }else{
|
| | | logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404");
|
| | |
| | | */
|
| | | private void processMessageRecordInfo(RequestEvent evt) {
|
| | | try {
|
| | | |
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | String uuid = UUID.randomUUID().toString().replace("-", "");
|
| | | RecordInfo recordInfo = new RecordInfo();
|
| | | Element rootElement = getRootElement(evt);
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getText().toString();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | String sn = getText(rootElement, "SN"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + sn; |
| | | if (device != null ) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | | }
|
| | | recordInfo.setDeviceId(deviceId);
|
| | | recordInfo.setName(XmlUtil.getText(rootElement, "Name"));
|
| | | if (XmlUtil.getText(rootElement, "SumNum")== null || XmlUtil.getText(rootElement, "SumNum") =="") {
|
| | | recordInfo.setSn(sn); |
| | | recordInfo.setName(getText(rootElement, "Name")); |
| | | if (getText(rootElement, "SumNum")== null || getText(rootElement, "SumNum") =="") { |
| | | recordInfo.setSumNum(0);
|
| | | } else {
|
| | | recordInfo.setSumNum(Integer.parseInt(XmlUtil.getText(rootElement, "SumNum")));
|
| | | recordInfo.setSumNum(Integer.parseInt(getText(rootElement, "SumNum"))); |
| | | }
|
| | | String sn = XmlUtil.getText(rootElement, "SN");
|
| | | |
| | | Element recordListElement = rootElement.element("RecordList");
|
| | | if (recordListElement == null || recordInfo.getSumNum() == 0) {
|
| | | logger.info("无录像数据");
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
| | | msg.setKey(key); |
| | | msg.setData(recordInfo);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | Iterator<Element> recordListIterator = recordListElement.elementIterator();
|
| | | List<RecordItem> recordList = new ArrayList<RecordItem>();
|
| | |
| | | continue;
|
| | | }
|
| | | record = new RecordItem();
|
| | | record.setDeviceId(XmlUtil.getText(itemRecord, "DeviceID"));
|
| | | record.setName(XmlUtil.getText(itemRecord, "Name"));
|
| | | record.setFilePath(XmlUtil.getText(itemRecord, "FilePath"));
|
| | | record.setAddress(XmlUtil.getText(itemRecord, "Address"));
|
| | | record.setDeviceId(getText(itemRecord, "DeviceID")); |
| | | record.setName(getText(itemRecord, "Name")); |
| | | record.setFilePath(getText(itemRecord, "FilePath")); |
| | | record.setAddress(getText(itemRecord, "Address")); |
| | | record.setStartTime(
|
| | | DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(XmlUtil.getText(itemRecord, "StartTime")));
|
| | | DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "StartTime"))); |
| | | record.setEndTime(
|
| | | DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(XmlUtil.getText(itemRecord, "EndTime")));
|
| | | DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "EndTime"))); |
| | | record.setSecrecy(itemRecord.element("Secrecy") == null ? 0
|
| | | : Integer.parseInt(XmlUtil.getText(itemRecord, "Secrecy")));
|
| | | record.setType(XmlUtil.getText(itemRecord, "Type"));
|
| | | record.setRecorderId(XmlUtil.getText(itemRecord, "RecorderID"));
|
| | | : Integer.parseInt(getText(itemRecord, "Secrecy"))); |
| | | record.setType(getText(itemRecord, "Type")); |
| | | record.setRecorderId(getText(itemRecord, "RecorderID")); |
| | | recordList.add(record);
|
| | | }
|
| | | recordInfo.setRecordList(recordList);
|
| | |
| | | */
|
| | | private void processMessageMediaStatus(RequestEvent evt){
|
| | | try {
|
| | | |
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | String NotifyType =XmlUtil.getText(rootElement, "NotifyType");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String NotifyType =getText(rootElement, "NotifyType"); |
| | | if (NotifyType.equals("121")){
|
| | | logger.info("媒体播放完毕,通知关流");
|
| | | StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, "*");
|
| | |
| | | */
|
| | | private void processMessageBroadcast(RequestEvent evt) {
|
| | | try {
|
| | | |
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); |
| | | // 查询设备是否存在 |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); |
| | | responseAck(evt, Response.NOT_FOUND); |
| | | return; |
| | | } |
| | | |
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
| | | String channelId = getText(rootElement, "DeviceID"); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId + channelId; |
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | | responseAck(evt, Response.OK); |
| | | if (rootElement.getName().equals("Response")) {
|
| | | // 此处是对本平台发出Broadcast指令的应答
|
| | | JSONObject json = new JSONObject();
|
| | |
| | | logger.debug(json.toJSONString());
|
| | | }
|
| | | RequestMessage msg = new RequestMessage();
|
| | | msg.setDeviceId(deviceId);
|
| | | msg.setType(DeferredResultHolder.CALLBACK_CMD_BROADCAST);
|
| | | msg.setKey(key); |
| | | msg.setData(json);
|
| | | deferredResultHolder.invokeResult(msg);
|
| | | deferredResultHolder.invokeAllResult(msg); |
| | | } else {
|
| | | // 此处是上级发出的Broadcast指令
|
| | | }
|
| | | } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /***
|
| | | * 回复200 OK
|
| | | * @param evt
|
| | | * @throws SipException
|
| | | * @throws InvalidArgumentException
|
| | | * @throws ParseException
|
| | | */
|
| | | private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) {
|
| | | serverTransaction.getDialog().delete();
|
| | | }
|
| | | }
|
| | |
|
| | | /***
|
| | | * 回复404
|
| | | * @param evt
|
| | | * @throws SipException
|
| | | * @throws InvalidArgumentException
|
| | | * @throws ParseException
|
| | | */
|
| | | private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) {
|
| | | serverTransaction.getDialog().delete();
|
| | | }
|
| | | }
|
| | |
|
| | | private Element getRootElement(RequestEvent evt) throws DocumentException {
|
| | |
|
| | | return getRootElement(evt, "gb2312");
|
| | | }
|
| | |
|
| | | private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
|
| | | if (charset == null) {
|
| | | charset = "gb2312";
|
| | | }
|
| | | Request request = evt.getRequest();
|
| | | SAXReader reader = new SAXReader();
|
| | | reader.setEncoding(charset);
|
| | | Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
|
| | | return xml.getRootElement();
|
| | | }
|
| | |
|
| | | public void setCmder(SIPCommander cmder) {
|
| | | this.cmder = cmder;
|
| | | }
|
| | |
|
| | | public void setStorager(IVideoManagerStorager storager) {
|
| | | this.storager = storager;
|
| | | }
|
| | |
|
| | | public void setPublisher(EventPublisher publisher) {
|
| | | this.publisher = publisher;
|
| | | }
|
| | |
|
| | | public void setRedis(RedisUtil redis) {
|
| | | this.redis = redis;
|
| | | }
|
| | |
|
| | | public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
|
| | | this.deferredResultHolder = deferredResultHolder;
|
| | | }
|
| | |
|
| | | public void setOffLineDetector(DeviceOffLineDetector offLineDetector) {
|
| | | this.offLineDetector = offLineDetector;
|
| | | }
|
| | |
|
| | | public IRedisCatchStorage getRedisCatchStorage() {
|
| | | return redisCatchStorage;
|
| | | }
|
| | |
|
| | | public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
|
| | | this.redisCatchStorage = redisCatchStorage;
|
| | | }
|
| | |
|
| | | public SIPCommanderFroPlatform getCmderFroPlatform() {
|
| | | return cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
|
| | | this.cmderFroPlatform = cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) {
|
| | | this.deviceAlarmService = deviceAlarmService;
|
| | | }
|
| | | }
|