Commit 4172e6c64b1e18ff18958db58fec5a378d0a37dc

Authored by 648540858
1 parent 3e4d2b68

修复可空时间参数的校验 #784

src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
8 import org.springframework.http.HttpStatus; 8 import org.springframework.http.HttpStatus;
9 import org.springframework.http.ResponseEntity; 9 import org.springframework.http.ResponseEntity;
10 import org.springframework.security.authentication.BadCredentialsException; 10 import org.springframework.security.authentication.BadCredentialsException;
  11 +import org.springframework.web.HttpRequestMethodNotSupportedException;
11 import org.springframework.web.bind.annotation.ExceptionHandler; 12 import org.springframework.web.bind.annotation.ExceptionHandler;
12 import org.springframework.web.bind.annotation.ResponseStatus; 13 import org.springframework.web.bind.annotation.ResponseStatus;
13 import org.springframework.web.bind.annotation.RestControllerAdvice; 14 import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -43,6 +44,17 @@ public class GlobalExceptionHandler { @@ -43,6 +44,17 @@ public class GlobalExceptionHandler {
43 return WVPResult.fail(ErrorCode.ERROR400); 44 return WVPResult.fail(ErrorCode.ERROR400);
44 } 45 }
45 46
  47 + /**
  48 + * 默认异常处理
  49 + * @param e 异常
  50 + * @return 统一返回结果
  51 + */
  52 + @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
  53 + @ResponseStatus(HttpStatus.BAD_REQUEST)
  54 + public WVPResult<String> exceptionHandler(HttpRequestMethodNotSupportedException e) {
  55 + return WVPResult.fail(ErrorCode.ERROR400);
  56 + }
  57 +
