CatalogController 调整

全局默认异步超时时间 3 min
This commit is contained in:
shikong 2023-10-03 11:28:21 +08:00
parent 7b3f2a57a2
commit 6202acb560
4 changed files with 23 additions and 4 deletions

View File

@ -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<String> exception(AsyncRequestTimeoutException e) {
e.printStackTrace();
return JsonResponse.error("请求超时");
}
@ExceptionHandler(Exception.class)
public JsonResponse<String> exception(Exception e) {
e.printStackTrace();

View File

@ -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<List<?>> catalog(String gbDeviceId){
public DeferredResult<JsonResponse<List<?>>> catalog(String gbDeviceId){
DeferredResult<JsonResponse<List<?>>> result = new DeferredResult<>();
CompletableFuture<List<CatalogItemDTO>> catalog = catalogService.catalog(gbDeviceId);
return JsonResponse.success(catalog.get());
catalog.whenComplete((data,throwable)->{
result.setResult(JsonResponse.success(data));
});
return result;
}
}

View File

@ -3,3 +3,7 @@ server:
project:
version: @project.version@
spring:
mvc:
async:
request-timeout: 3m

View File

@ -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