hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r664066 - in /httpcomponents/httpclient/trunk: ./ module-client/src/main/java/org/apache/http/client/ module-client/src/main/java/org/apache/http/impl/client/ module-client/src/test/java/org/apache/http/impl/client/
Date Fri, 06 Jun 2008 18:13:19 GMT
Author: olegk
Date: Fri Jun  6 11:13:18 2008
New Revision: 664066

URL: http://svn.apache.org/viewvc?rev=664066&view=rev
Log:
HttpClient will throw an exception if an attempt is made to retry a request with a non-repeatable
request entity.

Added:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=664066&r1=664065&r2=664066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Jun  6 11:13:18 2008
@@ -1,6 +1,10 @@
 Changes since 4.0 Alpha 4
 -------------------
 
+* HttpClient will throw an exception if an attempt is made to retry
+  a request with a non-repeatable request entity.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * Fixed request re-generation logic when retrying a failed request.
   Auto-generated headers will no accumulate.
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Added: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java?rev=664066&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
(added)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
Fri Jun  6 11:13:18 2008
@@ -0,0 +1,63 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ *
+ *  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.client;
+
+import org.apache.http.ProtocolException;
+
+/**
+ * Signals failure to retry the request due to non-repeatable request 
+ * entity.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * 
+ * @since 4.0
+ */
+public class NonRepeatableEntityException extends ProtocolException {
+
+    private static final long serialVersionUID = 82685265288806048L;
+
+    /**
+     * Creates a new NonRepeatableEntityException with a <tt>null</tt> detail
message. 
+     */
+    public NonRepeatableEntityException() {
+        super();
+    }
+
+    /**
+     * Creates a new NonRepeatableEntityException with the specified detail message.
+     * 
+     * @param message The exception detail message
+     */
+    public NonRepeatableEntityException(String message) {
+        super(message);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java?rev=664066&r1=664065&r2=664066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java
Fri Jun  6 11:13:18 2008
@@ -35,7 +35,7 @@
 /**
  * Signals violation of HTTP specification caused by an invalid redirect
  * 
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * 
  * @since 4.0
  */

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?rev=664066&r1=664065&r2=664066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
Fri Jun  6 11:13:18 2008
@@ -61,6 +61,7 @@
 import org.apache.http.client.ClientRequestDirector;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.NonRepeatableEntityException;
 import org.apache.http.client.RedirectException;
 import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.UserTokenHandler;
@@ -384,6 +385,18 @@
                 boolean retrying = true;
                 while (retrying) {
                     execCount++;
+                    
+                    if (execCount > 1) {
+                        if (request instanceof HttpEntityEnclosingRequest) {
+                            HttpEntity entity = 
+                                ((HttpEntityEnclosingRequest) request).getEntity();
+                            if (entity != null && !entity.isRepeatable()) {
+                                throw new NonRepeatableEntityException(
+                                        "Cannot retry the request");
+                            }
+                        }
+                    }
+                    
                     try {
                         if (LOG.isDebugEnabled()) {
                             LOG.debug("Attempt " + execCount + " to execute request");

Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=664066&r1=664065&r2=664066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Fri Jun  6 11:13:18 2008
@@ -28,6 +28,7 @@
 
 package org.apache.http.impl.client;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.ConnectException;
 import java.net.URISyntaxException;
@@ -49,8 +50,10 @@
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.NonRepeatableEntityException;
 import org.apache.http.client.methods.AbortableHttpRequest;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ClientConnectionRequest;
@@ -61,6 +64,7 @@
 import org.apache.http.conn.scheme.PlainSocketFactory;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.conn.ClientConnAdapterMockup;
 import org.apache.http.impl.conn.SingleClientConnManager;
@@ -706,4 +710,26 @@
         assertEquals(1, myheaders.length);
     }
     
+    public void testNonRepatableEntity() throws Exception {
+        int port = this.localServer.getServicePort();
+        this.localServer.register("*", new SimpleService());
+        
+        FaultyHttpClient client = new FaultyHttpClient(); 
+        HttpContext context = new BasicHttpContext();
+
+        String s = "http://localhost:" + port;
+        HttpPost httppost = new HttpPost(s);
+        httppost.setEntity(new InputStreamEntity(
+                new ByteArrayInputStream(
+                        new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
+                        -1));
+
+        try {
+            client.execute(getServerHttp(), httppost, context);
+            fail("NonRepeatableEntityException should have been thrown");
+        } catch (NonRepeatableEntityException ex) {
+           // expected
+        }
+    }
+    
 }



Mime
View raw message