From 243edbd14369cf8be80008056320aa809612cdc0 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 9 Sep 2022 23:19:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAUser-Agent=E6=B7=BB=E5=8A=A0=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++-- .../genersoft/iot/vmp/VManageBootstrap.java | 13 +++++++++++ .../cmd/SIPRequestHeaderPlarformProvider.java | 9 ++++++-- .../cmd/SIPRequestHeaderProvider.java | 22 ++++++++++++++++--- .../transmit/cmd/impl/SIPCommander.java | 8 +++++-- .../impl/InviteResponseProcessor.java | 6 ++++- .../iot/vmp/gb28181/utils/SipUtils.java | 10 ++++++--- .../com/genersoft/iot/vmp/utils/GitUtil.java | 15 +++++++++++++ src/main/resources/all-application.yml | 6 ----- src/main/resources/application-dev.yml | 6 ----- src/main/resources/application-docker.yml | 7 ------ src/main/resources/banner.txt | 2 -- 12 files changed, 76 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 71dd9485..25bdb818 100644 --- a/pom.xml +++ b/pom.xml @@ -263,14 +263,16 @@ - + org.apache.maven.plugins diff --git a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java index 21002c41..af3340dd 100644 --- a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java +++ b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java @@ -3,6 +3,12 @@ package com.genersoft.iot.vmp; import java.util.logging.LogManager; import com.genersoft.iot.vmp.conf.druid.EnableDruidSupport; +import com.genersoft.iot.vmp.storager.impl.RedisCatchStorageImpl; +import com.genersoft.iot.vmp.utils.GitUtil; +import com.genersoft.iot.vmp.utils.SpringBeanFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; @@ -17,11 +23,18 @@ import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling @EnableDruidSupport public class VManageBootstrap extends LogManager { + + private final static Logger logger = LoggerFactory.getLogger(VManageBootstrap.class); + private static String[] args; private static ConfigurableApplicationContext context; public static void main(String[] args) { VManageBootstrap.args = args; VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args); + GitUtil gitUtil1 = SpringBeanFactory.getBean("gitUtil"); + logger.info("构建版本: {}", gitUtil1.getBuildVersion()); + logger.info("构建时间: {}", gitUtil1.getBuildDate()); + logger.info("GIT最后提交时间: {}", gitUtil1.getCommitTime()); } // 项目重启 public static void restart() { 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 2f3be356..6ee3cce2 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 @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.message.MessageFactoryImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -34,6 +35,9 @@ public class SIPRequestHeaderPlarformProvider { @Autowired private SipFactory sipFactory; + @Autowired + private GitUtil gitUtil; + @Autowired private IRedisCatchStorage redisCatchStorage; @@ -72,8 +76,7 @@ public class SIPRequestHeaderPlarformProvider { ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(isRegister ? platform.getExpires() : 0); request.addHeader(expires); - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); - request.addHeader(userAgentHeader); + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); return request; } @@ -183,6 +186,8 @@ public class SIPRequestHeaderPlarformProvider { request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards); + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); request.setContent(content, contentTypeHeader); return request; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index 807afb42..21ab3742 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.SipProviderImpl; import gov.nist.javax.sip.SipStackImpl; import gov.nist.javax.sip.stack.SIPDialog; @@ -37,6 +38,9 @@ public class SIPRequestHeaderProvider { @Autowired private SipFactory sipFactory; + @Autowired + private GitUtil gitUtil; + @Autowired private IRedisCatchStorage redisCatchStorage; @@ -76,6 +80,9 @@ public class SIPRequestHeaderProvider { request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards); + + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); request.setContent(content, contentTypeHeader); return request; @@ -106,7 +113,9 @@ public class SIPRequestHeaderProvider { //ceq CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.INVITE); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); - + + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); @@ -146,6 +155,9 @@ public class SIPRequestHeaderProvider { Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); + + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + // Subject SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); request.addHeader(subjectHeader); @@ -180,6 +192,8 @@ public class SIPRequestHeaderProvider { CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); return request; @@ -230,6 +244,9 @@ public class SIPRequestHeaderProvider { ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); request.setContent(content, contentTypeHeader); + + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); + return request; } @@ -264,8 +281,7 @@ public class SIPRequestHeaderProvider { Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() .createSipURI(sipConfig.getId(), sipConfig.getIp() + ":" + sipConfig.getPort())); infoRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); - infoRequest.addHeader(userAgentHeader); + infoRequest.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSRTSP"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index a80745d8..2d305c06 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.SipProviderImpl; import gov.nist.javax.sip.SipStackImpl; import gov.nist.javax.sip.message.MessageFactoryImpl; @@ -60,6 +61,9 @@ public class SIPCommander implements ISIPCommander { @Autowired private SipFactory sipFactory; + @Autowired + private GitUtil gitUtil; + @Autowired @Qualifier(value="tcpSipProvider") private SipProviderImpl tcpSipProvider; @@ -727,7 +731,7 @@ public class SIPCommander implements ISIPCommander { // 增加Contact header Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); byeRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); byeRequest.addHeader(userAgentHeader); ClientTransaction clientTransaction = null; if("TCP".equals(protocol)) { @@ -1618,7 +1622,7 @@ public class SIPCommander implements ISIPCommander { if (request.getHeader(UserAgentHeader.NAME) == null) { UserAgentHeader userAgentHeader = null; try { - userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); + userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); } catch (ParseException e) { logger.error("添加UserAgentHeader失败", e); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java index 923d79f1..a2bc6e1f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcessorAbstract; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; +import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.ResponseEventExt; import gov.nist.javax.sip.stack.SIPDialog; import org.slf4j.Logger; @@ -48,6 +49,9 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract { @Autowired private SipFactory sipFactory; + @Autowired + private GitUtil gitUtil; + @Override public void afterPropertiesSet() throws Exception { // 添加消息处理的订阅 @@ -98,7 +102,7 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract { } requestURI.setPort(event.getRemotePort()); reqAck.setRequestURI(requestURI); - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); reqAck.addHeader(userAgentHeader); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); reqAck.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 47bf38d3..cf64a86a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.utils; +import com.genersoft.iot.vmp.utils.GitUtil; import gov.nist.javax.sip.address.AddressImpl; import gov.nist.javax.sip.address.SipUri; import gov.nist.javax.sip.header.Subject; @@ -49,10 +50,13 @@ public class SipUtils { return "z9hG4bK" + System.currentTimeMillis(); } - public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory) throws PeerUnavailableException, ParseException { + public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory, GitUtil gitUtil) throws PeerUnavailableException, ParseException { List agentParam = new ArrayList<>(); - agentParam.add("WVP PRO"); - // TODO 添加版本信息以及日期 + agentParam.add("WVP-Pro v"); + if (gitUtil != null && gitUtil.getCommitTime() != null) { + agentParam.add(gitUtil.getBuildVersion() + "."); + agentParam.add(gitUtil.getCommitTime()); + } return sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java index 60ee987c..d6dc943a 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java @@ -19,9 +19,16 @@ public class GitUtil { private String gitUrl; @Value("${git.build.time:null}") private String buildDate; + + @Value("${git.build.version:null}") + private String buildVersion; + @Value("${git.commit.id.abbrev:null}") private String commitIdShort; + @Value("${git.commit.time:null}") + private String commitTime; + public String getGitCommitId() { return gitCommitId; } @@ -41,4 +48,12 @@ public class GitUtil { public String getCommitIdShort() { return commitIdShort; } + + public String getBuildVersion() { + return buildVersion; + } + + public String getCommitTime() { + return commitTime; + } } diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml index 222c0765..3569de2e 100644 --- a/src/main/resources/all-application.yml +++ b/src/main/resources/all-application.yml @@ -195,9 +195,3 @@ springdoc: enabled: false swagger-ui: enabled: false - -# 版本信息, 不需修改 -version: - version: "@project.version@" - description: "@project.description@" - artifact-id: "@project.artifactId@" diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 833bb300..7d1e116d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -84,9 +84,3 @@ media: # [可选] 日志配置, 一般不需要改 logging: config: classpath:logback-spring-local.xml - -# 版本信息, 不需修改 -version: - version: "@project.version@" - description: "@project.description@" - artifact-id: "@project.artifactId@" diff --git a/src/main/resources/application-docker.yml b/src/main/resources/application-docker.yml index 06b78100..a722435c 100644 --- a/src/main/resources/application-docker.yml +++ b/src/main/resources/application-docker.yml @@ -78,10 +78,3 @@ user-settings: # 推流直播是否录制 record-push-live: true auto-apply-play: true - - -# 版本信息, 不需修改 -version: - version: "@project.version@" - description: "@project.description@" - artifact-id: "@project.artifactId@" diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index 0c7250d4..7a75e1c6 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -5,5 +5,3 @@ \ \ \|\__\_\ \ \ / / \ \ \___\|____________|\ \ \___|\ \ \\ \\ \ \\\ \ \ \____________\ \__/ / \ \__\ \ \__\ \ \__\\ _\\ \_______\ \|____________|\|__|/ \|__| \|__| \|__|\|__|\|_______| - -版本:${version.version} \ No newline at end of file