package com.test.util; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.NoHttpResponseException; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.protocol.HttpContext; public class CustomHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler { private static final Log LOG = LogFactory.getLog(CustomHttpRequestRetryHandler.class.getName()); public CustomHttpRequestRetryHandler(int retryCount, boolean sentRequestRetryEnabled) { super(retryCount, sentRequestRetryEnabled); } @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount <= getRetryCount()) { // Retry if the server dropped connection on us if (exception instanceof NoHttpResponseException) { LOG.debug("Caught NoHttpResponseException. Retrying attempt " + executionCount + 1 + " of " + getRetryCount()); return true; } } return super.retryRequest(exception, executionCount, context); } }