title: How to catch time out exception when use RestTemplate call API
body: <p>I'm have function call api, use RestTemplate. I want catch exception when time out will return null, this is my code:</p>
  
  <pre><code>//Create resttemplate
  public List&lt;String&gt; getRoleUser(String username) {
      try{
          RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());
          String[] list = restTemplate.getForObject("(link call api)", String[].class);
          return Arrays.asList(list);
      }catch (Exception ex){
          ex.printStackTrace();
          return null;
      }
  }
  
  //Override timeouts in request factory
  private SimpleClientHttpRequestFactory getClientHttpRequestFactory()
  {
      SimpleClientHttpRequestFactory clientHttpRequestFactory
                        = new SimpleClientHttpRequestFactory();
      //Connect timeout
      clientHttpRequestFactory.setConnectTimeout(10_000);
  
      //Read timeout
      clientHttpRequestFactory.setReadTimeout(10_000);
      return clientHttpRequestFactory;
  }
  </code></pre>
  
  <p>but it don't work.
  So, how can I return null when time out?</p>