46 58
47 /** 59 /**
48 * 自定义异常处理, 处理controller中返回的错误 60 * 自定义异常处理, 处理controller中返回的错误
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
@@ -71,11 +71,11 @@ public class AlarmController { @@ -71,11 +71,11 @@ public class AlarmController {
71 if (ObjectUtils.isEmpty(deviceIds)) { 71 if (ObjectUtils.isEmpty(deviceIds)) {
72 deviceIds = null; 72 deviceIds = null;
73 } 73 }
  74 +
74 if (ObjectUtils.isEmpty(time)) { 75 if (ObjectUtils.isEmpty(time)) {
75 time = null; 76 time = null;
76 - }  
77 - if (!DateUtil.verification(time, DateUtil.formatter) ){  
78 - return null; 77 + }else if (!DateUtil.verification(time, DateUtil.formatter) ){
  78 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "time格式为" + DateUtil.PATTERN);
79 } 79 }
80 List<String> deviceIdList = null; 80 List<String> deviceIdList = null;
81 if (deviceIds != null) { 81 if (deviceIds != null) {
@@ -170,16 +170,17 @@ public class AlarmController { @@ -170,16 +170,17 @@ public class AlarmController {
170 if (ObjectUtils.isEmpty(alarmType)) { 170 if (ObjectUtils.isEmpty(alarmType)) {
171 alarmType = null; 171 alarmType = null;
172 } 172 }
  173 +
173 if (ObjectUtils.isEmpty(startTime)) { 174 if (ObjectUtils.isEmpty(startTime)) {
174 startTime = null; 175 startTime = null;
  176 + }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
  177 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime格式为" + DateUtil.PATTERN);
175 } 178 }
  179 +
176 if (ObjectUtils.isEmpty(endTime)) { 180 if (ObjectUtils.isEmpty(endTime)) {
177 endTime = null; 181 endTime = null;
178 - }  
179 -  
180 -  
181 - if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){  
182 - throw new ControllerException(ErrorCode.ERROR100.getCode(), "开始时间或结束时间格式有误"); 182 + }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
  183 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime格式为" + DateUtil.PATTERN);
183 } 184 }
184 185
185 return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod, 186 return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
@@ -3,33 +3,30 @@ package com.genersoft.iot.vmp.vmanager.gb28181.record; @@ -3,33 +3,30 @@ package com.genersoft.iot.vmp.vmanager.gb28181.record;
3 import com.genersoft.iot.vmp.common.StreamInfo; 3 import com.genersoft.iot.vmp.common.StreamInfo;
4 import com.genersoft.iot.vmp.conf.exception.ControllerException; 4 import com.genersoft.iot.vmp.conf.exception.ControllerException;
5 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; 5 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
  6 +import com.genersoft.iot.vmp.gb28181.bean.Device;
  7 +import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
  8 +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
6 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; 9 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
  10 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
7 import com.genersoft.iot.vmp.service.IDeviceService; 11 import com.genersoft.iot.vmp.service.IDeviceService;
8 import com.genersoft.iot.vmp.service.IPlayService; 12 import com.genersoft.iot.vmp.service.IPlayService;
  13 +import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
9 import com.genersoft.iot.vmp.utils.DateUtil; 14 import com.genersoft.iot.vmp.utils.DateUtil;
10 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; 15 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
11 import com.genersoft.iot.vmp.vmanager.bean.StreamContent; 16 import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
12 import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 17 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
13 -  
14 import io.swagger.v3.oas.annotations.Operation; 18 import io.swagger.v3.oas.annotations.Operation;
15 import io.swagger.v3.oas.annotations.Parameter; 19 import io.swagger.v3.oas.annotations.Parameter;
16 import io.swagger.v3.oas.annotations.tags.Tag; 20 import io.swagger.v3.oas.annotations.tags.Tag;
17 import org.slf4j.Logger; 21 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
20 -import org.springframework.web.bind.annotation.CrossOrigin;  
21 import org.springframework.web.bind.annotation.GetMapping; 24 import org.springframework.web.bind.annotation.GetMapping;
22 import org.springframework.web.bind.annotation.PathVariable; 25 import org.springframework.web.bind.annotation.PathVariable;
23 import org.springframework.web.bind.annotation.RequestMapping; 26 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RestController; 27 import org.springframework.web.bind.annotation.RestController;
25 import org.springframework.web.context.request.async.DeferredResult; 28 import org.springframework.web.context.request.async.DeferredResult;
26 29
27 -import com.genersoft.iot.vmp.gb28181.bean.Device;  
28 -import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;  
29 -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;  
30 -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;  
31 -import com.genersoft.iot.vmp.storager.IVideoManagerStorage;  
32 -  
33 import javax.sip.InvalidArgumentException; 30 import javax.sip.InvalidArgumentException;
34 import javax.sip.SipException; 31 import javax.sip.SipException;
35 import java.text.ParseException; 32 import java.text.ParseException;
@@ -74,10 +71,10 @@ public class GBRecordController { @@ -74,10 +71,10 @@ public class GBRecordController {
74 } 71 }
75 DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>(); 72 DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>();
76 if (!DateUtil.verification(startTime, DateUtil.formatter)){ 73 if (!DateUtil.verification(startTime, DateUtil.formatter)){
77 - throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime error, format is " + DateUtil.PATTERN); 74 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime格式为" + DateUtil.PATTERN);
78 } 75 }
79 if (!DateUtil.verification(endTime, DateUtil.formatter)){ 76 if (!DateUtil.verification(endTime, DateUtil.formatter)){
80 - throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime error, format is " + DateUtil.PATTERN); 77 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime格式为" + DateUtil.PATTERN);
81 } 78 }
82 79
83 Device device = storager.queryVideoDevice(deviceId); 80 Device device = storager.queryVideoDevice(deviceId);
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
@@ -60,18 +60,21 @@ public class LogController { @@ -60,18 +60,21 @@ public class LogController {
60 if (ObjectUtils.isEmpty(query)) { 60 if (ObjectUtils.isEmpty(query)) {
61 query = null; 61 query = null;
62 } 62 }
  63 +
  64 + if (!userSetting.getLogInDatebase()) {
  65 + logger.warn("自动记录日志功能已关闭,查询结果可能不完整。");
  66 + }
  67 +
63 if (ObjectUtils.isEmpty(startTime)) { 68 if (ObjectUtils.isEmpty(startTime)) {
64 startTime = null; 69 startTime = null;
  70 + }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
  71 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime格式为" + DateUtil.PATTERN);
65 } 72 }
  73 +
66 if (ObjectUtils.isEmpty(endTime)) { 74 if (ObjectUtils.isEmpty(endTime)) {
67 endTime = null; 75 endTime = null;
68 - }  
69 - if (!userSetting.getLogInDatebase()) {  
70 - logger.warn("自动记录日志功能已关闭,查询结果可能不完整。");  
71 - }  
72 -  
73 - if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){  
74 - throw new ControllerException(ErrorCode.ERROR400); 76 + }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
  77 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime格式为" + DateUtil.PATTERN);
75 } 78 }
76 79
77 return logService.getAll(page, count, query, type, startTime, endTime); 80 return logService.getAll(page, count, query, type, startTime, endTime);