From bc7cc73d52261b57445c3462bdbd784eb70ae011 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 22 三月 2023 15:21:22 +0800
Subject: [PATCH] 修复可空时间参数的校验 #784
---
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java | 17 ++++----
src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java | 12 ++++++
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java | 19 +++++----
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java | 17 +++-----
4 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
index dbea741..0333e0d 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
@@ -8,6 +8,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -43,6 +44,17 @@
return WVPResult.fail(ErrorCode.ERROR400);
}
+ /**
+ * 榛樿寮傚父澶勭悊
+ * @param e 寮傚父
+ * @return 缁熶竴杩斿洖缁撴灉
+ */
+ @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public WVPResult<String> exceptionHandler(HttpRequestMethodNotSupportedException e) {
+ return WVPResult.fail(ErrorCode.ERROR400);
+ }
+
/**
* 鑷畾涔夊紓甯稿鐞嗭紝 澶勭悊controller涓繑鍥炵殑閿欒
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
index d84fb79..6f2a585 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
@@ -71,11 +71,11 @@
if (ObjectUtils.isEmpty(deviceIds)) {
deviceIds = null;
}
+
if (ObjectUtils.isEmpty(time)) {
time = null;
- }
- if (!DateUtil.verification(time, DateUtil.formatter) ){
- return null;
+ }else if (!DateUtil.verification(time, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "time鏍煎紡涓�" + DateUtil.PATTERN);
}
List<String> deviceIdList = null;
if (deviceIds != null) {
@@ -170,16 +170,17 @@
if (ObjectUtils.isEmpty(alarmType)) {
alarmType = null;
}
+
if (ObjectUtils.isEmpty(startTime)) {
startTime = null;
+ }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
}
+
if (ObjectUtils.isEmpty(endTime)) {
endTime = null;
- }
-
-
- if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
- throw new ControllerException(ErrorCode.ERROR100.getCode(), "寮�濮嬫椂闂存垨缁撴潫鏃堕棿鏍煎紡鏈夎");
+ }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
}
return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
index 093b324..0dcc5ad 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
@@ -3,32 +3,29 @@
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
+import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IPlayService;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
-
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
-
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
@@ -74,10 +71,10 @@
}
DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>();
if (!DateUtil.verification(startTime, DateUtil.formatter)){
- throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime error, format is " + DateUtil.PATTERN);
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
}
if (!DateUtil.verification(endTime, DateUtil.formatter)){
- throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime error, format is " + DateUtil.PATTERN);
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
}
Device device = storager.queryVideoDevice(deviceId);
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
index 3cabb99..a412b10 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
@@ -60,18 +60,21 @@
if (ObjectUtils.isEmpty(query)) {
query = null;
}
- if (ObjectUtils.isEmpty(startTime)) {
- startTime = null;
- }
- if (ObjectUtils.isEmpty(endTime)) {
- endTime = null;
- }
+
if (!userSetting.getLogInDatebase()) {
logger.warn("鑷姩璁板綍鏃ュ織鍔熻兘宸插叧闂紝鏌ヨ缁撴灉鍙兘涓嶅畬鏁淬��");
}
- if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
- throw new ControllerException(ErrorCode.ERROR400);
+ if (ObjectUtils.isEmpty(startTime)) {
+ startTime = null;
+ }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
+ }
+
+ if (ObjectUtils.isEmpty(endTime)) {
+ endTime = null;
+ }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
}
return logService.getAll(page, count, query, type, startTime, endTime);
--
Gitblit v1.8.0