### Eclipse Workspace Patch 1.0 #P httpcomponents-client Index: module-client/src/main/java/org/apache/http/client/ClientProtocolException.java =================================================================== --- module-client/src/main/java/org/apache/http/client/ClientProtocolException.java (revision 0) +++ module-client/src/main/java/org/apache/http/client/ClientProtocolException.java (revision 0) @@ -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); + } + + +} Index: module-client/src/main/java/org/apache/http/client/HttpClient.java =================================================================== --- module-client/src/main/java/org/apache/http/client/HttpClient.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/HttpClient.java (working copy) @@ -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 ; Index: module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpGet.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpGet.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpGet.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpHead.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpHead.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpHead.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpPost.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpPost.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpPost.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpPut.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpPut.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpPut.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java =================================================================== --- module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java (revision 661455) +++ module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java (working copy) @@ -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 Index: module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java =================================================================== --- module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java (revision 661455) +++ module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java (working copy) @@ -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 { return execute(request, null); } @@ -451,7 +452,7 @@ */ public final HttpResponse execute(HttpUriRequest request, HttpContext context) - throws HttpException, IOException { + throws IOException { 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 { 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 Index: module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java =================================================================== --- module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java (revision 661455) +++ module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java (working copy) @@ -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 } } Index: module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java =================================================================== --- module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java (revision 661455) +++ module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java (working copy) @@ -30,7 +30,6 @@ 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; @@ -550,7 +549,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; }