1

I have a struts based application in which I am calling my Restful Web Service. My actual service invocation looks like below:

      RestTemplate restTemplate = new RestTemplate();
      ResponseEntity<String> response = restTemplate.exchange(testUrl, httpMethod, entity, String.class);

Call go through just fine but I want to handle the scenario if in case my service is down I want to timeout in like 1 minute instead of waiting for so long.

Newbie Here
  • 55
  • 2
  • 13

1 Answers1

1

You can go for Spring Rest template which provide methods for timeout handling:

For connect timeout:

RestTemplate restTemplate = new RestTemplate();
((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(2000);

For read timeout:

((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(2000);

For more information please visit the documentation page: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/client/SimpleClientHttpRequestFactory.html

Ravi Sharma
  • 197
  • 1
  • 4