Commit 4172e6c64b1e18ff18958db58fec5a378d0a37dc
1 parent
3e4d2b68
修复可空时间参数的校验 #784
Showing
4 changed files
with
38 additions
and
25 deletions
src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
| ... | ... | @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; |
| 8 | 8 | import org.springframework.http.HttpStatus; |
| 9 | 9 | import org.springframework.http.ResponseEntity; |
| 10 | 10 | import org.springframework.security.authentication.BadCredentialsException; |
| 11 | +import org.springframework.web.HttpRequestMethodNotSupportedException; | |
| 11 | 12 | import org.springframework.web.bind.annotation.ExceptionHandler; |
| 12 | 13 | import org.springframework.web.bind.annotation.ResponseStatus; |
| 13 | 14 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| ... | ... | @@ -43,6 +44,17 @@ public class GlobalExceptionHandler { |
| 43 | 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 | 60 | * 自定义异常处理, 处理controller中返回的错误 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
| ... | ... | @@ -71,11 +71,11 @@ public class AlarmController { |
| 71 | 71 | if (ObjectUtils.isEmpty(deviceIds)) { |
| 72 | 72 | deviceIds = null; |
| 73 | 73 | } |
| 74 | + | |
| 74 | 75 | if (ObjectUtils.isEmpty(time)) { |
| 75 | 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 | 80 | List<String> deviceIdList = null; |
| 81 | 81 | if (deviceIds != null) { |
| ... | ... | @@ -170,16 +170,17 @@ public class AlarmController { |
| 170 | 170 | if (ObjectUtils.isEmpty(alarmType)) { |
| 171 | 171 | alarmType = null; |
| 172 | 172 | } |
| 173 | + | |
| 173 | 174 | if (ObjectUtils.isEmpty(startTime)) { |
| 174 | 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 | 180 | if (ObjectUtils.isEmpty(endTime)) { |
| 177 | 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 | 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 | 3 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| 5 | 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 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 7 | 11 | import com.genersoft.iot.vmp.service.IDeviceService; |
| 8 | 12 | import com.genersoft.iot.vmp.service.IPlayService; |
| 13 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | |
| 9 | 14 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 10 | 15 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 11 | 16 | import com.genersoft.iot.vmp.vmanager.bean.StreamContent; |
| 12 | 17 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 13 | - | |
| 14 | 18 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | 19 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | 20 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | 21 | import org.slf4j.Logger; |
| 18 | 22 | import org.slf4j.LoggerFactory; |
| 19 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | -import org.springframework.web.bind.annotation.CrossOrigin; | |
| 21 | 24 | import org.springframework.web.bind.annotation.GetMapping; |
| 22 | 25 | import org.springframework.web.bind.annotation.PathVariable; |
| 23 | 26 | import org.springframework.web.bind.annotation.RequestMapping; |
| 24 | 27 | import org.springframework.web.bind.annotation.RestController; |
| 25 | 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 | 30 | import javax.sip.InvalidArgumentException; |
| 34 | 31 | import javax.sip.SipException; |
| 35 | 32 | import java.text.ParseException; |
| ... | ... | @@ -74,10 +71,10 @@ public class GBRecordController { |
| 74 | 71 | } |
| 75 | 72 | DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>(); |
| 76 | 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 | 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 | 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 | 60 | if (ObjectUtils.isEmpty(query)) { |
| 61 | 61 | query = null; |
| 62 | 62 | } |
| 63 | + | |
| 64 | + if (!userSetting.getLogInDatebase()) { | |
| 65 | + logger.warn("自动记录日志功能已关闭,查询结果可能不完整。"); | |
| 66 | + } | |
| 67 | + | |
| 63 | 68 | if (ObjectUtils.isEmpty(startTime)) { |
| 64 | 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 | 74 | if (ObjectUtils.isEmpty(endTime)) { |
| 67 | 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 | 80 | return logService.getAll(page, count, query, type, startTime, endTime); | ... | ... |