hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sber...@apache.org
Subject svn commit: r664505 - in /httpcomponents/httpclient/trunk/module-client/src: main/java/org/apache/http/client/ main/java/org/apache/http/client/methods/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/client/protocol/ test/java/org/apa...
Date Sun, 08 Jun 2008 13:21:20 GMT
Author: sberlin
Date: Sun Jun  8 06:21:20 2008
New Revision: 664505

URL: http://svn.apache.org/viewvc?rev=664505&view=rev
Log:
HTTPCLIENT-779: toplevel exception cleanup.  HttpClient.execute now only throws an IOException
(and specific subtypes of that), and HttpGet/HttpPut and associated classes' String constructor
now throw IllegalArgumentException instead of URISyntaxException.

Added:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientProtocolException.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java

Added: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientProtocolException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientProtocolException.java?rev=664505&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientProtocolException.java
(added)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientProtocolException.java
Sun Jun  8 06:21:20 2008
@@ -0,0 +1,30 @@
+package org.apache.http.client;
+
+import java.io.IOException;
+
+/**
+ * Signals an error in the HTTP protocol.
+ */
+public class ClientProtocolException extends IOException {
+    
+    private static final long serialVersionUID = -5596590843227115865L;
+
+    public ClientProtocolException() {
+        super();
+    }
+
+    public ClientProtocolException(String s) {
+        super(s);
+    }
+    
+    public ClientProtocolException(Throwable cause) {
+        initCause(cause);
+    }
+    
+    public ClientProtocolException(String message, Throwable cause) {
+        super(message);
+        initCause(cause);
+    }
+    
+
+}

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

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java
Sun Jun  8 06:21:20 2008
@@ -36,7 +36,6 @@
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
-import org.apache.http.HttpException;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.client.methods.HttpUriRequest;
@@ -87,13 +86,11 @@
      * @param request   the request to execute
      *
      * @return  the response to the request
-     *
-     * @throws HttpException            in case of a problem
-     * @throws IOException              in case of an IO problem
-     *                                     or the connection was aborted
+     * @throws IOException in case of a problem or the connection was aborted
+     * @throws ClientProtocolException in case of an http protocol error
      */
     HttpResponse execute(HttpUriRequest request)
-        throws HttpException, IOException
+        throws IOException, ClientProtocolException
         ;
 
 
@@ -110,13 +107,11 @@
      *          Whether redirects or authentication challenges will be returned
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
-     *
-     * @throws HttpException    in case of a problem
-     * @throws IOException      in case of an IO problem
-     *                             or the connection was aborted
+     * @throws IOException in case of a problem or the connection was aborted
+     * @throws ClientProtocolException in case of an http protocol error
      */
     HttpResponse execute(HttpUriRequest request, HttpContext context)
-        throws HttpException, IOException
+        throws IOException, ClientProtocolException
         ;
 
 
@@ -135,13 +130,11 @@
      *          Whether redirects or authentication challenges will be returned
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
-     *
-     * @throws HttpException    in case of a problem
-     * @throws IOException      in case of an IO problem
-     *                             or the connection was aborted
+     * @throws IOException in case of a problem or the connection was aborted
+     * @throws ClientProtocolException in case of an http protocol error
      */
     HttpResponse execute(HttpHost target, HttpRequest request)
-        throws HttpException, IOException
+        throws IOException, ClientProtocolException
         ;
 
 
@@ -161,14 +154,12 @@
      *          Whether redirects or authentication challenges will be returned
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
-     *
-     * @throws HttpException    in case of a problem
-     * @throws IOException      in case of an IO problem
-     *                             or the connection was aborted
+     * @throws IOException in case of a problem or the connection was aborted
+     * @throws ClientProtocolException in case of an http protocol error
      */
     HttpResponse execute(HttpHost target, HttpRequest request,
                          HttpContext context)
-        throws HttpException, IOException
+        throws IOException, ClientProtocolException
         ;
 
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP DELETE method
@@ -61,9 +60,12 @@
         setURI(uri);
     }
 
