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; } }; }
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; } }; }
/** * @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; } }; }
/** * @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; } }; }
/** * 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); }
public synchronized void setRetryHandler(final HttpMethodRetryHandler handler) { httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, handler); }