【问题标题】:How to set the connection Timeout for SOAP?如何设置 SOAP 的连接超时?
【发布时间】:2021-11-08 10:38:57
【问题描述】:

我正在使用以下示例代码soap

SSLConnectionSocketFactory socketFactory =
        new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    HttpClient httpClient = HttpClients.custom()
        .setSSLSocketFactory(socketFactory)
        .addInterceptorFirst(new RemoHttpHeadersInterceptor())
        .setMaxConnTotal(config.getDefaultMaxTotalConnections())
        .setMaxConnPerRoute(config.getDefaultMaxRouteConnections())
        .build();
    return httpClient;

如何设置连接超时值?我无法在任何地方找到setTimeout api。

【问题讨论】:

  • 嗨,请更准确地说:[httpclient] 不要使用:[apache-commons-httpclient]、[apache-httpclient-4.x]、[jetty-httpclient]、[java-http -客户端]?
  • 对于 [apache-httpclient-4.x],请参阅:RequestConfig / example

标签: java soap httpclient


【解决方案1】:

配置方法是使用RequestConfig:

例子:

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;


 RequestConfig config = RequestConfig.custom()
         .setConnectTimeout(5000)
         .setConnectionRequestTimeout(5000)
         .setSocketTimeout(5000).build();

 HttpClients.custom()
         .setDefaultRequestConfig(config)
         .setSSLSocketFactory(socketFactory)
         .addInterceptorFirst(new RemoHttpHeadersInterceptor())
         .setMaxConnTotal(config.getDefaultMaxTotalConnections())
         .setMaxConnPerRoute(config.getDefaultMaxRouteConnections())
         .build();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多