private HttpClient getClient ( int retries , int connectionTimeout , int socketTimeout ) { HttpClient httpClient = new DefaultHttpClient ( ) ; HttpParams httpParams = httpClient . getParams ( ) ; // Retries if ( retries > 0 ) { DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler ( retries , true ) ; ( ( AbstractHttpClient ) httpClient ) . setHttpRequestRetryHandler ( retryHandler ) ; } // Timeouts if ( connectionTimeout > 0 ) { httpParams . setParameter ( CoreConnectionPNames . CONNECTION_TIMEOUT , connectionTimeout ) ; } if ( socketTimeout > 0 ) { httpParams . setParameter ( CoreConnectionPNames . SO_TIMEOUT , socketTimeout ) ; } //Proxy if ( StringUtils . isNotEmpty ( proxyHostName ) ) { HttpHost proxy = new HttpHost ( proxyHostName , proxyPort ) ; httpParams . setParameter ( ConnRoutePNames . DEFAULT_PROXY , proxy ) ; } return httpClient ; }
Returns a DefaultHttpClient instance with retries and timeouts settings If proxy information exists its setted on the client .