What is the default timeout value when using Spring's RestTemplate ?
For e.g., I am invoking a web service like this:
RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject("http://webservice.com/item/3455", String.class);
Is there any built-in timeout value for RestTemplate? I am not planning to change the timeout value, however, I want to ensure that there is a reasonable timeout for every request.
Thanks.
To explicitly answer the question...
The default timeout is infinite.
By default RestTemplate uses SimpleClientHttpRequestFactory and that in turn uses HttpURLConnection.
By default the timeout for HttpURLConnection is 0 - ie infinite, unless it has been set by these properties :
One of the nice features of spring-android RestTemplate is the use of appropriate (recommended by Google) implementation of RequestFactory depending on the version of OS.
So the previous answer is not full because HttpComponentsClientHttpRequestFactory (which is used by spring-android for Android OS versions < 2.3) is not taken into consideration.
My solution was something like this:
I think you can use SimpleClientHttpRequestFactory for timeout parameter. Instance of SimpleClientHttpRequestFactory can be set to rest template by constructor or setter method.
By default RestTemplate uses SimpleClientHttpRequestFactory so may be you can directly set value to restTemplate.