修复订阅超时

This commit is contained in:
648540858 2022-06-04 10:18:04 +08:00
parent 075c6ad7f8
commit 8e1f032b28
2 changed files with 25 additions and 3 deletions

View File

@ -32,7 +32,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.sip.*; import javax.sip.*;
import javax.sip.address.Address;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.address.URI;
import javax.sip.header.*; import javax.sip.header.*;
import javax.sip.message.Request; import javax.sip.message.Request;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -1487,11 +1489,20 @@ public class SIPCommander implements ISIPCommander {
Request request; Request request;
if (dialog != null) { if (dialog != null) {
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
request = dialog.createRequest(Request.SUBSCRIBE); request = dialog.createRequest(Request.SUBSCRIBE);
ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
request.setExpires(expiresHeader);
request.setRequestURI(requestURI);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
request.setContent(subscribePostitionXml.toString(), contentTypeHeader); request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
request.addHeader(expireHeader); CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE));
request.removeHeader(CSeqHeader.NAME);
request.addHeader(cSeqHeader);
}else { }else {
String tm = Long.toString(System.currentTimeMillis()); String tm = Long.toString(System.currentTimeMillis());
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
@ -1582,12 +1593,21 @@ public class SIPCommander implements ISIPCommander {
Request request; Request request;
if (dialog != null) { if (dialog != null) {
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
request = dialog.createRequest(Request.SUBSCRIBE); request = dialog.createRequest(Request.SUBSCRIBE);
ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog()); ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
request.setExpires(expiresHeader); request.setExpires(expiresHeader);
request.setRequestURI(requestURI);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
request.setContent(cmdXml.toString(), contentTypeHeader); request.setContent(cmdXml.toString(), contentTypeHeader);
CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE));
request.removeHeader(CSeqHeader.NAME);
request.addHeader(cSeqHeader);
}else { }else {
String tm = Long.toString(System.currentTimeMillis()); String tm = Long.toString(System.currentTimeMillis());

View File

@ -82,7 +82,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
@Override @Override
public void process(RequestEvent evt) { public void process(RequestEvent evt) {
Request request = evt.getRequest(); Request request = evt.getRequest();
System.out.println("收到订阅");
try { try {
Element rootElement = getRootElement(evt); Element rootElement = getRootElement(evt);
String cmd = XmlUtil.getText(rootElement, "CmdType"); String cmd = XmlUtil.getText(rootElement, "CmdType");
@ -176,6 +176,8 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
} }
private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException { private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException {
System.out.println(evt.getRequest().toString());
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
String deviceId = XmlUtil.getText(rootElement, "DeviceID"); String deviceId = XmlUtil.getText(rootElement, "DeviceID");
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId); ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);