[英]How to set a timeout with a default soap response in soap producer?
我知道超时是客户端的属性,但我们需要在 2 分钟内从 spring soap 端点发送响应。
如何在 spring soap 中超时并在指定时间内从 soap 生产者应用程序发送默认响应?
容器:Tomcat
@Endpoint
public class SOAPEndpoint {
private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
private Repository repository;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getData")
@ResponsePayload
public Response getCountry(@RequestPayload SampleRequest request) {
Response response = new Response();
response.setCountry(repository.retrieveData(request.getParam())); // this lines takes 5 minutes to respond
return response;
}
}
我找不到基于配置的解决方案,但这里有一些可能的基于库的解决方案:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
TimeLimiter timeLimiter = TimeLimiter.of(Duration.ofSeconds(1));
try {
Country country = timeLimiter.executeFutureSupplier(() ->
CompletableFuture.supplyAsync(() -> countryRepository.findCountry(request.getName())));
response.setCountry(country);
return response;
} catch (TimeoutException e) {
e.printStackTrace(); // handle timeout.
} catch (Exception e) {
e.printStackTrace(); // handle general error.
}
return null; // You may want to replace this.
}
上面的生产者代码源自 - https://spring.io/guides/gs/produce-web-service/并针对消费者进行了测试 - https://spring.io/guides/gs/sumption-web-service /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.