diff --git a/gb28181-client/pom.xml b/gb28181-client/pom.xml index e9b1db74..a4249ae3 100644 --- a/gb28181-client/pom.xml +++ b/gb28181-client/pom.xml @@ -6,7 +6,7 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 ${gb28181-proxy.version} diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/MessageClientHandlerAbstract.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/MessageClientHandlerAbstract.java index c245d4ab..91ea5b16 100755 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/MessageClientHandlerAbstract.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/MessageClientHandlerAbstract.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; import gov.nist.javax.sip.message.SIPRequest; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import io.github.lunasaw.sip.common.transmit.event.message.MessageHandlerAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java index 8db6b4ab..805d526a 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java @@ -2,6 +2,7 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -37,7 +38,7 @@ public DeviceControlMessageHandler(MessageProcessorClient messageProcessorClient @Override public String getRootType() { - return CONTROL; + return ClientMessageRequestProcessor.METHOD + CONTROL; } @Override diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java index ec81d137..16a9d566 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java @@ -2,9 +2,10 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import io.github.lunasaw.sip.common.entity.FromDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceBroadcastNotify; import org.springframework.stereotype.Component; @@ -36,7 +37,7 @@ public BroadcastNotifyMessageHandler(MessageProcessorClient messageProcessorClie @Override public String getRootType() { - return NOTIFY; + return ClientMessageRequestProcessor.METHOD + NOTIFY; } @Override diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java index fad15626..f0fe91ce 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java @@ -3,11 +3,12 @@ import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceAlarmNotify; import io.github.lunasaw.gb28181.common.entity.query.DeviceAlarmQuery; @@ -39,7 +40,7 @@ public AlarmQueryMessageClientHandler(MessageProcessorClient messageProcessorCli @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } @Override diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/CatalogQueryMessageClientHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/CatalogQueryMessageClientHandler.java index e6883775..9b8b7862 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/CatalogQueryMessageClientHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/CatalogQueryMessageClientHandler.java @@ -3,6 +3,7 @@ import javax.sip.RequestEvent; import io.github.lunasaw.gb28181.common.entity.response.DeviceResponse; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import lombok.Setter; @@ -13,7 +14,7 @@ import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageProcessorClient; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -41,7 +42,7 @@ public CatalogQueryMessageClientHandler(MessageProcessorClient messageProcessorC @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java index 3550b95b..266703ea 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java @@ -3,10 +3,11 @@ import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceConfigDownload; import io.github.lunasaw.gb28181.common.entity.response.DeviceConfigResponse; @@ -41,7 +42,7 @@ public ConfigDownloadMessageHandler(MessageProcessorClient messageProcessorClien @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java index bbceaacc..1736c8db 100755 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java @@ -2,6 +2,7 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; @@ -13,7 +14,7 @@ import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageProcessorClient; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceInfo; import lombok.extern.slf4j.Slf4j; @@ -40,7 +41,7 @@ public DeviceInfoQueryMessageClientHandler(MessageProcessorClient messageProcess @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java index d45d7ffc..0b6f0570 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java @@ -2,6 +2,7 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import org.springframework.stereotype.Component; @@ -11,7 +12,7 @@ import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageProcessorClient; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceStatus; import lombok.Getter; @@ -42,7 +43,7 @@ public DeviceStatusQueryMessageClientHandler(MessageProcessorClient messageProce @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java index 1c9d58f7..5d513d6b 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java @@ -2,18 +2,18 @@ import javax.sip.RequestEvent; -import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; import org.springframework.stereotype.Component; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceRecordQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceRecord; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd; +import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageProcessorClient; +import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; - import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -36,10 +36,9 @@ public RecordInfoQueryMessageClientHandler(MessageProcessorClient messageProcess super(messageProcessorClient, sipUserGenerateClient); } - @Override public String getRootType() { - return QUERY; + return ClientMessageRequestProcessor.METHOD + QUERY; } @Override diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/SubscribeClientHandlerAbstract.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/SubscribeClientHandlerAbstract.java index a3a36111..6cdd750f 100755 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/SubscribeClientHandlerAbstract.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/SubscribeClientHandlerAbstract.java @@ -6,8 +6,8 @@ import org.springframework.stereotype.Component; import gov.nist.javax.sip.message.SIPRequest; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.sip.common.transmit.event.message.MessageHandlerAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; import lombok.Data; @@ -32,7 +32,7 @@ public SubscribeClientHandlerAbstract(SubscribeProcessorClient subscribeProcesso @Override public String getRootType() { - return "Root"; + return ClientSubscribeRequestProcessor.METHOD + "Root"; } public DeviceSession getDeviceSession(RequestEvent event) { diff --git a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/CatalogQueryMessageHandler.java b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/SubscribeCatalogQueryMessageHandler.java similarity index 84% rename from gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/CatalogQueryMessageHandler.java rename to gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/SubscribeCatalogQueryMessageHandler.java index 48d6066d..f0d7734f 100644 --- a/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/CatalogQueryMessageHandler.java +++ b/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/subscribe/catalog/SubscribeCatalogQueryMessageHandler.java @@ -2,6 +2,7 @@ import javax.sip.RequestEvent; import javax.sip.header.ContentTypeHeader; +import javax.sip.header.EventHeader; import javax.sip.header.ExpiresHeader; import javax.sip.message.Response; @@ -9,7 +10,6 @@ import io.github.lunasaw.sip.common.entity.Device; import io.github.lunasaw.gb28181.common.entity.response.DeviceSubscribe; import io.github.lunasaw.sip.common.enums.ContentTypeEnum; -import io.github.lunasaw.sip.common.service.SipUserGenerate; import io.github.lunasaw.sip.common.transmit.ResponseCmd; import io.github.lunasaw.sip.common.utils.SipRequestUtils; import org.springframework.stereotype.Component; @@ -17,7 +17,7 @@ import gov.nist.javax.sip.message.SIPRequest; import io.github.lunasaw.gbproxy.client.transmit.request.subscribe.SubscribeClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.subscribe.SubscribeProcessorClient; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import io.github.lunasaw.gb28181.common.entity.enums.CmdTypeEnum; import io.github.lunasaw.sip.common.subscribe.SubscribeInfo; @@ -36,11 +36,11 @@ @Slf4j @Getter @Setter -public class CatalogQueryMessageHandler extends SubscribeClientHandlerAbstract { +public class SubscribeCatalogQueryMessageHandler extends SubscribeClientHandlerAbstract { public static final String CMD_TYPE = CmdTypeEnum.CATALOG.getType(); - public CatalogQueryMessageHandler(SubscribeProcessorClient subscribeProcessorClient, SipUserGenerateClient sipUserGenerate) { + public SubscribeCatalogQueryMessageHandler(SubscribeProcessorClient subscribeProcessorClient, SipUserGenerateClient sipUserGenerate) { super(subscribeProcessorClient, sipUserGenerate); } @@ -53,6 +53,13 @@ public String getRootType() { @Override public void handForEvt(RequestEvent event) { DeviceSession deviceSession = getDeviceSession(event); + + EventHeader header = (EventHeader) event.getRequest().getHeader(EventHeader.NAME); + if (header == null){ + log.info("handForEvt::event = {}", event); + return; + } + // 订阅消息过来 String sipId = deviceSession.getSipId(); String userId = deviceSession.getUserId(); diff --git a/gb28181-client/src/test/java/io/github/lunasw/gbproxy/client/test/cmd/ApplicationTest.java b/gb28181-client/src/test/java/io/github/lunasw/gbproxy/client/test/cmd/ApplicationTest.java index 7452177e..0f94c428 100644 --- a/gb28181-client/src/test/java/io/github/lunasw/gbproxy/client/test/cmd/ApplicationTest.java +++ b/gb28181-client/src/test/java/io/github/lunasw/gbproxy/client/test/cmd/ApplicationTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import io.github.lunasaw.gbproxy.client.Gb28181Client; @@ -31,10 +32,12 @@ public class ApplicationTest { static String localIp = "172.19.128.100"; FromDevice fromDevice; ToDevice toDevice; + @Autowired + SipLayer sipLayer; @BeforeEach public void before() { - SipLayer.addListeningPoint(localIp, 8117); + sipLayer.addListeningPoint(localIp, 8117); fromDevice = FromDevice.getInstance("33010602011187000001", localIp, 8117); toDevice = ToDevice.getInstance("41010500002000000001", localIp, 8118); toDevice.setPassword("luna"); diff --git a/gb28181-common/pom.xml b/gb28181-common/pom.xml index 32161445..3596ee87 100644 --- a/gb28181-common/pom.xml +++ b/gb28181-common/pom.xml @@ -6,7 +6,7 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 ${gb28181-proxy.version} diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/ManufacturerEnum.java b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/ManufacturerEnum.java similarity index 89% rename from sip-common/src/main/java/io/github/lunasaw/sip/common/enums/ManufacturerEnum.java rename to gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/ManufacturerEnum.java index 460a969c..b5a81e20 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/ManufacturerEnum.java +++ b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/ManufacturerEnum.java @@ -1,4 +1,4 @@ -package io.github.lunasaw.sip.common.enums; +package io.github.lunasaw.gb28181.common.entity.enums; /** * @author luna diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/StreamModeEnum.java b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/StreamModeEnum.java similarity index 92% rename from sip-common/src/main/java/io/github/lunasaw/sip/common/enums/StreamModeEnum.java rename to gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/StreamModeEnum.java index d22c6112..8ddd8d80 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/StreamModeEnum.java +++ b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/StreamModeEnum.java @@ -1,4 +1,4 @@ -package io.github.lunasaw.sip.common.enums; +package io.github.lunasaw.gb28181.common.entity.enums; /** * @author luna diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/TransModeEnum.java b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/TransModeEnum.java similarity index 76% rename from sip-common/src/main/java/io/github/lunasaw/sip/common/enums/TransModeEnum.java rename to gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/TransModeEnum.java index e1ff93f4..24412b08 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/enums/TransModeEnum.java +++ b/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/enums/TransModeEnum.java @@ -1,6 +1,4 @@ -package io.github.lunasaw.sip.common.enums; - -import io.github.lunasaw.sip.common.constant.Constant; +package io.github.lunasaw.gb28181.common.entity.enums; /** * @author luna @@ -11,8 +9,8 @@ public enum TransModeEnum { /** * 传输模式 */ - UDP(Constant.UDP, "UDP"), - TCP(Constant.TCP, "TCP"), + UDP("UDP", "UDP"), + TCP("TCP", "TCP"), ; diff --git a/gb28181-server/pom.xml b/gb28181-server/pom.xml index 33bcec6d..6f588a26 100644 --- a/gb28181-server/pom.xml +++ b/gb28181-server/pom.xml @@ -6,7 +6,7 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 ${gb28181-proxy.version} diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteEntity.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteEntity.java index a110c8cc..1d28d1b2 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteEntity.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteEntity.java @@ -1,8 +1,8 @@ package io.github.lunasaw.gbproxy.server.entity; import io.github.lunasaw.gb28181.common.entity.enums.InviteSessionNameEnum; -import io.github.lunasaw.sip.common.enums.ManufacturerEnum; -import io.github.lunasaw.sip.common.enums.StreamModeEnum; +import io.github.lunasaw.gb28181.common.entity.enums.ManufacturerEnum; +import io.github.lunasaw.gb28181.common.entity.enums.StreamModeEnum; import org.apache.commons.lang3.StringUtils; /** diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteRequest.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteRequest.java index 8158ca24..7a603c6f 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteRequest.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/entity/InviteRequest.java @@ -1,7 +1,7 @@ package io.github.lunasaw.gbproxy.server.entity; -import io.github.lunasaw.sip.common.enums.ManufacturerEnum; -import io.github.lunasaw.sip.common.enums.StreamModeEnum; +import io.github.lunasaw.gb28181.common.entity.enums.ManufacturerEnum; +import io.github.lunasaw.gb28181.common.entity.enums.StreamModeEnum; import io.github.lunasaw.sip.common.utils.SipUtils; import lombok.Data; diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/cmd/ServerSendCmd.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/cmd/ServerSendCmd.java index 72ca2007..1ca0da42 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/cmd/ServerSendCmd.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/cmd/ServerSendCmd.java @@ -21,7 +21,7 @@ import io.github.lunasaw.gbproxy.server.enums.PlayActionEnums; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.sip.common.enums.StreamModeEnum; +import io.github.lunasaw.gb28181.common.entity.enums.StreamModeEnum; import io.github.lunasaw.sip.common.subscribe.SubscribeInfo; import io.github.lunasaw.sip.common.transmit.SipSender; diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/info/CustomInfoProcessorServer.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/info/CustomInfoProcessorServer.java index 86455a81..25db0de6 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/info/CustomInfoProcessorServer.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/info/CustomInfoProcessorServer.java @@ -1,21 +1,12 @@ package io.github.lunasaw.gbproxy.server.transimit.request.info; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.stereotype.Component; - /** * @author luna * @date 2023/12/29 */ -public class CustomInfoProcessorServer implements InfoProcessorServer, InitializingBean { +public class CustomInfoProcessorServer implements InfoProcessorServer { @Override public void dealInfo(String userId, String content) { } - - @Override - public void afterPropertiesSet() throws Exception { - System.out.println(this); - } } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/BaseMessageServerHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/BaseMessageServerHandler.java index 2ee023f5..ceb3e7d2 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/BaseMessageServerHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/BaseMessageServerHandler.java @@ -40,8 +40,5 @@ public String getCmdType() { return cmdType; } - @Override - public String getRootType() { - return super.getRootType(); - } + } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/MessageServerHandlerAbstract.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/MessageServerHandlerAbstract.java index 31cb157c..24b4295f 100755 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/MessageServerHandlerAbstract.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/MessageServerHandlerAbstract.java @@ -1,17 +1,17 @@ package io.github.lunasaw.gbproxy.server.transimit.request.message; +import javax.annotation.Resource; +import javax.sip.RequestEvent; + +import io.github.lunasaw.sip.common.entity.DeviceSession; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + import gov.nist.javax.sip.message.SIPRequest; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; - import io.github.lunasaw.sip.common.transmit.event.message.MessageHandlerAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; import lombok.Data; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import javax.sip.RequestEvent; /** * @author luna @@ -22,7 +22,7 @@ public abstract class MessageServerHandlerAbstract extends MessageHandlerAbstrac @Resource @Lazy - public MessageProcessorServer messageProcessorServer; + public MessageProcessorServer messageProcessorServer; @Resource protected SipUserGenerateServer sipUserGenerate; @@ -38,7 +38,7 @@ public String getRootType() { } public DeviceSession getDeviceSession(RequestEvent event) { - SIPRequest sipRequest = (SIPRequest) event.getRequest(); + SIPRequest sipRequest = (SIPRequest)event.getRequest(); // 客户端发送的userId String userId = SipUtils.getUserIdFromFromHeader(sipRequest); diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/ServerMessageRequestProcessor.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/ServerMessageRequestProcessor.java index 2ad75f0b..922b8fc5 100755 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/ServerMessageRequestProcessor.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/ServerMessageRequestProcessor.java @@ -34,18 +34,11 @@ public class ServerMessageRequestProcessor extends SipMessageRequestProcessorAbs @Override public void process(RequestEvent evt) { - SIPRequest request = (SIPRequest)evt.getRequest(); - - // 在服务端看来 收到请求的时候fromHeader还是客户端的 toHeader才是自己的,这里是要查询自己的信息 - String sip = SipUtils.getUserIdFromToHeader(request); - - // 获取设备 - FromDevice fromDevice = (FromDevice)sipUserGenerate.getFromDevice(); - if (!sip.equals(fromDevice.getUserId())) { + if (!sipUserGenerate.checkDevice(evt)) { + // 如果是客户端收到的userId,一定是和自己的userId一致 return; } - - doMessageHandForEvt(evt, fromDevice); + doMessageHandForEvt(evt, (FromDevice) sipUserGenerate.getFromDevice()); } } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/AlarmNotifyMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/AlarmNotifyMessageHandler.java index ebe39d14..510cb1e3 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/AlarmNotifyMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/AlarmNotifyMessageHandler.java @@ -3,6 +3,7 @@ import javax.sip.RequestEvent; import io.github.lunasaw.gb28181.common.entity.notify.DeviceAlarmNotify; +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import org.springframework.stereotype.Component; @@ -10,7 +11,7 @@ import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageProcessorServer; import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageServerHandlerAbstract; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -36,7 +37,7 @@ public AlarmNotifyMessageHandler(MessageProcessorServer messageProcessorServer, @Override public String getRootType() { - return NOTIFY; + return ServerMessageRequestProcessor.METHOD + NOTIFY; } @Override diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/KeepaliveNotifyMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/KeepaliveNotifyMessageHandler.java index 7d120328..5b78a7fc 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/KeepaliveNotifyMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/KeepaliveNotifyMessageHandler.java @@ -4,10 +4,11 @@ import javax.sip.message.Response; import gov.nist.javax.sip.message.SIPRequest; +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import io.github.lunasaw.sip.common.entity.RemoteAddressInfo; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceKeepLiveNotify; import io.github.lunasaw.sip.common.transmit.ResponseCmd; @@ -39,7 +40,7 @@ public KeepaliveNotifyMessageHandler(MessageProcessorServer messageProcessorServ @Override public String getRootType() { - return NOTIFY; + return ServerMessageRequestProcessor.METHOD + NOTIFY; } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MediaStatusNotifyMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MediaStatusNotifyMessageHandler.java index 664909a8..e07c831c 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MediaStatusNotifyMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MediaStatusNotifyMessageHandler.java @@ -2,6 +2,7 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import org.springframework.stereotype.Component; @@ -9,7 +10,7 @@ import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageProcessorServer; import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageServerHandlerAbstract; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.MediaStatusNotify; import lombok.Getter; import lombok.Setter; @@ -36,7 +37,7 @@ public MediaStatusNotifyMessageHandler(MessageProcessorServer messageProcessorSe @Override public String getRootType() { - return NOTIFY; + return ServerMessageRequestProcessor.METHOD + NOTIFY; } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MobilePositionNotifyMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MobilePositionNotifyMessageHandler.java index 5bc7183d..80e455a3 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MobilePositionNotifyMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/notify/MobilePositionNotifyMessageHandler.java @@ -2,9 +2,10 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.MobilePositionNotify; import org.springframework.stereotype.Component; @@ -36,7 +37,7 @@ public MobilePositionNotifyMessageHandler(MessageProcessorServer messageProcesso @Override public String getRootType() { - return NOTIFY; + return ServerMessageRequestProcessor.METHOD + NOTIFY; } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/RecordInfoMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/RecordInfoMessageHandler.java index d4f08bbf..a4fd5caf 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/RecordInfoMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/RecordInfoMessageHandler.java @@ -2,15 +2,15 @@ import javax.sip.RequestEvent; -import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; -import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; -import io.github.lunasaw.gb28181.common.entity.response.DeviceRecord; - +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; +import io.github.lunasaw.sip.common.entity.DeviceSession; import org.springframework.stereotype.Component; +import io.github.lunasaw.gb28181.common.entity.response.DeviceRecord; import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageProcessorServer; import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageServerHandlerAbstract; +import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; +import io.github.lunasaw.sip.common.entity.ToDevice; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -35,7 +35,7 @@ public RecordInfoMessageHandler(MessageProcessorServer messageProcessorServer, S @Override public String getRootType() { - return RESPONSE; + return ServerMessageRequestProcessor.METHOD + RESPONSE; } @Override diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/ResponseCatalogMessageHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/ResponseCatalogMessageHandler.java index 22a55bde..1e952d3a 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/ResponseCatalogMessageHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/message/response/ResponseCatalogMessageHandler.java @@ -2,9 +2,10 @@ import javax.sip.RequestEvent; +import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import io.github.lunasaw.sip.common.entity.ToDevice; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.response.DeviceResponse; import org.springframework.stereotype.Component; @@ -55,6 +56,6 @@ public String getCmdType() { @Override public String getRootType() { - return RESPONSE; + return ServerMessageRequestProcessor.METHOD + RESPONSE; } } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/NotifyServerHandlerAbstract.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/NotifyServerHandlerAbstract.java index a92df569..71fbb5db 100755 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/NotifyServerHandlerAbstract.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/NotifyServerHandlerAbstract.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; import gov.nist.javax.sip.message.SIPRequest; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; import io.github.lunasaw.sip.common.transmit.event.message.MessageHandlerAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/ServerNotifyRequestProcessor.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/ServerNotifyRequestProcessor.java index 8f5040a1..5d7a3256 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/ServerNotifyRequestProcessor.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/ServerNotifyRequestProcessor.java @@ -40,18 +40,12 @@ public class ServerNotifyRequestProcessor extends SipMessageRequestProcessorAbst */ @Override public void process(RequestEvent evt) { - SIPRequest request = (SIPRequest)evt.getRequest(); - - // 在服务端看来 收到请求的时候fromHeader还是客户端的 toHeader才是自己的,这里是要查询自己的信息 - String userId = SipUtils.getUserIdFromToHeader(request); - - // 获取设备 - FromDevice fromDevice = (FromDevice)sipUserGenerate.getFromDevice(); - if (!userId.equals(fromDevice.getUserId())) { + if (!sipUserGenerate.checkDevice(evt)) { + // 如果是客户端收到的userId,一定是和自己的userId一致 return; } - doMessageHandForEvt(evt, fromDevice); + doMessageHandForEvt(evt, (FromDevice) sipUserGenerate.getFromDevice()); } } diff --git a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/catalog/CatalogNotifyHandler.java b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/catalog/CatalogNotifyHandler.java index 96c47db4..7922401b 100644 --- a/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/catalog/CatalogNotifyHandler.java +++ b/gb28181-server/src/main/java/io/github/lunasaw/gbproxy/server/transimit/request/notify/catalog/CatalogNotifyHandler.java @@ -2,15 +2,12 @@ import javax.sip.RequestEvent; -import io.github.lunasaw.gbproxy.server.transimit.request.notify.NotifyProcessorServer; -import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer; - import org.springframework.stereotype.Component; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceOtherUpdateNotify; -import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageProcessorServer; import io.github.lunasaw.gbproxy.server.transimit.request.notify.NotifyServerHandlerAbstract; +import io.github.lunasaw.gbproxy.server.transimit.request.notify.ServerNotifyRequestProcessor; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.sip.common.entity.ToDevice; import lombok.Getter; import lombok.Setter; @@ -28,7 +25,6 @@ public class CatalogNotifyHandler extends NotifyServerHandlerAbstract { public static final String CMD_TYPE = "Catalog"; - @Override public void handForEvt(RequestEvent event) { DeviceSession deviceSession = getDeviceSession(event); @@ -52,6 +48,6 @@ public String getCmdType() { @Override public String getRootType() { - return RESPONSE; + return ServerNotifyRequestProcessor.METHOD + RESPONSE; } } diff --git a/gb28181-server/src/test/java/io/github/lunasaw/gbproxy/server/cmd/Applicationtest.java b/gb28181-server/src/test/java/io/github/lunasaw/gbproxy/server/cmd/Applicationtest.java index ba1265ee..c8801121 100644 --- a/gb28181-server/src/test/java/io/github/lunasaw/gbproxy/server/cmd/Applicationtest.java +++ b/gb28181-server/src/test/java/io/github/lunasaw/gbproxy/server/cmd/Applicationtest.java @@ -7,6 +7,7 @@ import io.github.lunasaw.sip.common.layer.SipLayer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; /** @@ -23,9 +24,12 @@ public class Applicationtest { static String localIp = "172.19.128.100"; + @Autowired + SipLayer sipLayer; + @BeforeEach public void before() { - SipLayer.addListeningPoint(localIp, 8117); + sipLayer.addListeningPoint(localIp, 8117); fromDevice = FromDevice.getInstance("41010500002000000001", localIp, 8117); toDevice = ToDevice.getInstance("33010602011187000001", localIp, 8118); toDevice.setPassword("luna"); diff --git a/gb28181-test/pom.xml b/gb28181-test/pom.xml index c4a43339..914cacc5 100644 --- a/gb28181-test/pom.xml +++ b/gb28181-test/pom.xml @@ -6,7 +6,7 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 ${gb28181-proxy.version} diff --git a/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/config/DeviceConfig.java b/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/config/DeviceConfig.java index b7736573..4930bb6d 100644 --- a/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/config/DeviceConfig.java +++ b/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/config/DeviceConfig.java @@ -20,7 +20,7 @@ @Configuration public class DeviceConfig { - public static final String LOOP_IP = SystemInfoUtil.getIpv4(); + public static final String LOOP_IP = "192.168.2.101"; public static final String LOOP_IP_LOCAL = "0.0.0.0"; diff --git a/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/user/client/DefaultRegisterProcessorClient.java b/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/user/client/DefaultRegisterProcessorClient.java index 073d12e3..1080728d 100644 --- a/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/user/client/DefaultRegisterProcessorClient.java +++ b/gb28181-test/src/main/java/io/github/lunasaw/gbproxy/test/user/client/DefaultRegisterProcessorClient.java @@ -2,10 +2,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -16,6 +14,8 @@ import io.github.lunasaw.sip.common.entity.Device; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; +import io.github.lunasaw.sip.common.utils.DynamicTask; +import lombok.extern.slf4j.Slf4j; /** * @author luna @@ -25,14 +25,18 @@ @Component public class DefaultRegisterProcessorClient implements RegisterProcessorClient { - public static Boolean isRegister = true; + private static final String KEEPALIVE = "keepalive"; /** * 心跳定时任务线程池 */ private static final ScheduledExecutorService taskExecutor = Executors.newScheduledThreadPool(1); + public static Boolean isRegister = true; @Autowired @Qualifier("clientFrom") - private Device fromDevice; + private Device fromDevice; + + @Autowired + private DynamicTask dynamicTask; @Override public Integer getExpire(String userId) { @@ -42,26 +46,23 @@ public Integer getExpire(String userId) { @Override public void registerSuccess(String toUserId) { // 定时任务 每分钟执行一次 - ScheduledFuture future = taskExecutor.scheduleWithFixedDelay( - () -> { - if (!isRegister) { - return; - } - try { - ClientSendCmd.deviceKeepLiveNotify((FromDevice)fromDevice, (ToDevice)DeviceConfig.DEVICE_CLIENT_VIEW_MAP.get(toUserId), "OK", - eventResult -> { - // 注册 - log.error("心跳失败 发起注册 registerSuccess::toUserId = {} ", toUserId); - ClientSendCmd.deviceRegister((FromDevice)fromDevice, (ToDevice)DeviceConfig.DEVICE_CLIENT_VIEW_MAP.get(toUserId), 300); - }); - } catch (Exception e) { - e.printStackTrace(); + dynamicTask.startCron(KEEPALIVE, + () -> { + if (!isRegister) { + return; } - }, 30, 60, TimeUnit.SECONDS); + ClientSendCmd.deviceKeepLiveNotify((FromDevice)fromDevice, (ToDevice)DeviceConfig.DEVICE_CLIENT_VIEW_MAP.get(toUserId), "OK", + eventResult -> { + dynamicTask.stop(KEEPALIVE); + // 注册 + log.error("心跳失败 发起注册 registerSuccess::toUserId = {} ", toUserId); + ClientSendCmd.deviceRegister((FromDevice)fromDevice, (ToDevice)DeviceConfig.DEVICE_CLIENT_VIEW_MAP.get(toUserId), 300); + }); + }, 60, TimeUnit.SECONDS); if (!isRegister) { // 注销 - future.cancel(false); + dynamicTask.stop(KEEPALIVE); } } } diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181Test.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181Test.java index 1e2a70cc..625597c7 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181Test.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181Test.java @@ -36,10 +36,13 @@ public class Gb28181Test { @Qualifier("clientTo") private Device toDevice; + @Autowired + private SipLayer sipLayer; + @BeforeEach public void before() { // 本地端口监听 - SipLayer.addListeningPoint(fromDevice.getIp(), fromDevice.getPort()); + sipLayer.addListeningPoint(fromDevice.getIp(), fromDevice.getPort()); } diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestClient.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestClient.java index 3f0f48ff..92317f93 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestClient.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestClient.java @@ -40,6 +40,9 @@ public class Gb28181TestClient { @Qualifier("clientTo") private Device toDevice; + @Autowired + private SipLayer sipLayer; + @AfterAll public static void after() { while (true) { @@ -51,7 +54,7 @@ public static void after() { public void before() { // 本地端口监听 log.info("before::客户端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort(), true); + sipLayer.addListeningPoint("192.168.2.101", fromDevice.getPort(), true); DeviceConfig.DEVICE_CLIENT_VIEW_MAP.put(toDevice.getUserId(), toDevice); diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestServer.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestServer.java index 3ce90954..fdaf98eb 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestServer.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/Gb28181TestServer.java @@ -42,11 +42,14 @@ public class Gb28181TestServer { @Autowired private DynamicTask dynamicTask; + @Autowired + private SipLayer sipLayer; + @BeforeEach public void before() { // 本地端口监听 log.info("before::服务端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); } @Test diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ClientInviteTest.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ClientInviteTest.java index 28c1160a..3b47ab39 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ClientInviteTest.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ClientInviteTest.java @@ -38,6 +38,9 @@ public class ClientInviteTest { @Qualifier("clientTo") private Device toDevice; + @Autowired + private SipLayer sipLayer; + @AfterAll public static void after() { while (true) { @@ -49,7 +52,7 @@ public static void after() { public void before() { // 本地端口监听 log.info("before::客户端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort()); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort()); // 模拟平台添加 DeviceConfig.DEVICE_CLIENT_VIEW_MAP.put(toDevice.getUserId(), toDevice); } diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ServerInviteTest.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ServerInviteTest.java index 928bd6c1..091dfb02 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ServerInviteTest.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/invite/ServerInviteTest.java @@ -1,6 +1,5 @@ package io.github.lunasaw.gbproxy.test.invite; -import io.github.lunasaw.sip.common.entity.Device; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -11,6 +10,7 @@ import io.github.lunasaw.gbproxy.server.transimit.cmd.ServerSendCmd; import io.github.lunasaw.gbproxy.test.Gb28181ApplicationTest; import io.github.lunasaw.gbproxy.test.config.DeviceConfig; +import io.github.lunasaw.sip.common.entity.Device; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; import io.github.lunasaw.sip.common.layer.SipLayer; @@ -33,10 +33,13 @@ public class ServerInviteTest { @Autowired private DynamicTask dynamicTask; + @Autowired + private SipLayer sipLayer; + @BeforeEach public void before() { // 本地端口监听 - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); } @Test diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/register/RegisterClientTest.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/register/RegisterClientTest.java index 07c98493..669d91a3 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/register/RegisterClientTest.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/register/RegisterClientTest.java @@ -2,8 +2,6 @@ import javax.sip.message.Request; -import io.github.lunasaw.gbproxy.test.Gb28181ApplicationTest; -import io.github.lunasaw.gbproxy.test.config.DeviceConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -11,6 +9,8 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; +import io.github.lunasaw.gbproxy.test.Gb28181ApplicationTest; +import io.github.lunasaw.gbproxy.test.config.DeviceConfig; import io.github.lunasaw.sip.common.entity.Device; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.entity.ToDevice; @@ -32,11 +32,14 @@ public class RegisterClientTest { @Autowired @Qualifier("clientFrom") - private Device fromDevice; + private Device fromDevice; @Autowired @Qualifier("clientTo") - private Device toDevice; + private Device toDevice; + + @Autowired + private SipLayer sipLayer; @AfterAll public static void after() { @@ -49,7 +52,7 @@ public static void after() { public void before() { // 本地端口监听 log.info("before::客户端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort()); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort()); } diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeClientTest.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeClientTest.java index b0f846bc..b4f144d3 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeClientTest.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeClientTest.java @@ -32,6 +32,9 @@ public class SubscribeClientTest { @Qualifier("clientTo") private Device toDevice; + @Autowired + private SipLayer sipLayer; + @AfterAll public static void after() { while (true) { @@ -43,7 +46,7 @@ public static void after() { public void before() { // 本地端口监听 log.info("before::客户端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort(), true); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, fromDevice.getPort(), true); DeviceConfig.DEVICE_CLIENT_VIEW_MAP.put(toDevice.getUserId(), toDevice); diff --git a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeServerTest.java b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeServerTest.java index 8d87450c..cd86edc4 100644 --- a/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeServerTest.java +++ b/gb28181-test/src/test/java/io/github/lunasaw/gbproxy/test/subscribe/SubscribeServerTest.java @@ -38,11 +38,14 @@ public class SubscribeServerTest { @Autowired private DynamicTask dynamicTask; + @Autowired + private SipLayer sipLayer; + @BeforeEach public void before() { // 本地端口监听 log.info("before::服务端初始化 fromDevice.ip : {} , fromDevice.port : {}", fromDevice.getIp(), fromDevice.getPort()); - SipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); + sipLayer.addListeningPoint(DeviceConfig.LOOP_IP, 8117, true); } @Test diff --git a/pom.xml b/pom.xml index d9163ce9..86db41df 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 pom sip-common @@ -28,8 +28,9 @@ ${project.name} 1.3.0-91 2.1.4 - 1.1.5 - 1.1.5 + 1.1.6 + 1.1.6 + 9.1.0 diff --git a/sip-common/pom.xml b/sip-common/pom.xml index 7433b8d6..290495fb 100644 --- a/sip-common/pom.xml +++ b/sip-common/pom.xml @@ -6,11 +6,11 @@ io.github.lunasaw sip-proxy - 1.1.5 + 1.1.6 jar - 1.1.5 + 1.1.6 sip-common sip-common 轻量级SIP框架封装 @@ -39,6 +39,13 @@ org.slf4j log4j-over-slf4j + + + + org.apache.skywalking + apm-toolkit-trace + ${skywalking.version} + diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/DefaultProperties.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/DefaultProperties.java index 3dc5916f..85cad940 100755 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/DefaultProperties.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/DefaultProperties.java @@ -1,9 +1,12 @@ package io.github.lunasaw.sip.common.conf; import java.io.File; +import java.io.InputStream; import java.nio.file.Files; import java.util.Properties; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.util.ResourceUtils; import lombok.extern.slf4j.Slf4j; @@ -29,8 +32,9 @@ public static Properties getProperties(String name, String ip, boolean sipLog) { * sip_server_log.log 和 sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE */ try { - File configFile = ResourceUtils.getFile("classpath:sip/config.properties").getAbsoluteFile(); - properties.load(Files.newInputStream(configFile.toPath())); + Resource resource = new ClassPathResource("sip/config.properties"); + InputStream inputStream = resource.getInputStream(); + properties.load(inputStream); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/SipProxyAutoConfig.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/SipProxyAutoConfig.java index 8bfc1478..1d645c88 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/SipProxyAutoConfig.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/conf/SipProxyAutoConfig.java @@ -3,15 +3,18 @@ import java.lang.reflect.Field; import java.util.Map; -import io.github.lunasaw.sip.common.transmit.event.message.MessageHandler; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; +import io.github.lunasaw.sip.common.transmit.CustomSipProcessorInject; +import io.github.lunasaw.sip.common.transmit.SipProcessorInject; import io.github.lunasaw.sip.common.transmit.SipProcessorObserver; import io.github.lunasaw.sip.common.transmit.event.request.SipRequestProcessor; import io.github.lunasaw.sip.common.transmit.event.request.SipRequestProcessorAbstract; @@ -31,13 +34,13 @@ public class SipProxyAutoConfig implements InitializingBean, ApplicationContextA private static final String METHOD = "method"; - private ApplicationContext applicationContext; + private ApplicationContext applicationContext; @Override public void afterPropertiesSet() { // 获取所有的SipResponseProcessorAbstract bean Map responseProcessorAbstractMap = - applicationContext.getBeansOfType(SipResponseProcessor.class); + applicationContext.getBeansOfType(SipResponseProcessor.class); responseProcessorAbstractMap.forEach((k, v) -> { try { @@ -72,4 +75,10 @@ public void afterPropertiesSet() { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } + + @Bean + @ConditionalOnMissingBean + public SipProcessorInject sipProcessorInject() { + return new CustomSipProcessorInject(); + } } diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/constant/Constant.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/constant/Constant.java index a2a27066..978d4bb3 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/constant/Constant.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/constant/Constant.java @@ -6,9 +6,9 @@ */ public class Constant { - public static final String TCP = "tcp"; + public static final String TCP = "TCP"; - public static final String UDP = "udp"; + public static final String UDP = "UDP"; public static final String AGENT = "LunaSaw-GB28181-Proxy"; diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/DeviceSession.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/DeviceSession.java index e27c9863..5cf425fd 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/DeviceSession.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/DeviceSession.java @@ -1,4 +1,4 @@ -package io.github.lunasaw.gb28181.common.entity.base; +package io.github.lunasaw.sip.common.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/FromDevice.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/FromDevice.java index 39bdbea3..803aec2f 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/FromDevice.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/FromDevice.java @@ -1,8 +1,7 @@ package io.github.lunasaw.sip.common.entity; import io.github.lunasaw.sip.common.constant.Constant; -import io.github.lunasaw.sip.common.enums.StreamModeEnum; -import io.github.lunasaw.sip.common.enums.TransModeEnum; + import io.github.lunasaw.sip.common.utils.SipRequestUtils; import lombok.Data; @@ -31,8 +30,8 @@ public static FromDevice getInstance(String userId, String ip, int port) { fromDevice.setUserId(userId); fromDevice.setIp(ip); fromDevice.setPort(port); - fromDevice.setTransport(TransModeEnum.UDP.getType()); - fromDevice.setStreamMode(StreamModeEnum.TCP_PASSIVE.getType()); + fromDevice.setTransport("UDP"); + fromDevice.setStreamMode("TCP_PASSIVE"); fromDevice.setFromTag(SipRequestUtils.getNewFromTag()); fromDevice.setAgent(Constant.AGENT); return fromDevice; diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/ToDevice.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/ToDevice.java index c5ed2a50..c39264f3 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/ToDevice.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/entity/ToDevice.java @@ -1,7 +1,5 @@ package io.github.lunasaw.sip.common.entity; -import io.github.lunasaw.sip.common.enums.StreamModeEnum; -import io.github.lunasaw.sip.common.enums.TransModeEnum; import lombok.Data; /** @@ -33,8 +31,8 @@ public static ToDevice getInstance(String userId, String ip, int port) { toDevice.setUserId(userId); toDevice.setIp(ip); toDevice.setPort(port); - toDevice.setTransport(TransModeEnum.UDP.getType()); - toDevice.setStreamMode(StreamModeEnum.TCP_PASSIVE.getType()); + toDevice.setTransport("UDP"); + toDevice.setStreamMode("TCP_PASSIVE"); toDevice.setToTag(null); return toDevice; } diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/layer/SipLayer.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/layer/SipLayer.java index fb446b74..b9b67ccb 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/layer/SipLayer.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/layer/SipLayer.java @@ -1,5 +1,18 @@ package io.github.lunasaw.sip.common.layer; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TooManyListenersException; +import java.util.concurrent.ConcurrentHashMap; + +import javax.sip.*; + +import org.assertj.core.util.Lists; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + import gov.nist.javax.sip.SipProviderImpl; import gov.nist.javax.sip.SipStackImpl; import io.github.lunasaw.sip.common.conf.DefaultProperties; @@ -7,27 +20,20 @@ import io.github.lunasaw.sip.common.transmit.SipProcessorObserver; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.assertj.core.util.Lists; -import org.springframework.util.ObjectUtils; - -import javax.sip.*; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.TooManyListenersException; -import java.util.concurrent.ConcurrentHashMap; /** * @author luna */ @Slf4j +@Component public class SipLayer { private static final Map tcpSipProviderMap = new ConcurrentHashMap<>(); private static final Map udpSipProviderMap = new ConcurrentHashMap<>(); - @Getter - private static final List monitorIpList = Lists.newArrayList("0.0.0.0"); + private static final List monitorIpList = Lists.newArrayList("0.0.0.0"); + @Autowired + private SipProcessorObserver sipProcessorObserver; public static SipProviderImpl getUdpSipProvider(String ip) { if (ObjectUtils.isEmpty(ip)) { @@ -57,23 +63,27 @@ public static SipProviderImpl getTcpSipProvider(String ip) { return tcpSipProviderMap.get(ip); } - public static void addListeningPoint(String monitorIp, int port) { + public static String getMonitorIp() { + return monitorIpList.get(0); + } + + public void addListeningPoint(String monitorIp, int port) { monitorIpList.add(monitorIp); - addListeningPoint(monitorIp, port, new SipProcessorObserver(), true); + addListeningPoint(monitorIp, port, sipProcessorObserver, true); } - public static void addListeningPoint(String monitorIp, int port, Boolean enableLog) { + public void addListeningPoint(String monitorIp, int port, Boolean enableLog) { monitorIpList.add(monitorIp); - addListeningPoint(monitorIp, port, new SipProcessorObserver(), enableLog); + addListeningPoint(monitorIp, port, sipProcessorObserver, enableLog); } - public synchronized static void addListeningPoint(String monitorIp, int port, SipListener listener, Boolean enableLog) { + public synchronized void addListeningPoint(String monitorIp, int port, SipListener listener, Boolean enableLog) { SipStackImpl sipStack; try { Properties properties = DefaultProperties.getProperties("GB28181_SIP", monitorIp, enableLog); SipFactory sipFactory = SipFactory.getInstance(); sipFactory.setPathName("gov.nist"); - sipStack = (SipStackImpl) sipFactory.createSipStack(properties); + sipStack = (SipStackImpl)sipFactory.createSipStack(properties); sipStack.setMessageParserFactory(new StringMsgParserFactory()); } catch (PeerUnavailableException e) { log.error("[SIP SERVER] SIP服务启动失败, 监听地址{}失败,请检查ip是否正确", monitorIp, e); @@ -83,42 +93,36 @@ public synchronized static void addListeningPoint(String monitorIp, int port, Si try { ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(monitorIp, port, "TCP"); - SipProviderImpl tcpSipProvider = (SipProviderImpl) sipStack.createSipProvider(tcpListeningPoint); + SipProviderImpl tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint); tcpSipProvider.setDialogErrorsAutomaticallyHandled(); tcpSipProvider.addSipListener(listener); tcpSipProviderMap.put(monitorIp, tcpSipProvider); log.info("[SIP SERVER] tcp://{}:{} 启动成功", monitorIp, port); } catch (TransportNotSupportedException - | TooManyListenersException - | ObjectInUseException - | InvalidArgumentException e) { - log.error("[SIP SERVER] tcp://{}:{} SIP服务启动失败,请检查端口是否被占用或者ip是否正确" - , monitorIp, port); + | TooManyListenersException + | ObjectInUseException + | InvalidArgumentException e) { + log.error("[SIP SERVER] tcp://{}:{} SIP服务启动失败,请检查端口是否被占用或者ip是否正确", monitorIp, port); } try { ListeningPoint udpListeningPoint = sipStack.createListeningPoint(monitorIp, port, "UDP"); - SipProviderImpl udpSipProvider = (SipProviderImpl) sipStack.createSipProvider(udpListeningPoint); + SipProviderImpl udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint); udpSipProvider.addSipListener(listener); udpSipProviderMap.put(monitorIp, udpSipProvider); log.info("[SIP SERVER] udp://{}:{} 启动成功", monitorIp, port); } catch (TransportNotSupportedException - | TooManyListenersException - | ObjectInUseException - | InvalidArgumentException e) { - log.error("[SIP SERVER] udp://{}:{} SIP服务启动失败,请检查端口是否被占用或者ip是否正确" - , monitorIp, port); + | TooManyListenersException + | ObjectInUseException + | InvalidArgumentException e) { + log.error("[SIP SERVER] udp://{}:{} SIP服务启动失败,请检查端口是否被占用或者ip是否正确", monitorIp, port); } } - public static String getMonitorIp() { - return monitorIpList.get(0); - } - public String getLocalIp(String deviceLocalIp) { if (!ObjectUtils.isEmpty(deviceLocalIp)) { return deviceLocalIp; diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/subscribe/SubscribeHolder.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/subscribe/SubscribeHolder.java index 2357edc7..e29febbf 100755 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/subscribe/SubscribeHolder.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/subscribe/SubscribeHolder.java @@ -52,7 +52,7 @@ public void putMobilePositionSubscribe(String userId, String prefixKey, Subscrib mobilePositionMap.put(userId, subscribeInfo); String key = prefixKey + userId; // 添加任务处理GPS定时推送 - dynamicTask.startCron(key, task, subscribeInfo.getGpsInterval() * 1000); + dynamicTask.startCron(key, task, subscribeInfo.getGpsInterval() * 1000L); String taskOverdueKey = taskOverduePrefix + prefixKey + userId; // 添加任务处理订阅过期 dynamicTask.startDelay(taskOverdueKey, () -> { diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/CustomSipProcessorInject.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/CustomSipProcessorInject.java new file mode 100644 index 00000000..5d39af9f --- /dev/null +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/CustomSipProcessorInject.java @@ -0,0 +1,21 @@ +package io.github.lunasaw.sip.common.transmit; + +import java.util.EventObject; + +/** + * @author luna + * @date 2023/12/29 + */ +public class CustomSipProcessorInject implements SipProcessorInject { + + + @Override + public void before(EventObject eventObject) { + + } + + @Override + public void after() { + + } +} diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorInject.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorInject.java new file mode 100644 index 00000000..b7ebfe41 --- /dev/null +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorInject.java @@ -0,0 +1,14 @@ +package io.github.lunasaw.sip.common.transmit; + +import java.util.EventObject; + +/** + * @author luna + * @date 2023/12/29 + */ +public interface SipProcessorInject { + + void before(EventObject eventObject); + + void after(); +} diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorObserver.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorObserver.java index 920c73a9..024d4924 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorObserver.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/SipProcessorObserver.java @@ -22,6 +22,9 @@ import io.github.lunasaw.sip.common.transmit.event.response.SipResponseProcessor; import io.github.lunasaw.sip.common.transmit.event.timeout.ITimeoutProcessor; import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.apm.toolkit.trace.Trace; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * SIP信令处理类观察者 @@ -29,8 +32,12 @@ * @author luna */ @Slf4j +@Component public class SipProcessorObserver implements SipListener { + @Autowired + private SipProcessorInject sipProcessorInject; + /** * 对SIP事件进行处理 */ @@ -86,7 +93,10 @@ public synchronized static void addTimeoutProcessor(String method, ITimeoutProce * @param requestEvent RequestEvent事件 */ @Override + @Trace(operationName = "processRequest") public void processRequest(RequestEvent requestEvent) { + sipProcessorInject.before(requestEvent); + String method = requestEvent.getRequest().getMethod(); List sipRequestProcessors = REQUEST_PROCESSOR_MAP.get(method); if (CollectionUtils.isEmpty(sipRequestProcessors)) { @@ -101,6 +111,8 @@ public void processRequest(RequestEvent requestEvent) { } catch (Exception e) { log.error("processRequest::requestEvent = {} ", requestEvent, e); } + + sipProcessorInject.after(); } /** @@ -109,7 +121,10 @@ public void processRequest(RequestEvent requestEvent) { * @param responseEvent responseEvent事件 */ @Override + @Trace(operationName = "responseEvent") public void processResponse(ResponseEvent responseEvent) { + sipProcessorInject.before(responseEvent); + Response response = responseEvent.getResponse(); int status = response.getStatusCode(); @@ -145,6 +160,7 @@ public void processResponse(ResponseEvent responseEvent) { } } + sipProcessorInject.after(); } /** diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/MessageHandlerAbstract.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/MessageHandlerAbstract.java index 32d81c04..c73b63e5 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/MessageHandlerAbstract.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/MessageHandlerAbstract.java @@ -5,13 +5,13 @@ import javax.sip.RequestEvent; import javax.sip.message.Response; -import io.github.lunasaw.gb28181.common.entity.base.DeviceSession; import org.apache.commons.lang3.StringUtils; import com.luna.common.text.StringTools; import gov.nist.javax.sip.message.SIPRequest; import io.github.lunasaw.sip.common.constant.Constant; +import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.sip.common.transmit.ResponseCmd; import io.github.lunasaw.sip.common.utils.XmlUtils; import lombok.Getter; @@ -23,6 +23,25 @@ public class MessageHandlerAbstract implements MessageHandler { private String xmlStr; + public static T parseRequest(RequestEvent event, String charset, Class clazz) { + SIPRequest sipRequest = (SIPRequest)event.getRequest(); + byte[] rawContent = sipRequest.getRawContent(); + if (StringUtils.isBlank(charset)) { + charset = Constant.UTF_8; + } + String xmlStr = StringTools.toEncodedString(rawContent, Charset.forName(charset)); + Object o = XmlUtils.parseObj(xmlStr, clazz); + return (T)o; + } + + public static String parseRequest(RequestEvent event, String charset) { + SIPRequest sipRequest = (SIPRequest)event.getRequest(); + byte[] rawContent = sipRequest.getRawContent(); + if (StringUtils.isBlank(charset)) { + charset = Constant.UTF_8; + } + return StringTools.toEncodedString(rawContent, Charset.forName(charset)); + } @Override public void handForEvt(RequestEvent event) { @@ -65,26 +84,6 @@ public T parseXml(Class clazz) { if (StringUtils.isBlank(xmlStr)) { return null; } - return (T) XmlUtils.parseObj(xmlStr, clazz); - } - - public static T parseRequest(RequestEvent event, String charset, Class clazz) { - SIPRequest sipRequest = (SIPRequest) event.getRequest(); - byte[] rawContent = sipRequest.getRawContent(); - if (StringUtils.isBlank(charset)) { - charset = Constant.UTF_8; - } - String xmlStr = StringTools.toEncodedString(rawContent, Charset.forName(charset)); - Object o = XmlUtils.parseObj(xmlStr, clazz); - return (T) o; - } - - public static String parseRequest(RequestEvent event, String charset) { - SIPRequest sipRequest = (SIPRequest) event.getRequest(); - byte[] rawContent = sipRequest.getRawContent(); - if (StringUtils.isBlank(charset)) { - charset = Constant.UTF_8; - } - return StringTools.toEncodedString(rawContent, Charset.forName(charset)); + return (T)XmlUtils.parseObj(xmlStr, clazz); } } diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/SipMessageRequestProcessorAbstract.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/SipMessageRequestProcessorAbstract.java index 77eb8275..a83e574b 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/SipMessageRequestProcessorAbstract.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/transmit/event/message/SipMessageRequestProcessorAbstract.java @@ -44,7 +44,7 @@ public static void addHandler(MessageHandler messageHandler) { } public void doMessageHandForEvt(RequestEvent evt, FromDevice fromDevice) { - SIPRequest request = (SIPRequest) evt.getRequest(); + SIPRequest request = (SIPRequest)evt.getRequest(); String charset = Optional.of(fromDevice).map(Device::getCharset).orElse(Constant.UTF_8); @@ -52,10 +52,10 @@ public void doMessageHandForEvt(RequestEvent evt, FromDevice fromDevice) { byte[] rawContent = request.getRawContent(); String xmlStr = StringTools.toEncodedString(rawContent, Charset.forName(charset)); - String cmdType = XmlUtils.getCmdType(xmlStr); String rootType = XmlUtils.getRootType(xmlStr); - Map messageHandlerMap = MESSAGE_HANDLER_CMD_MAP.get(rootType); + String method = request.getMethod(); + Map messageHandlerMap = MESSAGE_HANDLER_CMD_MAP.get(method + rootType); if (MapUtils.isEmpty(messageHandlerMap)) { return; @@ -77,5 +77,4 @@ public void doMessageHandForEvt(RequestEvent evt, FromDevice fromDevice) { } } - } diff --git a/sip-common/src/main/java/io/github/lunasaw/sip/common/utils/DynamicTask.java b/sip-common/src/main/java/io/github/lunasaw/sip/common/utils/DynamicTask.java index b56ee4b3..b1c72cd0 100644 --- a/sip-common/src/main/java/io/github/lunasaw/sip/common/utils/DynamicTask.java +++ b/sip-common/src/main/java/io/github/lunasaw/sip/common/utils/DynamicTask.java @@ -24,31 +24,34 @@ @Component public class DynamicTask { - private final Logger logger = LoggerFactory.getLogger(DynamicTask.class); - - private ThreadPoolTaskScheduler threadPoolTaskScheduler; - - private final Map> futureMap = new ConcurrentHashMap<>(); - private final Map runnableMap = new ConcurrentHashMap<>(); + private final Logger logger = LoggerFactory.getLogger(DynamicTask.class); + private final Map> futureMap = new ConcurrentHashMap<>(); + private final Map runnableMap = new ConcurrentHashMap<>(); + private ThreadPoolTaskScheduler threadPoolTaskScheduler; @PostConstruct public void DynamicTask() { threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); - threadPoolTaskScheduler.setPoolSize(300); + threadPoolTaskScheduler.setPoolSize(200); threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true); threadPoolTaskScheduler.setAwaitTerminationSeconds(10); threadPoolTaskScheduler.initialize(); } + public void startCron(String key, Runnable task, Integer duration, TimeUnit timeUnit) { + long convert = TimeUnit.MILLISECONDS.convert(duration, timeUnit); + startCron(key, task, convert); + } + /** * 循环执行的任务 * - * @param key 任务ID - * @param task 任务 - * @param cycleForCatalog 间隔 毫秒 + * @param key 任务ID + * @param task 任务 + * @param time 间隔 毫秒 * @return */ - public void startCron(String key, Runnable task, int cycleForCatalog) { + public void startCron(String key, Runnable task, long time) { if (ObjectUtils.isEmpty(key)) { return; } @@ -61,8 +64,8 @@ public void startCron(String key, Runnable task, int cycleForCatalog) { return; } } - // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔 - future = threadPoolTaskScheduler.scheduleAtFixedRate(task, cycleForCatalog); + // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, time表示执行的间隔 + future = threadPoolTaskScheduler.scheduleAtFixedRate(task, time); if (future != null) { futureMap.put(key, future); runnableMap.put(key, task); @@ -75,8 +78,8 @@ public void startCron(String key, Runnable task, int cycleForCatalog) { /** * 延时任务 * - * @param key 任务ID - * @param task 任务 + * @param key 任务ID + * @param task 任务 * @param delay 延时 /毫秒 * @return */ diff --git a/sip-common/src/test/java/io/github/lunasaw/sip/common/test/ApplicationTest.java b/sip-common/src/test/java/io/github/lunasaw/sip/common/test/ApplicationTest.java index ba6b32ac..882d1f8b 100644 --- a/sip-common/src/test/java/io/github/lunasaw/sip/common/test/ApplicationTest.java +++ b/sip-common/src/test/java/io/github/lunasaw/sip/common/test/ApplicationTest.java @@ -7,6 +7,7 @@ import io.github.lunasaw.sip.common.utils.SipRequestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import com.luna.common.os.SystemInfoUtil; @@ -20,10 +21,12 @@ @SpringBootTest(classes = SipCommonApplication.class) public class ApplicationTest { + @Autowired + private SipLayer sipLayer; @BeforeEach public void before() { - SipLayer.addListeningPoint(SystemInfoUtil.getIP(), 8117); + sipLayer.addListeningPoint(SystemInfoUtil.getIP(), 8117); } @SneakyThrows