hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r189802 - in /jakarta/httpclient/trunk/http-common/src: contrib/org/apache/http/contrib/spring/http-beans.xml java/org/apache/http/executor/HttpExecutionContext.java java/org/apache/http/executor/HttpRequestExecutor.java java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java
Date Thu, 09 Jun 2005 19:45:24 GMT
Author: olegk
Date: Thu Jun  9 12:45:22 2005
New Revision: 189802

URL: http://svn.apache.org/viewcvs?rev=189802&view=rev
Log:
Added default request retry handler

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java
      - copied, changed from r189566, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java
Modified:
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java

Modified: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml?rev=189802&r1=189801&r2=189802&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
(original)
+++ jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
Thu Jun  9 12:45:22 2005
@@ -24,6 +24,12 @@
     <constructor-arg index="2"><value>80</value></constructor-arg>
   </bean>
   
+  <bean id="request-retry-handler" 
+    class="org.apache.http.impl.DefaultHttpRequestRetryHandler">
+    <constructor-arg index="0"><value>3</value></constructor-arg>
+    <constructor-arg index="1"><value>false</value></constructor-arg>
+  </bean>
+  
   <bean id="http-executor" 
     class="org.apache.http.executor.HttpRequestExecutor" 
     singleton="true" >
@@ -38,6 +44,7 @@
         <bean class="org.apache.http.interceptor.RequestExpectContinue" />
       </set>
     </property>
+    <property name="retryHandler"><ref bean="request-retry-handler"/></property>
   </bean>
   
   <bean id="http-data-trx-factory" 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java?rev=189802&r1=189801&r2=189802&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
Thu Jun  9 12:45:22 2005
@@ -49,6 +49,7 @@
     public static final String HTTP_CONNECTION  = "http.connection"; 
     public static final String HTTP_TARGET_HOST = "http.target_host"; 
     public static final String HTTP_PROXY_HOST  = "http.proxy_host"; 
+    public static final String HTTP_REQ_SENT    = "http.request_sent"; 
     
     private final HttpContext parentContext;
     private Map map = null;

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java?rev=189802&r1=189801&r2=189802&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
Thu Jun  9 12:45:22 2005
@@ -219,7 +219,11 @@
                     conn.open(this.params);
                     // TODO: Implement secure tunnelling
                 }
+                this.localContext.setAttribute(HttpExecutionContext.HTTP_REQ_SENT, 
+                        new Boolean(false)); 
                 response = conn.sendRequest(request);
+                this.localContext.setAttribute(HttpExecutionContext.HTTP_REQ_SENT, 
+                        new Boolean(true)); 
                 // Request may be terminated prematurely, if the expect-continue 
                 // protocol is used
                 if (response == null) {

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java
(from r189566, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java&p1=jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java&r1=189566&r2=189802&rev=189802&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestRetryHandler.java
Thu Jun  9 12:45:22 2005
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java,v
1.3 2004/12/20 11:47:46 olegk Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  *
@@ -27,29 +27,27 @@
  *
  */
 
-package org.apache.commons.httpclient;
+package org.apache.http.impl;
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.net.UnknownHostException;
 
+import javax.net.ssl.SSLHandshakeException;
+
+import org.apache.http.HttpContext;
+import org.apache.http.NoHttpResponseException;
+import org.apache.http.executor.HttpExecutionContext;
+import org.apache.http.executor.HttpRequestRetryHandler;
+
 /**
- * The default {@link HttpMethodRetryHandler} used by {@link HttpMethod}s.
+ * The default {@link HttpRequestRetryHandler} used by {@link HttpRequestExecutor}s.
  * 
  * @author Michael Becke
- * @author <a href="mailto:oleg -at- ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  */
-public class DefaultHttpMethodRetryHandler implements HttpMethodRetryHandler {
-
+public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
 
-	private static Class SSL_HANDSHAKE_EXCEPTION = null;
-	
-	static {
-		try {
-			SSL_HANDSHAKE_EXCEPTION = Class.forName("javax.net.ssl.SSLHandshakeException");
-		} catch (ClassNotFoundException ignore) {			
-		}
-	}
 	/** the number of times a method will be retried */
     private int retryCount;
     
@@ -59,7 +57,7 @@
     /**
      * Default constructor
      */
-    public DefaultHttpMethodRetryHandler(int retryCount, boolean requestSentRetryEnabled)
{
+    public DefaultHttpRequestRetryHandler(int retryCount, boolean requestSentRetryEnabled)
{
         super();
         this.retryCount = retryCount;
         this.requestSentRetryEnabled = requestSentRetryEnabled;
@@ -68,7 +66,7 @@
     /**
      * Default constructor
      */
-    public DefaultHttpMethodRetryHandler() {
+    public DefaultHttpRequestRetryHandler() {
         this(3, false);
     }
     /** 
@@ -77,16 +75,16 @@
      * 
      * @see HttpMethodRetryHandler#retryMethod(HttpMethod, IOException, int)
      */
-    public boolean retryMethod(
-        final HttpMethod method, 
-        final IOException exception, 
-        int executionCount) {
-        if (method == null) {
-            throw new IllegalArgumentException("HTTP method may not be null");
-        }
+    public boolean retryRequest(
+            final IOException exception, 
+            int executionCount,
+            final HttpContext context) {
         if (exception == null) {
             throw new IllegalArgumentException("Exception parameter may not be null");
         }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
         if (executionCount > this.retryCount) {
             // Do not retry if over max retry count
             return false;
@@ -103,11 +101,13 @@
             // Unknown host
             return false;
         }
-        if (SSL_HANDSHAKE_EXCEPTION != null && SSL_HANDSHAKE_EXCEPTION.isInstance(exception))
{
+        if (exception instanceof SSLHandshakeException) {
             // SSL handshake exception
             return false;
         }
-        if (!method.isRequestSent() || this.requestSentRetryEnabled) {
+        Boolean b = (Boolean) context.getAttribute(HttpExecutionContext.HTTP_REQ_SENT);
+        boolean sent = (b != null && b.booleanValue());
+        if (!sent || this.requestSentRetryEnabled) {
             // Retry if the request has not been sent fully or
             // if it's OK to retry methods that have been sent
             return true;



Mime
View raw message