-    public HttpDelete(final String uri) throws URISyntaxException {
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpDelete(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP GET method.
@@ -68,9 +67,12 @@
         setURI(uri);
     }
 
-    public HttpGet(final String uri) throws URISyntaxException {
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpGet(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP HEAD method.
@@ -68,9 +67,12 @@
         setURI(uri);
     }
 
-    public HttpHead(final String uri) throws URISyntaxException {
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpHead(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -73,9 +72,12 @@
         setURI(uri);
     }
 
-    public HttpOptions(final String uri) throws URISyntaxException {
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpOptions(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP POST method.
@@ -71,10 +70,13 @@
         super();
         setURI(uri);
     }
-
-    public HttpPost(final String uri) throws URISyntaxException {
+    
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpPost(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP PUT method.
@@ -64,9 +63,12 @@
         setURI(uri);
     }
 
-    public HttpPut(final String uri) throws URISyntaxException {
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpPut(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java
Sun Jun  8 06:21:20 2008
@@ -32,7 +32,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 /**
  * HTTP TRACE method.
@@ -66,10 +65,13 @@
         super();
         setURI(uri);
     }
-
-    public HttpTrace(final String uri) throws URISyntaxException {
+    
+    /**
+     * @throws IllegalArgumentException if the uri is invalid. 
+     */
+    public HttpTrace(final String uri) {
         super();
-        setURI(new URI(uri));
+        setURI(URI.create(uri));
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
Sun Jun  8 06:21:20 2008
@@ -43,6 +43,7 @@
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.client.AuthenticationHandler;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.ClientRequestDirector;
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.CredentialsProvider;
@@ -434,7 +435,7 @@
 
     // non-javadoc, see interface HttpClient
     public final HttpResponse execute(HttpUriRequest request)
-        throws HttpException, IOException {
+        throws IOException, ClientProtocolException {
 
         return execute(request, null);
     }
@@ -451,7 +452,7 @@
      */
     public final HttpResponse execute(HttpUriRequest request,
                                       HttpContext context)
-        throws HttpException, IOException {
+        throws IOException, ClientProtocolException {
 
         if (request == null) {
             throw new IllegalArgumentException
@@ -476,7 +477,7 @@
 
     // non-javadoc, see interface HttpClient
     public final HttpResponse execute(HttpHost target, HttpRequest request)
-        throws HttpException, IOException {
+        throws IOException, ClientProtocolException {
 
         return execute(target, request, null);
     }
@@ -485,7 +486,7 @@
     // non-javadoc, see interface HttpClient
     public final HttpResponse execute(HttpHost target, HttpRequest request,
                                       HttpContext context)
-        throws HttpException, IOException {
+        throws IOException, ClientProtocolException {
 
         if (request == null) {
             throw new IllegalArgumentException
@@ -535,7 +536,11 @@
                     determineParams(request));
         }
 
-        return director.execute(target, request, execContext);
+        try {
+            return director.execute(target, request, execContext);
+        } catch(HttpException httpException) {
+            throw new ClientProtocolException(httpException);
+        }
     } // execute
 
     

Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java?rev=664505&r1=664504&r2=664505&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java
Sun Jun  8 06:21:20 2008
@@ -43,6 +43,7 @@
 import org.apache.http.ProtocolException;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.CircularRedirectException;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.RedirectException;
 import org.apache.http.client.methods.HttpGet;
@@ -426,9 +427,9 @@
 
         try {
             client.execute(getServerHttp(), httpget);
-            fail("RedirectException exception should have been thrown");
-        } catch (RedirectException e) {
-            // expected
+            fail("ClientProtocolException exception should have been thrown");
+        } catch (ClientProtocolException e) {
+            assertTrue(e.getCause() instanceof RedirectException);
         }
     }
 
@@ -442,9 +443,9 @@
 
         try {
             client.execute(getServerHttp(), httpget);
-            fail("CircularRedirectException exception should have been thrown");
-        } catch (CircularRedirectException e) {
-            // expected
+            fail("ClientProtocolException exception should have been thrown");
+        } catch (ClientProtocolException e) {
+            assertTrue(e.getCause() instanceof CircularRedirectException);
         }
     }
 
@@ -542,8 +543,9 @@
 
         try {
             client.execute(getServerHttp(), httpget);
-            fail("ProtocolException exception should have been thrown");
-        } catch (ProtocolException e) {
+            fail("ClientProtocolException exception should have been thrown");
+        } catch (ClientProtocolException e) {
+            assertTrue(e.getCause() instanceof ProtocolException);
             // expected
         }
     }
@@ -575,8 +577,9 @@
 
         try {
             client.execute(getServerHttp(), httpget);
-            fail("ProtocolException should have been thrown");
-        } catch (ProtocolException e) {
+            fail("ClientProtocolException should have been thrown");
+        } catch (ClientProtocolException e) {
+            assertTrue(e.getCause() instanceof ProtocolException);
             // expected
         }
     }

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=664505&r1=664504&r2=664505&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
Sun Jun  8 06:21:20 2008
@@ -31,7 +31,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.ConnectException;
-import java.net.URISyntaxException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
@@ -49,6 +48,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.methods.AbortableHttpRequest;
@@ -554,7 +554,7 @@
     private static class CustomGet extends HttpGet {
         private final CountDownLatch releaseTriggerLatch;
 
-        public CustomGet(String uri, CountDownLatch releaseTriggerLatch) throws URISyntaxException
{
+        public CustomGet(String uri, CountDownLatch releaseTriggerLatch) {
             super(uri);
             this.releaseTriggerLatch = releaseTriggerLatch;
         }
@@ -726,8 +726,9 @@
 
         try {
             client.execute(getServerHttp(), httppost, context);
-            fail("NonRepeatableEntityException should have been thrown");
-        } catch (NonRepeatableRequestException ex) {
+            fail("ClientProtocolException should have been thrown");
+        } catch (ClientProtocolException ex) {
+            assertTrue(ex.getCause() instanceof NonRepeatableRequestException);
            // expected
         }
     }



Mime
View raw message