Java 类org.apache.commons.httpclient.HttpMethodRetryHandler 实例源码

项目:cloudstack    文件:HttpDirectTemplateDownloader.java   
protected HttpMethodRetryHandler createRetryTwiceHandler() {
    return new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) {
            if (executionCount >= 2) {
                // Do not retry if over max retry count
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                // Retry if the server dropped connection on us
                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;
        }
    };
}
项目:cloudstack    文件:HttpTemplateDownloader.java   
private HttpMethodRetryHandler createRetryTwiceHandler() {
    return new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) {
            if (executionCount >= 2) {
                // Do not retry if over max retry count
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                // Retry if the server dropped connection on us
                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;
        }
    };
}
项目:cosmic    文件:HTTPUtils.java   
/**
 * @return A HttpMethodRetryHandler with given number of retries.
 */
public static HttpMethodRetryHandler getHttpMethodRetryHandler(final int retryCount) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Initializing new HttpMethodRetryHandler with retry count " + retryCount);
    }

    return 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 (exception instanceof NoHttpResponseException) {
                // Retry if the server dropped connection on us
                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;
        }
    };
}
项目:cloudstack    文件:HTTPUtils.java   
/**
 * @return A HttpMethodRetryHandler with given number of retries.
 */
public static HttpMethodRetryHandler getHttpMethodRetryHandler(final int retryCount) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Initializing new HttpMethodRetryHandler with retry count " + retryCount);
    }

    return new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) {
            if (executionCount >= retryCount) {
                // Do not retry if over max retry count
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                // Retry if the server dropped connection on us
                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;
        }
    };
}
项目:further-open-core    文件:HttpClientTemplate.java   
/**
 * Private {@link HttpClient} initialization.
 */
@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);
}
项目:rome    文件:HttpClientFeedFetcher.java   
public synchronized void setRetryHandler(final HttpMethodRetryHandler handler) {
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, handler);
}