From c25a99d60bef3d3bbd59fee895bd658928fd00db Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 10 一月 2024 16:17:29 +0800
Subject: [PATCH] 修复空指针异常

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

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
old mode 100644
new mode 100755
index 5c577ba..41a7dd8
--- 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
@@ -13,6 +13,7 @@
 import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import gov.nist.javax.sip.message.SIPRequest;
+import org.apache.commons.lang3.ObjectUtils;
 import org.dom4j.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,7 @@
 public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
 
 
-    private Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
+    private final Logger logger = LoggerFactory.getLogger(KeepaliveNotifyMessageHandler.class);
     private final static String cmdType = "Keepalive";
 
     @Autowired
@@ -59,18 +60,23 @@
             // 鏈敞鍐岀殑璁惧涓嶅仛澶勭悊
             return;
         }
-        logger.info("[鏀跺埌蹇冭烦]锛� device: {}", device.getDeviceId());
         SIPRequest request = (SIPRequest) evt.getRequest();
+        logger.info("[鏀跺埌蹇冭烦]锛� device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
+
         // 鍥炲200 OK
         try {
             responseAck(request, Response.OK);
         } catch (SipException | InvalidArgumentException | ParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 蹇冭烦鍥炲: {}", e.getMessage());
         }
+        if (!ObjectUtils.isEmpty(device.getKeepaliveTime()) && DateUtil.getDifferenceForNow(device.getKeepaliveTime()) <= 3000L) {
+            logger.info("[鏀跺埌蹇冭烦] 蹇冭烦鍙戦�佽繃浜庨绻侊紝宸插拷鐣� device: {}, callId: {}", device.getDeviceId(), request.getCallIdHeader().getCallId());
+            return;
+        }
 
         RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, userSetting.getSipUseSourceIpAsRemoteAddress());
         if (!device.getIp().equalsIgnoreCase(remoteAddressInfo.getIp()) || device.getPort() != remoteAddressInfo.getPort()) {
-            logger.info("[蹇冭烦] 璁惧{}鍦板潃鍙樺寲, 杩滅▼鍦板潃涓�: {}:{}", device.getDeviceId(), remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
+            logger.info("[鏀跺埌蹇冭烦] 璁惧{}鍦板潃鍙樺寲, 杩滅▼鍦板潃涓�: {}:{}", device.getDeviceId(), remoteAddressInfo.getIp(), remoteAddressInfo.getPort());
             device.setPort(remoteAddressInfo.getPort());
             device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));
             device.setIp(remoteAddressInfo.getIp());
@@ -80,7 +86,7 @@
         }else {
             long lastTime = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(device.getKeepaliveTime());
             if (System.currentTimeMillis()/1000-lastTime > 10) {
-                device.setKeepaliveIntervalTime(new Long(System.currentTimeMillis()/1000-lastTime).intValue());
+                device.setKeepaliveIntervalTime(Long.valueOf(System.currentTimeMillis()/1000-lastTime).intValue());
             }
         }
 
@@ -104,7 +110,11 @@
 
     @Override
     public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) {
-        // 涓嶄細鏀跺埌涓婄骇骞冲彴鐨勫績璺充俊鎭�
-
+        // 涓埆骞冲彴淇濇椿涓嶅洖澶�200OK浼氬垽瀹氱绾�
+        try {
+            responseAck((SIPRequest) evt.getRequest(), Response.OK);
+        } catch (SipException | InvalidArgumentException | ParseException e) {
+            logger.error("[鍛戒护鍙戦�佸け璐 蹇冭烦鍥炲: {}", e.getMessage());
+        }
     }
 }

--
Gitblit v1.8.0