Various places to configure httpclient timeout in Spring boot

2 weeks ago 26
ARTICLE AD BOX

I am using Spring boot version 3.5.9 and httpclient version 5.5.1, and aware that Spring boot have some issue regarding set the connect timeout for httpclient 5.5.1.

refer the github issue here: https://github.com/spring-projects/spring-boot/issues/47940

and which seems to be fixed by this commit:https://github.com/spring-projects/spring-boot/commit/0ca8f6d03f84132563e7c9b07c034b381297b0bf#diff-8b43c3d64899c92eceef16c0119431ad2d54515c540e2b45ae097864cf91a208 in spring boot 3.5.8.

Now I am confused about the current behavior, Now if I want to configure all types of timeout for http requets,

I can configure the connect timeout and readtime out easily as below:

@Bean public RestTemplate restTemplateWithTimeout() { ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.defaults() .withConnectTimeout(Duration.ofSeconds(1)) .withReadTimeout(Duration.ofSeconds(1)); return restTemplateBuilder .requestFactorySettings(settings) .build(); }

But why does spring boot do not support to configure the connectionrequesttimeout here as well?

So to configure the connection request timeout, I still need to build a HttpComponentsClientHttpRequestFactory and set it to the resttemplate with the configuration like below:

private HttpComponentsClientHttpRequestFactory buildClientHttpRequestFactoryWithTimeout() { HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(); clientHttpRequestFactory.setConnectionRequestTimeout(timeout); return clientHttpRequestFactory; }

Why does Spring boot not privide a consistent configuration for these 3 properties?

Read Entire Article