rest template how to set set read timeout and pooling connection manager

80 Views Asked by At

in spring boot 3.2.2, it's possible to create a rest template like this

RestTemplate rt =  builder.requestFactory(() -> new BufferingClientHttpRequestFactory(
        new HttpComponentsClientHttpRequestFactory(client)
))
.setReadTimeout(Duration.ofMillis(5000))
.build();

where we're providing a custom http client object with some ssl connection factory and pooling connection manager, however, then setReadTimeout() is throwing exception about the method being deprecated, as mentioned here

https://github.com/spring-projects/spring-boot/issues/35658

so according to that, the solution would be (this resolves the issue with exception)

builder.requestFactory((settings) -> new BufferingClientHttpRequestFactory(
        ClientHttpRequestFactories.get(HttpComponentsClientHttpRequestFactory.class, settings)))
        .setConnectTimeout(Duration.ofSeconds(300))
        .setReadTimeout(Duration.ofSeconds(300))
        .build();

but then i wonder how to set the ssl connection factory, connection manager etc.

0

There are 0 best solutions below