From 69d9692f6194d1e03ec81cf87ea8f0e7a62f7173 Mon Sep 17 00:00:00 2001
From: wangyimeng <421132955@qq.com>
Date: 星期三, 16 三月 2022 15:27:12 +0800
Subject: [PATCH] 删除重复字段
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java | 151 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 109 insertions(+), 42 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
index 2e2ec43..43e2690 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
@@ -2,8 +2,10 @@
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import gov.nist.javax.sip.message.MessageFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
@@ -15,10 +17,11 @@
import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
/**
- * @Description: 骞冲彴鍛戒护request鍒涢�犲櫒 TODO 鍐椾綑浠g爜澶寰呬紭鍖�
+ * @description: 骞冲彴鍛戒护request鍒涢�犲櫒 TODO 鍐椾綑浠g爜澶寰呬紭鍖�
* @author: panll
* @date: 2020骞�5鏈�6鏃� 涓婂崍9:29:02
*/
@@ -30,56 +33,56 @@
@Autowired
private SipFactory sipFactory;
-
+
@Autowired
- @Qualifier(value="tcpSipProvider")
- private SipProvider tcpSipProvider;
-
- @Autowired
- @Qualifier(value="udpSipProvider")
- private SipProvider udpSipProvider;
+ private IRedisCatchStorage redisCatchStorage;
- public Request createKeetpaliveMessageRequest(ParentPlatform parentPlatform, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
+ public Request createKeetpaliveMessageRequest(ParentPlatform parentPlatform, String content, String viaTag, String fromTag, String toTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null;
// sipuri
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
// via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
- ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(),
+ ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(),
parentPlatform.getTransport(), viaTag);
viaHeader.setRPort();
viaHeaders.add(viaHeader);
// from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
- sipConfig.getSipIp() + ":" + sipConfig.getSipPort());
+ sipConfig.getIp() + ":" + sipConfig.getPort());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort() );
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
- // callid
- CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
- : udpSipProvider.getNewCallId();
+
+
// Forwards
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
// ceq
- CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.MESSAGE);
+ CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.MESSAGE), Request.MESSAGE);
request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
toHeader, viaHeaders, maxForwards);
+
+ List<String> agentParam = new ArrayList<>();
+ agentParam.add("wvp-pro");
+ UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
+ request.addHeader(userAgentHeader);
+
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
request.setContent(content, contentTypeHeader);
return request;
}
- public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
+ public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null;
- String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort();
+ String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
//璇锋眰琛�
- SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),
+ SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(),
platform.getServerIP() + ":" + platform.getServerPort());
//via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
@@ -95,14 +98,7 @@
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
- //callid
- CallIdHeader callIdHeader = null;
- if(platform.getTransport().equals("TCP")) {
- callIdHeader = tcpSipProvider.getNewCallId();
- }
- if(platform.getTransport().equals("UDP")) {
- callIdHeader = udpSipProvider.getNewCallId();
- }
+
//Forwards
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
@@ -119,13 +115,28 @@
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
request.addHeader(expires);
+ List<String> agentParam = new ArrayList<>();
+ agentParam.add("wvp-pro");
+ UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
+ request.addHeader(userAgentHeader);
+
return request;
}
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
- String callId, WWWAuthenticateHeader www ) throws ParseException, PeerUnavailableException, InvalidArgumentException {
- Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
+ String callId, WWWAuthenticateHeader www , CallIdHeader callIdHeader) throws ParseException, PeerUnavailableException, InvalidArgumentException {
+
+ Request registerRequest = createRegisterRequest(parentPlatform, redisCatchStorage.getCSEQ(Request.REGISTER), fromTag, viaTag, callIdHeader);
+ SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
+ if (www == null) {
+ AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader("Digest");
+ authorizationHeader.setUsername(parentPlatform.getDeviceGBId());
+ authorizationHeader.setURI(requestURI);
+ authorizationHeader.setAlgorithm("MD5");
+ registerRequest.addHeader(authorizationHeader);
+ return registerRequest;
+ }
String realm = www.getRealm();
String nonce = www.getNonce();
String scheme = www.getScheme();
@@ -134,11 +145,8 @@
// qop 淇濇姢璐ㄩ噺 鍖呭惈auth锛堥粯璁ょ殑锛夊拰auth-int锛堝鍔犱簡鎶ユ枃瀹屾暣鎬ф娴嬶級涓ょ绛栫暐
String qop = www.getQop();
- CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
callIdHeader.setCallId(callId);
-
- SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
String cNonce = null;
String nc = "00000001";
if (qop != null) {
@@ -189,7 +197,7 @@
}
- public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag) throws PeerUnavailableException, ParseException, InvalidArgumentException {
+ public Request createMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, CallIdHeader callIdHeader) throws PeerUnavailableException, ParseException, InvalidArgumentException {
Request request = null;
// sipuri
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort());
@@ -200,26 +208,85 @@
viaHeader.setRPort();
viaHeaders.add(viaHeader);
// from
- SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(),
+ SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// to
- SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), parentPlatform.getServerGBDomain());
+ SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, null);
- // callid
- CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
- : udpSipProvider.getNewCallId();
+
// Forwards
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
// ceq
- CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.MESSAGE);
-
- request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
+ CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.MESSAGE), Request.MESSAGE);
+ MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
+ // 璁剧疆缂栫爜锛� 闃叉涓枃涔辩爜
+ messageFactory.setDefaultContentEncodingCharset("gb2312");
+ request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
toHeader, viaHeaders, maxForwards);
- ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
+ List<String> agentParam = new ArrayList<>();
+ agentParam.add("wvp-pro");
+ UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
+ request.addHeader(userAgentHeader);
+
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
request.setContent(content, contentTypeHeader);
return request;
}
+
+// public Request createNotifyRequest(ParentPlatform parentPlatform, String content, CallIdHeader callIdHeader, String viaTag, String fromTag, SubscribeInfo subscribeInfo) throws PeerUnavailableException, ParseException, InvalidArgumentException {
+// Request request = null;
+// // sipuri
+// SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP()+ ":" + parentPlatform.getServerPort());
+// // via
+// ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
+// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(parentPlatform.getDeviceIp(), Integer.parseInt(parentPlatform.getDevicePort()),
+// parentPlatform.getTransport(), viaTag);
+// viaHeader.setRPort();
+// viaHeaders.add(viaHeader);
+// // from
+// SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
+// parentPlatform.getDeviceIp() + ":" + parentPlatform.getDevicePort());
+// Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
+// FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
+// // to
+// SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
+// Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
+// ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, subscribeInfo.getFromTag());
+//
+// // Forwards
+// MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
+// // ceq
+// CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(Request.NOTIFY), Request.NOTIFY);
+// MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
+// // 璁剧疆缂栫爜锛� 闃叉涓枃涔辩爜
+// messageFactory.setDefaultContentEncodingCharset("gb2312");
+// request = messageFactory.createRequest(requestURI, Request.NOTIFY, callIdHeader, cSeqHeader, fromHeader,
+// toHeader, viaHeaders, maxForwards);
+// List<String> agentParam = new ArrayList<>();
+// agentParam.add("wvp-pro");
+// UserAgentHeader userAgentHeader = sipFactory.createHeaderFactory().createUserAgentHeader(agentParam);
+// request.addHeader(userAgentHeader);
+//
+// EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
+// if (subscribeInfo.getEventId() != null) {
+// event.setEventId(subscribeInfo.getEventId());
+// }
+//
+// request.addHeader(event);
+//
+// SubscriptionStateHeader active = sipFactory.createHeaderFactory().createSubscriptionStateHeader("active");
+// request.setHeader(active);
+//
+// String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
+// Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
+// .createSipURI(parentPlatform.getDeviceGBId(), sipAddress));
+// request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
+//
+// ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+// request.setContent(content, contentTypeHeader);
+// return request;
+// }
}
--
Gitblit v1.8.0