hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r759942 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/client/DefaultRequestDirector.java test/java/org/apache/http/impl/client/TestClientAuthentication.java
Date Mon, 30 Mar 2009 12:33:26 GMT
Author: olegk
Date: Mon Mar 30 12:33:25 2009
New Revision: 759942

URL: http://svn.apache.org/viewvc?rev=759942&view=rev
Log:
Added a test case for handling of authentication failures with non-repeatable requests

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=759942&r1=759941&r2=759942&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Mon Mar 30 12:33:25 2009
@@ -399,7 +399,8 @@
                     // Increment exec count for this particular request
                     wrapper.incrementExecCount();
                     if (wrapper.getExecCount() > 1 && !wrapper.isRepeatable())
{
-                        if(retryReason != null) {
+                        this.log.debug("Cannot retry non-repeatable request");
+                        if (retryReason != null) {
                             throw new NonRepeatableRequestException("Cannot retry request
" +
                                 "with a non-repeatable request entity.  The cause lists the
" +
                                 "reason the original request failed.", retryReason);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java?rev=759942&r1=759941&r2=759942&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
Mon Mar 30 12:33:25 2009
@@ -28,6 +28,7 @@
 
 package org.apache.http.impl.client;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 
 import junit.framework.Test;
@@ -41,8 +42,12 @@
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.localserver.BasicServerTestBase;
 import org.apache.http.localserver.LocalTestServer;
@@ -198,4 +203,52 @@
         assertEquals("test realm", authscope.getRealm());
     }
 
+    public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
+        localServer.register("*", new AuthHandler());
+        localServer.start();
+        
+        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        
+        DefaultHttpClient httpclient = new DefaultHttpClient();
+        httpclient.setCredentialsProvider(credsProvider);
+        
+        HttpPost httppost = new HttpPost("/");
+        httppost.setEntity(new StringEntity("some important stuff", HTTP.ISO_8859_1));
+        
+        HttpResponse response = httpclient.execute(getServerHttp(), httppost);
+        HttpEntity entity = response.getEntity();
+        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+        assertNotNull(entity);
+        entity.consumeContent();
+        AuthScope authscope = credsProvider.getAuthScope();
+        assertNotNull(authscope);
+        assertEquals("test realm", authscope.getRealm());
+    }
+
+    public void testBasicAuthenticationFailureOnNonRepeatablePost() throws Exception {
+        localServer.register("*", new AuthHandler());
+        localServer.start();
+        
+        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        
+        DefaultHttpClient httpclient = new DefaultHttpClient();
+        httpclient.setCredentialsProvider(credsProvider);
+        
+        HttpPost httppost = new HttpPost("/");
+        httppost.setEntity(new InputStreamEntity(
+                new ByteArrayInputStream(
+                        new byte[] { 0,1,2,3,4,5,6,7,8,9 }), -1));
+        
+        try {
+            httpclient.execute(getServerHttp(), httppost);
+            fail("ClientProtocolException should have been thrown");
+        } catch (ClientProtocolException ex) {
+            Throwable cause = ex.getCause();
+            assertNotNull(cause);
+            assertTrue(cause instanceof NonRepeatableRequestException);
+        }
+    }
+
 }



Mime
View raw message