0

I implemented a custom CloseableHttpClient like below:

        private WebServiceMessageSender createWebServiceMessageSender() {
            HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();

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

            SocketConfig socketConfig = SocketConfig.custom()
                    .setSoTimeout(4000)
                    .build();

            CloseableHttpClient httpClient = HttpClientBuilder.create()
                    .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor())
                    .setDefaultRequestConfig(config)
                    .setDefaultSocketConfig(socketConfig)
                    .disableAutomaticRetries()
                    .build();

            httpComponentsMessageSender.setHttpClient(httpClient);
            return httpComponentsMessageSender;
        }

and I injected this method to WebServiceTemplate as setMessageSender.

The problem is receiving the connection timeout (not the read timeout!) after 10 seconds, not as I configured above (4000 milliseconds). I have no idea why this webservice does not execute the timeout at the specified time, but waits 10 seconds. Has anyone had a similar problem?

Dependencies:

  • Spring-Boot: 2.7.x

  • spring-ws-core: 3.1.3

  • httpclient: 4.5.13

I`m calling google.com on port 81

f_puras
  • 2,521
  • 4
  • 33
  • 38
raf9
  • 11
  • 3
  • 1
    Does this answer your question? [Java HTTP Client Request with defined timeout](https://stackoverflow.com/questions/3000214/java-http-client-request-with-defined-timeout) – aled Apr 24 '23 at 12:20
  • @aled I received `message=I/O error: null; nested exception is org.apache.http.client.ClientProtocolException` in under 1sec ms when I implemented the code from the accepted answer. Also this method is deprecated in HttpClient 4.5.x – raf9 Apr 24 '23 at 12:57
  • setting `httpComponentsMessageSender.setReadTimeout(30000)` and `httpComponentsMessageSender.setConnectionTimeout(4000)` also doesn't help – raf9 Apr 24 '23 at 12:59
  • almost identical problem is here https://stackoverflow.com/questions/66478510/webservicetemplate-timeout-works-only-when-it-is-configured-under-21-seconds?rq=2 – raf9 Apr 24 '23 at 13:33
  • the problem is in Istio mesh config `connectTimeout` https://cloudnative.to/istio.io/docs/reference/config/istio.mesh.v1alpha1/ – raf9 Apr 25 '23 at 12:05

1 Answers1

1

10s connection timeout is default value in Istio MeshConfig connectTimeout https://istio.io/v1.12/docs/reference/config/istio.mesh.v1alpha1/

raf9
  • 11
  • 3