异常捕获修正
This commit is contained in:
parent
e8f5bfd1b0
commit
405e29c15b
@ -7,16 +7,13 @@ import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe;
|
|||||||
import cn.skcks.docking.gb28181.core.sip.message.subscribe.SipSubscribe;
|
import cn.skcks.docking.gb28181.core.sip.message.subscribe.SipSubscribe;
|
||||||
import cn.skcks.docking.gb28181.core.sip.service.SipService;
|
import cn.skcks.docking.gb28181.core.sip.service.SipService;
|
||||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice;
|
||||||
import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDeviceChannel;
|
|
||||||
import cn.skcks.docking.gb28181.service.device.DeviceChannelService;
|
import cn.skcks.docking.gb28181.service.device.DeviceChannelService;
|
||||||
import cn.skcks.docking.gb28181.service.docking.device.cache.DockingDeviceCacheService;
|
import cn.skcks.docking.gb28181.service.docking.device.cache.DockingDeviceCacheService;
|
||||||
import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogQueryDTO;
|
import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogQueryDTO;
|
||||||
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogItemDTO;
|
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogItemDTO;
|
||||||
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogResponseDTO;
|
|
||||||
import cn.skcks.docking.gb28181.sip.method.message.request.MessageRequestBuilder;
|
import cn.skcks.docking.gb28181.sip.method.message.request.MessageRequestBuilder;
|
||||||
import cn.skcks.docking.gb28181.sip.utils.MANSCDPUtils;
|
import cn.skcks.docking.gb28181.sip.utils.MANSCDPUtils;
|
||||||
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
|
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
|
||||||
import gov.nist.javax.sip.message.SIPRequest;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -24,13 +21,10 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import javax.sip.SipProvider;
|
import javax.sip.SipProvider;
|
||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Flow;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@ -10,26 +10,25 @@ public class FutureDeferredResult {
|
|||||||
public static <T> DeferredResult<JsonResponse<T>> toDeferredResultWithJson(CompletableFuture<T> future){
|
public static <T> DeferredResult<JsonResponse<T>> toDeferredResultWithJson(CompletableFuture<T> future){
|
||||||
DeferredResult<JsonResponse<T>> result = new DeferredResult<>();
|
DeferredResult<JsonResponse<T>> result = new DeferredResult<>();
|
||||||
future.whenComplete((data,throwable)->{
|
future.whenComplete((data,throwable)->{
|
||||||
|
if(throwable!= null){
|
||||||
|
result.setResult(JsonResponse.error(throwable.getMessage()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
result.setResult(JsonResponse.success(data));
|
result.setResult(JsonResponse.success(data));
|
||||||
});
|
});
|
||||||
future.exceptionally(e -> {
|
|
||||||
result.setResult(JsonResponse.error(e.getMessage()));
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> DeferredResult<JsonResponse<T>> toDeferredResultWithJsonAndTimeout(CompletableFuture<T> future, long time, TimeUnit timeUnit){
|
public static <T> DeferredResult<JsonResponse<T>> toDeferredResultWithJsonAndTimeout(CompletableFuture<T> future, long time, TimeUnit timeUnit){
|
||||||
DeferredResult<JsonResponse<T>> result = new DeferredResult<>(timeUnit.toMillis(time));
|
DeferredResult<JsonResponse<T>> result = new DeferredResult<>(timeUnit.toMillis(time));
|
||||||
result.onTimeout(()-> result.setResult(JsonResponse.error("请求超时")));
|
result.onTimeout(()-> result.setResult(JsonResponse.error("请求超时")));
|
||||||
|
|
||||||
future.whenComplete((data,throwable)->{
|
future.whenComplete((data,throwable)->{
|
||||||
|
if(throwable!= null){
|
||||||
|
result.setResult(JsonResponse.error(throwable.getMessage()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
result.setResult(JsonResponse.success(data));
|
result.setResult(JsonResponse.success(data));
|
||||||
});
|
});
|
||||||
future.exceptionally(e -> {
|
|
||||||
result.setResult(JsonResponse.error(e.getMessage()));
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user