hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1164052 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/test/java/org/apache/http/impl/client/
Date Thu, 01 Sep 2011 12:45:03 GMT
Author: sebb
Date: Thu Sep  1 12:45:02 2011
New Revision: 1164052

URL: http://svn.apache.org/viewvc?rev=1164052&view=rev
Log:
HTTPCLIENT-1120 - DefaultHttpRequestRetryHandler#retryRequest should not retry aborted requests

Added:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1164052&r1=1164051&r2=1164052&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Sep  1 12:45:02 2011
@@ -1,5 +1,8 @@
 Changes since 4.1.1
 
+* [HTTPCLIENT-1120] DefaultHttpRequestRetryHandler#retryRequest should not retry aborted
requests
+  Contributed by Alin Vasile <alinachegalati at yahoo dot com>
+
 * [HTTPCLIENT-1100] Missing Content-Length header makes cached entry invalid
   Contributed by Bart Robeyns <bart dot robeyns at gmail dot com>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java?rev=1164052&r1=1164051&r2=1164052&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
Thu Sep  1 12:45:02 2011
@@ -41,6 +41,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.client.methods.HttpUriRequest;
 
 /**
  * The default {@link HttpRequestRetryHandler} used by request executors.
@@ -109,6 +110,11 @@ public class DefaultHttpRequestRetryHand
 
         HttpRequest request = (HttpRequest)
             context.getAttribute(ExecutionContext.HTTP_REQUEST);
+        
+        if(requestIsAborted(request)){
+        	return false;
+        }
+        
         if (handleAsIdempotent(request)) {
             // Retry if the request is considered idempotent
             return true;
@@ -148,5 +154,9 @@ public class DefaultHttpRequestRetryHand
     protected boolean handleAsIdempotent(final HttpRequest request) {
         return !(request instanceof HttpEntityEnclosingRequest);
     }
+    
+    protected boolean requestIsAborted(final HttpRequest request) {
+        return (request instanceof HttpUriRequest && ((HttpUriRequest)request).isAborted());
+    }
 
 }

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java?rev=1164052&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
Thu Sep  1 12:45:02 2011
@@ -0,0 +1,103 @@
+/*
+ * ====================================================================
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import java.io.IOException;
+
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class TestDefaultHttpRequestRetryHandler {
+	
+	@Test
+	public void retryOnConnectTimeout() throws Exception {
+        DefaultHttpClient client = new DefaultHttpClient();
+        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
+        
+        client.setHttpRequestRetryHandler(retryHandler);
+
+        HttpRequestBase request = new HttpGet("http://www.example.com/");
+
+        HttpConnectionParams.setConnectionTimeout(request.getParams(), 1);
+        try {
+        	client.execute(request);
+        } catch (ConnectTimeoutException ex) {
+            Assert.assertEquals(3, retryHandler.getRetryCount());            
+        } 
+    }
+	
+	@Test
+	public void noRetryOnAbortedRequests() throws Exception{
+		HttpContext context = mock(HttpContext.class);
+		HttpRequestBase request = mock(HttpRequestBase.class);
+		
+        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
+        
+        when(request.isAborted()).thenReturn(Boolean.TRUE);
+        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
+        
+        Assert.assertFalse(retryHandler.retryRequest(new IOException(),3,context));
+	}
+	
+	@Test
+	public void retryOnNonAbortedRequests() throws Exception{
+		
+		HttpContext context = mock(HttpContext.class);
+		HttpRequestBase request = mock(HttpRequestBase.class);
+		
+        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
+        
+        when(request.isAborted()).thenReturn(Boolean.FALSE);
+        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
+        
+        Assert.assertTrue(retryHandler.retryRequest(new IOException(),3,context));
+	}
+	
+	@Test
+	public void noRetryOnConnectionTimeout() throws Exception{
+		
+		HttpContext context = mock(HttpContext.class);
+		HttpRequestBase request = mock(HttpRequestBase.class);
+		
+        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
+        
+        when(request.isAborted()).thenReturn(false);
+        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
+        
+        Assert.assertFalse(retryHandler.retryRequest(new ConnectTimeoutException(),3,context));
+	}
+	
+}
\ No newline at end of file

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultHttpRequestRetryHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message