Don't retry a request for NoRouteToHostException
This commit is contained in:
parent
56d7863651
commit
f0618b0484
|
@ -30,6 +30,7 @@ package org.apache.http.impl.client;
|
|||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -103,6 +104,7 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
|
|||
InterruptedIOException.class,
|
||||
UnknownHostException.class,
|
||||
ConnectException.class,
|
||||
NoRouteToHostException.class,
|
||||
SSLException.class));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
@ -111,4 +112,21 @@ public class TestDefaultHttpRequestRetryHandler {
|
|||
Assert.assertFalse(retryHandler.retryRequest(new ConnectTimeoutException(),3,context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that {@link DefaultHttpRequestRetryHandler} doesn't retry a request
|
||||
* when {@link java.net.NoRouteToHostException} is thrown when establishing
|
||||
* a connection
|
||||
*/
|
||||
@Test
|
||||
public void noRetryForNoRouteToHostException() {
|
||||
final HttpContext context = mock(HttpContext.class);
|
||||
final HttpUriRequest request = mock(HttpUriRequest.class);
|
||||
when(request.isAborted()).thenReturn(false);
|
||||
when(context.getAttribute(HttpCoreContext.HTTP_REQUEST)).thenReturn(request);
|
||||
|
||||
final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
|
||||
Assert.assertFalse("Request was unexpectedly retried for "
|
||||
+ NoRouteToHostException.class.getName() + " exception",
|
||||
retryHandler.retryRequest(new NoRouteToHostException(), 1, context));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue