Commit 32fbfd8d1e77e8745482b6df487f7f0acdd2721b

Authored by lawrencehj
1 parent a2bea34a

增加上级平台查询DeviceInfo和DeviceStatus的响应功能

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -5,6 +5,7 @@ import java.text.ParseException; @@ -5,6 +5,7 @@ import java.text.ParseException;
5 import java.util.*; 5 import java.util.*;
6 6
7 import javax.sip.header.FromHeader; 7 import javax.sip.header.FromHeader;
  8 +import javax.sip.header.HeaderAddress;
8 import javax.sip.InvalidArgumentException; 9 import javax.sip.InvalidArgumentException;
9 import javax.sip.RequestEvent; 10 import javax.sip.RequestEvent;
10 import javax.sip.SipException; 11 import javax.sip.SipException;
@@ -12,6 +13,7 @@ import javax.sip.message.Request; @@ -12,6 +13,7 @@ import javax.sip.message.Request;
12 import javax.sip.message.Response; 13 import javax.sip.message.Response;
13 14
14 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
  16 +import com.genersoft.iot.vmp.VManageBootstrap;
15 import com.genersoft.iot.vmp.common.StreamInfo; 17 import com.genersoft.iot.vmp.common.StreamInfo;
16 import com.genersoft.iot.vmp.common.VideoManagerConstants; 18 import com.genersoft.iot.vmp.common.VideoManagerConstants;
17 import com.genersoft.iot.vmp.conf.UserSetup; 19 import com.genersoft.iot.vmp.conf.UserSetup;
@@ -114,10 +116,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -114,10 +116,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
114 logger.info("接收到Catalog消息"); 116 logger.info("接收到Catalog消息");
115 processMessageCatalogList(evt); 117 processMessageCatalogList(evt);
116 } else if (MESSAGE_DEVICE_INFO.equals(cmd)) { 118 } else if (MESSAGE_DEVICE_INFO.equals(cmd)) {
117 - logger.info("接收到DeviceInfo消息"); 119 + //DeviceInfo消息处理
118 processMessageDeviceInfo(evt); 120 processMessageDeviceInfo(evt);
119 } else if (MESSAGE_DEVICE_STATUS.equals(cmd)) { 121 } else if (MESSAGE_DEVICE_STATUS.equals(cmd)) {
120 - logger.info("接收到DeviceStatus消息"); 122 + // DeviceStatus消息处理
121 processMessageDeviceStatus(evt); 123 processMessageDeviceStatus(evt);
122 } else if (MESSAGE_DEVICE_CONTROL.equals(cmd)) { 124 } else if (MESSAGE_DEVICE_CONTROL.equals(cmd)) {
123 logger.info("接收到DeviceControl消息"); 125 logger.info("接收到DeviceControl消息");
@@ -211,27 +213,48 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -211,27 +213,48 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
211 private void processMessageDeviceStatus(RequestEvent evt) { 213 private void processMessageDeviceStatus(RequestEvent evt) {
212 try { 214 try {
213 Element rootElement = getRootElement(evt); 215 Element rootElement = getRootElement(evt);
214 - String deviceId = XmlUtil.getText(rootElement, "DeviceID");  
215 - // 检查设备是否存在, 不存在则不回复  
216 - if (storager.exists(deviceId)) {  
217 - // 回复200 OK  
218 - responseAck(evt);  
219 - JSONObject json = new JSONObject();  
220 - XmlUtil.node2Json(rootElement, json);  
221 - if (logger.isDebugEnabled()) {  
222 - logger.debug(json.toJSONString());  
223 - }  
224 - RequestMessage msg = new RequestMessage();  
225 - msg.setDeviceId(deviceId);  
226 - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS);  
227 - msg.setData(json);  
228 - deferredResultHolder.invokeResult(msg); 216 + String name = rootElement.getName();
  217 + Element deviceIdElement = rootElement.element("DeviceID");
  218 + String deviceId = deviceIdElement.getText();
229 219
230 - if (offLineDetector.isOnline(deviceId)) {  
231 - publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); 220 + if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
  221 + logger.info("接收到DeviceStatus查询消息");
  222 + FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
  223 + String platformId = ((SipUri) fromHeader.getAddress().getURI()).getUser();
  224 + if (platformId == null) {
  225 + response404Ack(evt);
  226 + return;
232 } else { 227 } else {
  228 + // 回复200 OK
  229 + responseAck(evt);
  230 + String sn = rootElement.element("SN").getText();
  231 + ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
  232 + cmderFroPlatform.deviceStatusResponse(parentPlatform, sn, fromHeader.getTag());
  233 + }
  234 + } else {
  235 + logger.info("接收到DeviceStatus应答消息");
  236 + // 检查设备是否存在, 不存在则不回复
  237 + if (storager.exists(deviceId)) {
  238 + // 回复200 OK
  239 + responseAck(evt);
  240 + JSONObject json = new JSONObject();
  241 + XmlUtil.node2Json(rootElement, json);
  242 + if (logger.isDebugEnabled()) {
  243 + logger.debug(json.toJSONString());
  244 + }
  245 + RequestMessage msg = new RequestMessage();
  246 + msg.setDeviceId(deviceId);
  247 + msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS);
  248 + msg.setData(json);
  249 + deferredResultHolder.invokeResult(msg);
  250 +
  251 + if (offLineDetector.isOnline(deviceId)) {
  252 + publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
  253 + } else {
  254 + }
233 } 255 }
234 } 256 }
  257 +
235 } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { 258 } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
236 e.printStackTrace(); 259 e.printStackTrace();
237 } 260 }
@@ -263,6 +286,25 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -263,6 +286,25 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
263 deferredResultHolder.invokeResult(msg); 286 deferredResultHolder.invokeResult(msg);
264 } else { 287 } else {
265 // 此处是上级发出的DeviceControl指令 288 // 此处是上级发出的DeviceControl指令
  289 + if (XmlUtil.getText(rootElement, "TeleBoot").equals("Boot") && false) { // 远程启动功能:需要在重新启动程序后先对SipStack解绑
  290 + String platformId = ((SipUri) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
  291 + logger.info("执行远程启动命令");
  292 + ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
  293 + cmderFroPlatform.unregister(parentPlatform, null, null);
  294 +
  295 + Thread restartThread = new Thread(new Runnable() {
  296 + @Override
  297 + public void run() {
  298 + try {
  299 + Thread.sleep(1000);
  300 + VManageBootstrap.restart();
  301 + } catch (InterruptedException ignored) {
  302 + }
  303 + }
  304 + });
  305 + restartThread.setDaemon(false);
  306 + restartThread.start();
  307 + }
266 } 308 }
267 } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { 309 } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
268 e.printStackTrace(); 310 e.printStackTrace();
@@ -374,9 +416,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -374,9 +416,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
374 Element deviceIdElement = rootElement.element("DeviceID"); 416 Element deviceIdElement = rootElement.element("DeviceID");
375 String deviceId = deviceIdElement.getTextTrim().toString(); 417 String deviceId = deviceIdElement.getTextTrim().toString();
376 if (requestName.equals("Query")) { 418 if (requestName.equals("Query")) {
377 - // 回复200 OK  
378 - responseAck(evt); 419 + logger.info("接收到DeviceInfo查询消息");
  420 + FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
  421 + String platformId = ((SipUri) fromHeader.getAddress().getURI()).getUser();
  422 + if (platformId == null) {
  423 + response404Ack(evt);
  424 + return;
  425 + } else {
  426 + // 回复200 OK
  427 + responseAck(evt);
  428 + String sn = rootElement.element("SN").getText();
  429 + ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
  430 + cmderFroPlatform.deviceInfoResponse(parentPlatform, sn, fromHeader.getTag());
  431 + }
379 } else { 432 } else {
  433 + logger.info("接收到DeviceInfo应答消息");
380 Device device = storager.queryVideoDevice(deviceId); 434 Device device = storager.queryVideoDevice(deviceId);
381 if (device == null) { 435 if (device == null) {
382 return; 436 return;