List of usage examples for org.apache.commons.httpclient.params HttpClientParams setConnectionManagerClass
public void setConnectionManagerClass(Class paramClass)
From source file:edu.utah.further.core.ws.HttpClientTemplate.java
/** * Private {@link HttpClient} initialization. *///ww w. ja v a2 s .c o m @PostConstruct private final void afterPropertiesSet() { // Client is higher in the hierarchy than manager so set the parameters here final HttpClientParams clientParams = new HttpClientParams(); clientParams.setConnectionManagerClass(connectionManager.getClass()); clientParams.setConnectionManagerTimeout(connectionTimeout); clientParams.setSoTimeout(readTimeout); clientParams.setParameter("http.connection.timeout", new Integer(connectionTimeout)); // A retry handler for when a connection fails clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, final int executionCount) { if (executionCount >= retryCount) { // Do not retry if over max retry count return false; } if (instanceOf(exception, NoHttpResponseException.class)) { // Retry if the server dropped connection on us return true; } if (instanceOf(exception, SocketException.class)) { // Retry if the server reset connection on us return true; } if (instanceOf(exception, SocketTimeoutException.class)) { // Retry if the read timed out return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }); httpClient.setParams(clientParams); final HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost); connectionManager.setParams(connectionManagerParams); }