title: Spring RestTemplate Connection Timeout is not working
body: <p>I am trying to configure time out when external web service call. I am calling external web service by Spring Rest Template in my service. </p>
  
  <p>For connection timeout testing purpose, the external web service is stopped and application server is down.</p>
  
  <p>I have configured 10 seconds for timeout, but unfortunately i get connection refused exception after a second. </p>
  
  <pre><code>try {   
      final RestTemplate restTemplate = new RestTemplate();
  
      ((org.springframework.http.client.SimpleClientHttpRequestFactory)
          restTemplate.getRequestFactory()).setReadTimeout(1000*10);
  
      ((org.springframework.http.client.SimpleClientHttpRequestFactory)
          restTemplate.getRequestFactory()).setConnectTimeout(1000*10);
  
      HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_JSON);
  
      HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(reqJSON, headers);
  
      ResponseEntity&lt;String&gt; response = restTemplate.exchange(wsURI, HttpMethod.POST, entity, String.class);
  
      String premiumRespJSONStr = response.getBody();
  }
  </code></pre>
  
  <p>Please correct my understanding if any.</p>