Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9DC1F8136 for ; Thu, 1 Sep 2011 12:45:28 +0000 (UTC) Received: (qmail 58050 invoked by uid 500); 1 Sep 2011 12:45:28 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 58009 invoked by uid 500); 1 Sep 2011 12:45:27 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 57997 invoked by uid 99); 1 Sep 2011 12:45:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2011 12:45:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2011 12:45:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2BD00238897A for ; Thu, 1 Sep 2011 12:45:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hc.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110901124503.2BD00238897A@eris.apache.org> 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 + * [HTTPCLIENT-1100] Missing Content-Length header makes cached entry invalid Contributed by Bart Robeyns 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 + * . + * + */ +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