title: Using Apache HttpClient how to set the TIMEOUT on a request and response
body: <p>I need to set time out for the Http Request we make to a service (not a web service).  We are using Apache HTTP Client. I have added these 2 lines of code to set the time out on request and response to the service. </p>
  
  <pre><code>HttpConnectionParams.setConnectionTimeout(params, 10000);
  HttpConnectionParams.setSoTimeout(params, 10000);
  </code></pre>
  
  <p>1) Currently I have set 10 seconds as the timeout since I see the response coming from the service almost instantaneously. Should I increase or decrease the timing? </p>
  
  <p>2) What will happen when response is takes more than 10 seconds?  Will it throw exception and what exception will it be? Is there any thing else I need to add to set the time out in the below code.</p>
  
  <pre><code>public HashMap&lt;String, Object&gt; getJSONData(String url) throw Exception{
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpParams params = httpClient.getParams();
      HttpConnectionParams.setConnectionTimeout(params, 10000);
      HttpConnectionParams.setSoTimeout(params, 10000);
      HttpHost proxy = new HttpHost(getProxy(), getProxyPort());
      ConnRouteParams.setDefaultProxy(params, proxy);
      URI uri;
      InputStream data = null;
      try {
          uri = new URI(url);
          HttpGet method = new HttpGet(uri);
          HttpResponse response = httpClient.execute(method);
          data = response.getEntity().getContent();
      }
      catch (Exception e) {
          e.printStackTrace();
      }
      Reader r = new InputStreamReader(data);
      HashMap&lt;String, Object&gt; jsonObj = (HashMap&lt;String, Object&gt;) GenericJSONUtil.fromJson(r);
      return jsonObj;
  }
  </code></pre>