简体   繁体   English

如何在从 spring 集成调用 SOAP 服务时添加超时

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

While calling soap service from spring integration how to add timeout?从 spring 集成调用 soap 服务时如何添加超时? Below is the code where I'm calling a soap service using Ws.marshallingOutboundGateway().下面是我使用 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;
  }

Is there a way I can do something like below -有没有办法我可以做如下的事情 -

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

Here I have added timeout in the resttemplate that I've passed.在这里,我在我通过的 resttemplate 中添加了超时。

Use the HttpComponentsMessageSender in the template, instead of the default使用模板中的HttpComponentsMessageSender ,而不是默认的

https://docs.spring.io/spring-ws/docs/current/reference/html/#_using_the_client_side_api 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