diff --git a/api/src/main/java/cn/skcks/docking/gb28181/advice/ExceptionAdvice.java b/api/src/main/java/cn/skcks/docking/gb28181/advice/ExceptionAdvice.java index d1b5a7e..c490b67 100644 --- a/api/src/main/java/cn/skcks/docking/gb28181/advice/ExceptionAdvice.java +++ b/api/src/main/java/cn/skcks/docking/gb28181/advice/ExceptionAdvice.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.async.AsyncRequestTimeoutException; import java.util.Objects; @@ -72,6 +73,12 @@ public class ExceptionAdvice { return JsonResponse.error("参数异常"); } + @ExceptionHandler(AsyncRequestTimeoutException.class) + public JsonResponse exception(AsyncRequestTimeoutException e) { + e.printStackTrace(); + return JsonResponse.error("请求超时"); + } + @ExceptionHandler(Exception.class) public JsonResponse exception(Exception e) { e.printStackTrace(); diff --git a/api/src/main/java/cn/skcks/docking/gb28181/api/gb28181/catalog/CatalogController.java b/api/src/main/java/cn/skcks/docking/gb28181/api/gb28181/catalog/CatalogController.java index ee5264d..31a257f 100644 --- a/api/src/main/java/cn/skcks/docking/gb28181/api/gb28181/catalog/CatalogController.java +++ b/api/src/main/java/cn/skcks/docking/gb28181/api/gb28181/catalog/CatalogController.java @@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.async.DeferredResult; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -22,8 +23,12 @@ public class CatalogController { @SneakyThrows @GetJson - public JsonResponse> catalog(String gbDeviceId){ + public DeferredResult>> catalog(String gbDeviceId){ + DeferredResult>> result = new DeferredResult<>(); CompletableFuture> catalog = catalogService.catalog(gbDeviceId); - return JsonResponse.success(catalog.get()); + catalog.whenComplete((data,throwable)->{ + result.setResult(JsonResponse.success(data)); + }); + return result; } } diff --git a/starter/src/main/resources/application.yml b/starter/src/main/resources/application.yml index 59ab111..e8a728d 100644 --- a/starter/src/main/resources/application.yml +++ b/starter/src/main/resources/application.yml @@ -3,3 +3,7 @@ server: project: version: @project.version@ +spring: + mvc: + async: + request-timeout: 3m diff --git a/starter/src/test/resources/application.yml b/starter/src/test/resources/application.yml index 26651ce..ffe9294 100644 --- a/starter/src/test/resources/application.yml +++ b/starter/src/test/resources/application.yml @@ -24,6 +24,9 @@ spring: username: root password: 12341234 url: jdbc:mysql://10.10.10.200:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + mvc: + async: + request-timeout: 3m gb28181: # 作为28181服务器的配置 @@ -42,7 +45,7 @@ gb28181: # [可选] domain: 4405010000 # [可选] - id: 44050100002000000002 + id: 44050100002000000003 # [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验 password: 123456 # 是否存储alarm信息 @@ -50,7 +53,7 @@ gb28181: media: ip: 10.10.10.200 - url: 'http://10.10.10.200:5080' + url: 'http://10.10.10.200:5081' # url: 'http://10.10.10.200:12580/anything/' id: amrWMKmbKqoBjRQ9 secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333