簡體   English   中英

如何在從 spring 集成調用 SOAP 服務時添加超時

[英]How to add timeout while calling SOAP Service from spring integration

從 spring 集成調用 soap 服務時如何添加超時? 下面是我使用 Ws.marshallingOutboundGateway() 調用 soap 服務的代碼。

@Bean
  public IntegrationFlow flow() {
    return flow ->
        flow.handle(Ws.marshallingOutboundGateway(webServiceTemplate()).uri(someSOAPUrl));
    };
  }

  @Bean
  public WebServiceTemplate webServiceTemplate() throws Exception {
    WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    R123Marshaller marshaller = new R123Marshaller();
    marshaller.setContextPath("com.example.request.soap123");
    webServiceTemplate.setMarshaller(marshaller);

    Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
    unmarshaller.setContextPath("com.example.request.soap123");
    webServiceTemplate.setUnmarshaller(unmarshaller);

    return webServiceTemplate;
  }

有沒有辦法我可以做如下的事情 -

.handle(Http.outboundGateway(someURL, restTemplateConfig.restTemplate())

在這里,我在我通過的 resttemplate 中添加了超時。

使用模板中的HttpComponentsMessageSender ,而不是默認的

https://docs.spring.io/spring-ws/docs/current/reference/html/#_using_the_client_side_api

/**
 * 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) {
    if (timeout < 0) {
        throw new IllegalArgumentException("timeout must be a non-negative value");
    }
    org.apache.http.params.HttpConnectionParams.setSoTimeout(getHttpClient().getParams(), timeout);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM