diff --git a/.gitignore b/.gitignore index a1c2a23..ee31d72 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/.idea diff --git a/src/main/java/com/genersoft/iot/vmp/Swagger2.java b/src/main/java/com/genersoft/iot/vmp/Swagger2.java new file mode 100644 index 0000000..d85db69 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/Swagger2.java @@ -0,0 +1,52 @@ +package com.genersoft.iot.vmp; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class Swagger2 { + + /** + * 创建API应用 + * apiInfo() 增加API相关信息 + * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现, + * 本例采用指定扫描的包路径来定义指定要建立API的目录。 + * + * @return + */ + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.genersoft.iot.vmp")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 创建该API的基本信息(这些基本信息会展现在文档页面中) + * 访问地址:http://项目实际地址/swagger-ui.html + * + * @return + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("GB28181接口文档") + .description("") + .termsOfServiceUrl("") + .version("1.0") + .build(); + } + + +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java index 4b5e571..520cb90 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java @@ -1,5 +1,7 @@ package com.genersoft.iot.vmp.gb28181.event.offline; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; @@ -16,7 +18,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; */ @Component public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { - + private static Logger log = LoggerFactory.getLogger(KeepliveTimeoutListener.class); @Autowired private EventPublisher publisher; @@ -34,7 +36,7 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { // 获取失效的key String expiredKey = message.toString(); if(!expiredKey.startsWith(VideoManagerConstants.KEEPLIVEKEY_PREFIX)){ - System.out.println("收到redis过期监听,但开头不是"+VideoManagerConstants.KEEPLIVEKEY_PREFIX+",忽略"); + log.debug("收到redis过期监听,但开头不是"+VideoManagerConstants.KEEPLIVEKEY_PREFIX+",忽略"); return; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java index f0d71d2..4fa54f0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java @@ -5,6 +5,8 @@ import java.util.concurrent.ConcurrentHashMap; import javax.sip.ClientTransaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; /** @@ -14,6 +16,7 @@ import org.springframework.stereotype.Component; */ @Component public class VideoStreamSessionManager { + private static Logger log = LoggerFactory.getLogger(VideoStreamSessionManager.class); private ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); @@ -48,7 +51,7 @@ public class VideoStreamSessionManager { while (true == col.contains(ssrc)) { col.remove(ssrc); } - System.out.println(deviceSessionMap); + log.debug(deviceSessionMap.toString()); } public void putDevice(String deviceAndChannel,String ssrc){ diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java index aebc601..846f9fc 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java @@ -9,6 +9,8 @@ import javax.sip.message.Request; import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; import gov.nist.javax.sip.header.CSeq; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @Description:ACK请求处理器 @@ -16,7 +18,7 @@ import gov.nist.javax.sip.header.CSeq; * @date: 2020年5月3日 下午5:31:45 */ public class AckRequestProcessor extends SIPRequestAbstractProcessor { - + private static Logger log = LoggerFactory.getLogger(AckRequestProcessor.class); /** * 处理 ACK请求 * @@ -34,7 +36,7 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { CSeq csReq = (CSeq) request.getHeader(CSeq.NAME); ackRequest = dialog.createAck(csReq.getSeqNumber()); dialog.sendAck(ackRequest); - System.out.println("send ack to callee:" + ackRequest.toString()); + log.debug("send ack to callee:" + ackRequest.toString()); } catch (SipException e) { e.printStackTrace(); } catch (InvalidArgumentException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java index ab70a5e..6dbd90c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.request.impl; import javax.sip.RequestEvent; import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @Description:处理INVITE请求 @@ -10,7 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso * @date: 2020年5月3日 下午4:43:52 */ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { - + private static Logger log = LoggerFactory.getLogger(InviteRequestProcessor.class); /** * 处理invite请求 * @@ -29,7 +31,7 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { // URI reqUri = request.getRequestURI(); // URI contactURI = currUser.get(reqUri); // -// System.out.println("processInvite rqStr=" + reqUri + " contact=" + contactURI); +// log.debug("processInvite rqStr=" + reqUri + " contact=" + contactURI); // // // 根据Request uri来路由,后续的响应消息通过VIA来路由 // Request cliReq = messageFactory.createRequest(request.toString()); @@ -54,9 +56,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor { // clientTransactionId = sipProvider.getNewClientTransaction(cliReq); // clientTransactionId.sendRequest(); // -// System.out.println("processInvite clientTransactionId=" + clientTransactionId.toString()); +// log.debug("processInvite clientTransactionId=" + clientTransactionId.toString()); // -// System.out.println("send invite to callee: " + cliReq); +// log.debug("send invite to callee: " + cliReq); // } catch (TransactionUnavailableException e1) { // e1.printStackTrace(); // } catch (SipException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/OtherRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/OtherRequestProcessor.java index 63da991..581521f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/OtherRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/OtherRequestProcessor.java @@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.request.impl; import javax.sip.RequestEvent; import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @Description:暂不支持的消息请求处理器 @@ -10,7 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso * @date: 2020年5月3日 下午5:32:59 */ public class OtherRequestProcessor extends SIPRequestAbstractProcessor { - + private static Logger log = LoggerFactory.getLogger(OtherRequestProcessor.class); /** *

Title: process

*

Description:

@@ -21,7 +23,7 @@ public class OtherRequestProcessor extends SIPRequestAbstractProcessor { */ @Override public void process(RequestEvent evt) { - System.out.println("no support the method! Method:" + evt.getRequest().getMethod()); + log.debug("no support the method! Method:" + evt.getRequest().getMethod()); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java index a90429a..cee50a7 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java @@ -16,6 +16,8 @@ import javax.sip.header.ViaHeader; import javax.sip.message.Request; import javax.sip.message.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; import com.genersoft.iot.vmp.common.VideoManagerConstants; @@ -38,6 +40,7 @@ import gov.nist.javax.sip.header.Expires; * @date: 2020年5月3日 下午4:47:25 */ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { + private static Logger log = LoggerFactory.getLogger(RegisterRequestProcessor.class); private SipConfig sipConfig; @@ -56,9 +59,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { @Override public void process(RequestEvent evt) { try { - System.out.println("收到注册请求,开始处理"); + log.debug("收到注册请求,开始处理"); Request request = evt.getRequest(); - + log.debug("request: {}",request.toString()); Response response = null; boolean passwordCorrect = false; // 注册标志 0:未携带授权头或者密码错误 1:注册成功 2:注销成功 @@ -75,9 +78,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { if (authorhead == null || !passwordCorrect) { if (authorhead == null) { - System.out.println("未携带授权头 回复401"); + log.debug("未携带授权头 回复401"); } else if (!passwordCorrect) { - System.out.println("密码错误 回复401"); + log.debug("密码错误 回复401"); } response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getSipDomain()); @@ -137,12 +140,12 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { // 保存到redis // 下发catelog查询目录 if (registerFlag == 1 && device != null) { - System.out.println("注册成功! deviceId:" + device.getDeviceId()); + log.debug("注册成功! deviceId:" + device.getDeviceId()); storager.update(device); publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); handler.onRegister(device); } else if (registerFlag == 2) { - System.out.println("注销成功! deviceId:" + device.getDeviceId()); + log.debug("注销成功! deviceId:" + device.getDeviceId()); publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); } } catch (SipException | InvalidArgumentException | NoSuchAlgorithmException | ParseException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java index 010659e..bbcb260 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/SubscribeRequestProcessor.java @@ -11,6 +11,8 @@ import javax.sip.message.Request; import javax.sip.message.Response; import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @Description:SUBSCRIBE请求处理器 @@ -18,7 +20,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso * @date: 2020年5月3日 下午5:31:20 */ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor { - + private static Logger log = LoggerFactory.getLogger(SubscribeRequestProcessor.class); /** * 处理SUBSCRIBE请求 * @@ -38,13 +40,13 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor { ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30); response.setExpires(expireHeader); } - System.out.println("response : " + response.toString()); + log.debug("response : " + response.toString()); ServerTransaction transaction = getServerTransaction(evt); if (transaction != null) { transaction.sendResponse(response); transaction.terminate(); } else { - System.out.println("processRequest serverTransactionId is null."); + log.debug("processRequest serverTransactionId is null."); } } catch (ParseException e) { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7e6bc40..9bdaf78 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -39,4 +39,7 @@ sip: media: # ip: 10.200.64.88 ip: 192.168.0.102 - port: 10000 \ No newline at end of file + port: 10000 + +log: + path: /app/lboss/pro/gb28181/logs \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..13486a3 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + ${consolePattern} + + + + + + ${filePath} + 30 + + + ${consolePattern} + + + + + + + + + +