I am using **RestTemplate** to call an external service. One such request took more than 30 seconds and the springboot API call errored with the following message:
Caused by: java.io.IOException: Idle timeout expired: 30000/30000 ms
at org.springframework.http.client.JettyClientHttpRequest.executeInternal(JettyClientHttpRequest.java:120)
at org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal(AbstractStreamingClientHttpRequest.java:70)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:112)
at com.boomi.bundle.service.integration.hook.BaseRestTemplateInterceptor.intercept(BaseRestTemplateInterceptor.java:30)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88)
Is there a property for configuring the idle timeout? I have already set the following value
server.jetty.connection-idle-timeout=800000. Without this property is was timing out at 10 seconds
Any help is appreciated.
Requests made using RESTTemplate should complete if it is within the server.jetty.connection-idle-timeout limit
In Spring 3.4.2 you can provide custom request factory in RestTemplateBuilder:
import org.springframework.http.client.SimpleClientHttpRequestFactory;
public RestTemplateBuilder getBuilder(Duration timeout) {
return restTemplateBuilder
.requestFactory(() -> {
var factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(timeout);
factory.setReadTimeout(timeout);
return factory;
})
.connectTimeout(timeout)
.readTimeout(timeout);
}
Then depending on your need build rest template:
getBuilder(ofSeconds(120)).build();
This solved issue in my case.
Remember to consider other timeouts when increasing this one (load balancers, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With