您好我有关于设置连接超时的问题。 我使用WebServiceTemplate,它有1个messageSender(CommonsHttpMessageSender)。 但是,是否可以为每个URI(端点)设置不同的连接超时?
...此致
public Message sendRequest(OutgoingRequest message, MessageHeaders headers,
EndpointInfoProvider endpointInfoProvider,
WebServiceMessageCallback requestCallback){
Assert.notNull(endpointInfoProvider, "Destination provider is required!");
final Credentials credentials = endpointInfoProvider.getCredentials();
URI destinationUri = endpointInfoProvider.getDestination();
for (WebServiceMessageSender messageSender : webServiceTemplate.getMessageSenders()) {
if (messageSender instanceof CommonsHttpMessageSender) {
HttpClient httpClient = ((CommonsHttpMessageSender) messageSender).getHttpClient();
httpClient.getState().setCredentials(
new AuthScope(destinationUri.getHost(),
destinationUri.getPort(), AuthScope.ANY_REALM,
AuthScope.ANY_SCHEME), credentials
);
httpClient.getParams().setAuthenticationPreemptive(true);
((CommonsHttpMessageSender) messageSender)
.setConnectionTimeout(endpointInfoProvider
.getTimeOutDuration());
}
}
webServiceTemplate.setDestinationProvider(endpointInfoProvider);
//........
}
答案 0 :(得分:0)
Spring WS不支持不同URI的不同超时,并且不打算添加此类功能。鉴于您的问题涉及WebServiceTemplate,您可以轻松配置具有不同超时的多个模板,并根据需要使用它们。