Commit 243edbd14369cf8be80008056320aa809612cdc0
1 parent
221f99c7
为User-Agent添加必要的版本信息
Showing
12 changed files
with
76 additions
and
34 deletions
pom.xml
| ... | ... | @@ -263,14 +263,16 @@ |
| 263 | 263 | </configuration> |
| 264 | 264 | </plugin> |
| 265 | 265 | |
| 266 | - <!-- <plugin> | |
| 266 | + <plugin> | |
| 267 | 267 | <groupId>pl.project13.maven</groupId> |
| 268 | 268 | <artifactId>git-commit-id-plugin</artifactId> |
| 269 | 269 | <version>3.0.1</version> |
| 270 | 270 | <configuration> |
| 271 | 271 | <offline>true</offline> |
| 272 | + <failOnNoGitDirectory>false</failOnNoGitDirectory> | |
| 273 | + <dateFormat>yyyyMMdd</dateFormat> | |
| 272 | 274 | </configuration> |
| 273 | - </plugin>--> | |
| 275 | + </plugin> | |
| 274 | 276 | |
| 275 | 277 | <plugin> |
| 276 | 278 | <groupId>org.apache.maven.plugins</groupId> | ... | ... |
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
| ... | ... | @@ -3,6 +3,12 @@ package com.genersoft.iot.vmp; |
| 3 | 3 | import java.util.logging.LogManager; |
| 4 | 4 | |
| 5 | 5 | import com.genersoft.iot.vmp.conf.druid.EnableDruidSupport; |
| 6 | +import com.genersoft.iot.vmp.storager.impl.RedisCatchStorageImpl; | |
| 7 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 8 | +import com.genersoft.iot.vmp.utils.SpringBeanFactory; | |
| 9 | +import org.slf4j.Logger; | |
| 10 | +import org.slf4j.LoggerFactory; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | 12 | import org.springframework.boot.SpringApplication; |
| 7 | 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 8 | 14 | import org.springframework.boot.web.servlet.ServletComponentScan; |
| ... | ... | @@ -17,11 +23,18 @@ import org.springframework.scheduling.annotation.EnableScheduling; |
| 17 | 23 | @EnableScheduling |
| 18 | 24 | @EnableDruidSupport |
| 19 | 25 | public class VManageBootstrap extends LogManager { |
| 26 | + | |
| 27 | + private final static Logger logger = LoggerFactory.getLogger(VManageBootstrap.class); | |
| 28 | + | |
| 20 | 29 | private static String[] args; |
| 21 | 30 | private static ConfigurableApplicationContext context; |
| 22 | 31 | public static void main(String[] args) { |
| 23 | 32 | VManageBootstrap.args = args; |
| 24 | 33 | VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args); |
| 34 | + GitUtil gitUtil1 = SpringBeanFactory.getBean("gitUtil"); | |
| 35 | + logger.info("构建版本: {}", gitUtil1.getBuildVersion()); | |
| 36 | + logger.info("构建时间: {}", gitUtil1.getBuildDate()); | |
| 37 | + logger.info("GIT最后提交时间: {}", gitUtil1.getCommitTime()); | |
| 25 | 38 | } |
| 26 | 39 | // 项目重启 |
| 27 | 40 | public static void restart() { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
| ... | ... | @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.conf.SipConfig; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 6 | 6 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 7 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 7 | 8 | import gov.nist.javax.sip.message.MessageFactoryImpl; |
| 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | 10 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -35,6 +36,9 @@ public class SIPRequestHeaderPlarformProvider { |
| 35 | 36 | private SipFactory sipFactory; |
| 36 | 37 | |
| 37 | 38 | @Autowired |
| 39 | + private GitUtil gitUtil; | |
| 40 | + | |
| 41 | + @Autowired | |
| 38 | 42 | private IRedisCatchStorage redisCatchStorage; |
| 39 | 43 | |
| 40 | 44 | public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader, boolean isRegister) throws ParseException, InvalidArgumentException, PeerUnavailableException { |
| ... | ... | @@ -72,8 +76,7 @@ public class SIPRequestHeaderPlarformProvider { |
| 72 | 76 | ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(isRegister ? platform.getExpires() : 0); |
| 73 | 77 | request.addHeader(expires); |
| 74 | 78 | |
| 75 | - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); | |
| 76 | - request.addHeader(userAgentHeader); | |
| 79 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 77 | 80 | |
| 78 | 81 | return request; |
| 79 | 82 | } |
| ... | ... | @@ -183,6 +186,8 @@ public class SIPRequestHeaderPlarformProvider { |
| 183 | 186 | request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, |
| 184 | 187 | toHeader, viaHeaders, maxForwards); |
| 185 | 188 | |
| 189 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 190 | + | |
| 186 | 191 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 187 | 192 | request.setContent(content, contentTypeHeader); |
| 188 | 193 | return request; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
| ... | ... | @@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; |
| 13 | 13 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 14 | 14 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 15 | 15 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 16 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 16 | 17 | import gov.nist.javax.sip.SipProviderImpl; |
| 17 | 18 | import gov.nist.javax.sip.SipStackImpl; |
| 18 | 19 | import gov.nist.javax.sip.stack.SIPDialog; |
| ... | ... | @@ -38,6 +39,9 @@ public class SIPRequestHeaderProvider { |
| 38 | 39 | private SipFactory sipFactory; |
| 39 | 40 | |
| 40 | 41 | @Autowired |
| 42 | + private GitUtil gitUtil; | |
| 43 | + | |
| 44 | + @Autowired | |
| 41 | 45 | private IRedisCatchStorage redisCatchStorage; |
| 42 | 46 | |
| 43 | 47 | @Autowired |
| ... | ... | @@ -76,6 +80,9 @@ public class SIPRequestHeaderProvider { |
| 76 | 80 | |
| 77 | 81 | request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, |
| 78 | 82 | toHeader, viaHeaders, maxForwards); |
| 83 | + | |
| 84 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 85 | + | |
| 79 | 86 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 80 | 87 | request.setContent(content, contentTypeHeader); |
| 81 | 88 | return request; |
| ... | ... | @@ -106,7 +113,9 @@ public class SIPRequestHeaderProvider { |
| 106 | 113 | //ceq |
| 107 | 114 | CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(redisCatchStorage.getCSEQ(), Request.INVITE); |
| 108 | 115 | request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); |
| 109 | - | |
| 116 | + | |
| 117 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 118 | + | |
| 110 | 119 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); |
| 111 | 120 | // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); |
| 112 | 121 | request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| ... | ... | @@ -146,6 +155,9 @@ public class SIPRequestHeaderProvider { |
| 146 | 155 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); |
| 147 | 156 | // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort())); |
| 148 | 157 | request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| 158 | + | |
| 159 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 160 | + | |
| 149 | 161 | // Subject |
| 150 | 162 | SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0)); |
| 151 | 163 | request.addHeader(subjectHeader); |
| ... | ... | @@ -180,6 +192,8 @@ public class SIPRequestHeaderProvider { |
| 180 | 192 | CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId); |
| 181 | 193 | request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); |
| 182 | 194 | |
| 195 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 196 | + | |
| 183 | 197 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); |
| 184 | 198 | |
| 185 | 199 | return request; |
| ... | ... | @@ -230,6 +244,9 @@ public class SIPRequestHeaderProvider { |
| 230 | 244 | |
| 231 | 245 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); |
| 232 | 246 | request.setContent(content, contentTypeHeader); |
| 247 | + | |
| 248 | + request.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 249 | + | |
| 233 | 250 | return request; |
| 234 | 251 | } |
| 235 | 252 | |
| ... | ... | @@ -264,8 +281,7 @@ public class SIPRequestHeaderProvider { |
| 264 | 281 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory() |
| 265 | 282 | .createSipURI(sipConfig.getId(), sipConfig.getIp() + ":" + sipConfig.getPort())); |
| 266 | 283 | infoRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| 267 | - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); | |
| 268 | - infoRequest.addHeader(userAgentHeader); | |
| 284 | + infoRequest.addHeader(SipUtils.createUserAgentHeader(sipFactory, gitUtil)); | |
| 269 | 285 | |
| 270 | 286 | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", |
| 271 | 287 | "MANSRTSP"); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| ... | ... | @@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.service.IMediaServerService; |
| 21 | 21 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 22 | 22 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 23 | 23 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 24 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 24 | 25 | import gov.nist.javax.sip.SipProviderImpl; |
| 25 | 26 | import gov.nist.javax.sip.SipStackImpl; |
| 26 | 27 | import gov.nist.javax.sip.message.MessageFactoryImpl; |
| ... | ... | @@ -61,6 +62,9 @@ public class SIPCommander implements ISIPCommander { |
| 61 | 62 | private SipFactory sipFactory; |
| 62 | 63 | |
| 63 | 64 | @Autowired |
| 65 | + private GitUtil gitUtil; | |
| 66 | + | |
| 67 | + @Autowired | |
| 64 | 68 | @Qualifier(value="tcpSipProvider") |
| 65 | 69 | private SipProviderImpl tcpSipProvider; |
| 66 | 70 | |
| ... | ... | @@ -727,7 +731,7 @@ public class SIPCommander implements ISIPCommander { |
| 727 | 731 | // 增加Contact header |
| 728 | 732 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); |
| 729 | 733 | byeRequest.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); |
| 730 | - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); | |
| 734 | + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); | |
| 731 | 735 | byeRequest.addHeader(userAgentHeader); |
| 732 | 736 | ClientTransaction clientTransaction = null; |
| 733 | 737 | if("TCP".equals(protocol)) { |
| ... | ... | @@ -1618,7 +1622,7 @@ public class SIPCommander implements ISIPCommander { |
| 1618 | 1622 | if (request.getHeader(UserAgentHeader.NAME) == null) { |
| 1619 | 1623 | UserAgentHeader userAgentHeader = null; |
| 1620 | 1624 | try { |
| 1621 | - userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); | |
| 1625 | + userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); | |
| 1622 | 1626 | } catch (ParseException e) { |
| 1623 | 1627 | logger.error("添加UserAgentHeader失败", e); |
| 1624 | 1628 | } | ... | ... |
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; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.event.response.SIPResponseProcessorAbstract; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 8 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 8 | 9 | import gov.nist.javax.sip.ResponseEventExt; |
| 9 | 10 | import gov.nist.javax.sip.stack.SIPDialog; |
| 10 | 11 | import org.slf4j.Logger; |
| ... | ... | @@ -48,6 +49,9 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract { |
| 48 | 49 | @Autowired |
| 49 | 50 | private SipFactory sipFactory; |
| 50 | 51 | |
| 52 | + @Autowired | |
| 53 | + private GitUtil gitUtil; | |
| 54 | + | |
| 51 | 55 | @Override |
| 52 | 56 | public void afterPropertiesSet() throws Exception { |
| 53 | 57 | // 添加消息处理的订阅 |
| ... | ... | @@ -98,7 +102,7 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract { |
| 98 | 102 | } |
| 99 | 103 | requestURI.setPort(event.getRemotePort()); |
| 100 | 104 | reqAck.setRequestURI(requestURI); |
| 101 | - UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory); | |
| 105 | + UserAgentHeader userAgentHeader = SipUtils.createUserAgentHeader(sipFactory, gitUtil); | |
| 102 | 106 | reqAck.addHeader(userAgentHeader); |
| 103 | 107 | Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort())); |
| 104 | 108 | reqAck.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.utils; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.utils.GitUtil; | |
| 3 | 4 | import gov.nist.javax.sip.address.AddressImpl; |
| 4 | 5 | import gov.nist.javax.sip.address.SipUri; |
| 5 | 6 | import gov.nist.javax.sip.header.Subject; |
| ... | ... | @@ -49,10 +50,13 @@ public class SipUtils { |
| 49 | 50 | return "z9hG4bK" + System.currentTimeMillis(); |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | - public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory) throws PeerUnavailableException, ParseException { | |
| 53 | + public static UserAgentHeader createUserAgentHeader(SipFactory sipFactory, GitUtil gitUtil) throws PeerUnavailableException, ParseException { | |
| 53 | 54 | List<String> agentParam = new ArrayList<>(); |
| 54 | - agentParam.add("WVP PRO"); | |
| 55 | - // TODO 添加版本信息以及日期 | |
| 55 | + agentParam.add("WVP-Pro v"); | |
| 56 | + if (gitUtil != null && gitUtil.getCommitTime() != null) { | |
| 57 | + agentParam.add(gitUtil.getBuildVersion() + "."); | |
| 58 | + agentParam.add(gitUtil.getCommitTime()); | |
| 59 | + } | |
| 56 | 60 | return sipFactory.createHeaderFactory().createUserAgentHeader(agentParam); |
| 57 | 61 | } |
| 58 | 62 | ... | ... |
src/main/java/com/genersoft/iot/vmp/utils/GitUtil.java
| ... | ... | @@ -19,9 +19,16 @@ public class GitUtil { |
| 19 | 19 | private String gitUrl; |
| 20 | 20 | @Value("${git.build.time:null}") |
| 21 | 21 | private String buildDate; |
| 22 | + | |
| 23 | + @Value("${git.build.version:null}") | |
| 24 | + private String buildVersion; | |
| 25 | + | |
| 22 | 26 | @Value("${git.commit.id.abbrev:null}") |
| 23 | 27 | private String commitIdShort; |
| 24 | 28 | |
| 29 | + @Value("${git.commit.time:null}") | |
| 30 | + private String commitTime; | |
| 31 | + | |
| 25 | 32 | public String getGitCommitId() { |
| 26 | 33 | return gitCommitId; |
| 27 | 34 | } |
| ... | ... | @@ -41,4 +48,12 @@ public class GitUtil { |
| 41 | 48 | public String getCommitIdShort() { |
| 42 | 49 | return commitIdShort; |
| 43 | 50 | } |
| 51 | + | |
| 52 | + public String getBuildVersion() { | |
| 53 | + return buildVersion; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public String getCommitTime() { | |
| 57 | + return commitTime; | |
| 58 | + } | |
| 44 | 59 | } | ... | ... |
src/main/resources/all-application.yml
src/main/resources/application-dev.yml
src/main/resources/application-docker.yml
src/main/resources/banner.txt