1 30 31 package org.apache.commons.httpclient; 32 33 import java.io.IOException ; 34 import java.io.InterruptedIOException ; 35 import java.net.NoRouteToHostException ; 36 import java.net.UnknownHostException ; 37 38 44 public class DefaultHttpMethodRetryHandler implements HttpMethodRetryHandler { 45 46 47 private static Class SSL_HANDSHAKE_EXCEPTION = null; 48 49 static { 50 try { 51 SSL_HANDSHAKE_EXCEPTION = Class.forName("javax.net.ssl.SSLHandshakeException"); 52 } catch (ClassNotFoundException ignore) { 53 } 54 } 55 56 private int retryCount; 57 58 59 private boolean requestSentRetryEnabled; 60 61 66 public DefaultHttpMethodRetryHandler(int retryCount, boolean requestSentRetryEnabled) { 67 super(); 68 this.retryCount = retryCount; 69 this.requestSentRetryEnabled = requestSentRetryEnabled; 70 } 71 72 76 public DefaultHttpMethodRetryHandler() { 77 this(3, false); 78 } 79 85 public boolean retryMethod( 86 final HttpMethod method, 87 final IOException exception, 88 int executionCount) { 89 if (method == null) { 90 throw new IllegalArgumentException ("HTTP method may not be null"); 91 } 92 if (exception == null) { 93 throw new IllegalArgumentException ("Exception parameter may not be null"); 94 } 95 if (method instanceof HttpMethodBase) { 97 if (((HttpMethodBase)method).isAborted()) { 98 return false; 99 } 100 } 101 if (executionCount > this.retryCount) { 102 return false; 104 } 105 if (exception instanceof NoHttpResponseException) { 106 return true; 108 } 109 if (exception instanceof InterruptedIOException ) { 110 return false; 112 } 113 if (exception instanceof UnknownHostException ) { 114 return false; 116 } 117 if (exception instanceof NoRouteToHostException ) { 118 return false; 120 } 121 if (SSL_HANDSHAKE_EXCEPTION != null && SSL_HANDSHAKE_EXCEPTION.isInstance(exception)) { 122 return false; 124 } 125 if (!method.isRequestSent() || this.requestSentRetryEnabled) { 126 return true; 129 } 130 return false; 132 } 133 134 138 public boolean isRequestSentRetryEnabled() { 139 return requestSentRetryEnabled; 140 } 141 142 145 public int getRetryCount() { 146 return retryCount; 147 } 148 } 149 | Popular Tags |