我正在使用
SimpleWebServiceOutboundGateway
simpleGateway.setSendTimeout(1000);
调用Web服务,但有时Web服务需要更多时间来响应,我想设置超时,以便在响应延迟时终止流程。在setSendTimeOut之后,它会一直等待。我怎么能实现超时?
答案 0 :(得分:1)
引用JavaDocs:
/**
* Set the timeout for sending reply Messages.
* @param sendTimeout The send timeout.
*/
public void setSendTimeout(long sendTimeout) {
this.messagingTemplate.setSendTimeout(sendTimeout);
}
作为AbstractMessageProducingHandler
的一部分,它与已经发送到输出通道的消息完全相关。这不是SOAP协议交互的一部分。
您必须查看特定WebServiceMessageSender
的选项。例如,HttpComponentsMessageSender
具有以下选项:
/**
* Sets the timeout until a connection is established. A value of 0 means <em>never</em> timeout.
*
* @param timeout the timeout value in milliseconds
* @see org.apache.http.params.HttpConnectionParams#setConnectionTimeout(org.apache.http.params.HttpParams, int)
*/
public void setConnectionTimeout(int timeout) {
if (timeout < 0) {
throw new IllegalArgumentException("timeout must be a non-negative value");
}
org.apache.http.params.HttpConnectionParams.setConnectionTimeout(getHttpClient().getParams(), timeout);
}
/**
* Set the socket read timeout for the underlying HttpClient. A value of 0 means <em>never</em> timeout.
*
* @param timeout the timeout value in milliseconds
* @see org.apache.http.params.HttpConnectionParams#setSoTimeout(org.apache.http.params.HttpParams, int)
*/
public void setReadTimeout(int timeout) {
答案 1 :(得分:0)
使用配置文件
<int-http:inbound-gateway request-channel="requestData" **reply-timeout="5000"**
supported-methods="GET" path="/{oft}/users/{userId}"
payload-expression="#pathVariables.userId" reply-channel="responseChannel" >
<int-http:header name="outputfile" expression="#pathVariables.oft"/>
</int-http:inbound-gateway>