Reputation: 1396
I am using the following sample code 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;
How can I set the connection timeout value? I am not able to find the setTimeout
api anywhere.
Upvotes: 1
Views: 907
Reputation: 8383
The way to configure it is to use a RequestConfig:
Example:
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();
Upvotes: 1