title: Handle Connection and Read Timeouts for RestClient calls in android
body: <p>I have a RestService interface with many rest calls which I am using throughout my application. </p>
  
  <p>I am setting timeouts for handling <code>connection</code> and <code>read-timeouts</code></p>
  
  <pre><code>ClientHttpRequestFactory httpFactory = myRestService.getRestTemplate().getRequestFactory();
      if(httpFactory!=null)
      {
          if(httpFactory instanceof SimpleClientHttpRequestFactory)
          {
              ((SimpleClientHttpRequestFactory)httpFactory).setConnectTimeout(10*1000);
              ((SimpleClientHttpRequestFactory)httpFactory).setReadTimeout(30*1000);
          }
          else if(httpFactory instanceof HttpComponentsClientHttpRequestFactory)
          {
              ((HttpComponentsClientHttpRequestFactory)httpFactory).setConnectTimeout(10*1000);
              ((HttpComponentsClientHttpRequestFactory)httpFactory).setReadTimeout(30*1000);
          }
      }
  </code></pre>
  
  <p>But I am stuck with handling the timeout situation. 
  I thought of using this method but it is not coming into this loop when rest call fails.</p>
  
  <pre><code>myRestService.getRestTemplate().setErrorHandler(new ResponseErrorHandler() 
      {
          @Override
          public boolean hasError(ClientHttpResponse paramClientHttpResponse) throws IOException 
          {
              Log.e(TAG, paramClientHttpResponse==null?"Null response" : ("Has Error : " + paramClientHttpResponse.getStatusText()+" , status code : "+paramClientHttpResponse.getStatusCode()));
  
              return false;
          }
          @Override
          public void handleError(ClientHttpResponse paramClientHttpResponse) throws IOException 
          {
              Log.e(TAG, paramClientHttpResponse==null?"Null response":("Handle Error : " + paramClientHttpResponse.getStatusText()+" , status code : "+paramClientHttpResponse.getStatusCode()));
          }
      });
  </code></pre>
  
  <p>Can anybody help me with this..!?</p>