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.
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@664505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
13ba9862e0
commit
284556d9be
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -36,7 +36,6 @@ import java.io.IOException;
|
|||
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 @@ public interface HttpClient {
|
|||
* @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 @@ public interface HttpClient {
|
|||
* 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 @@ public interface HttpClient {
|
|||
* 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 @@ public interface HttpClient {
|
|||
* 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
|
||||
;
|
||||
|
||||
|
||||
|
|
|
@ -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 @@ public class HttpDelete extends HttpRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpGet extends HttpRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpHead extends HttpRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpOptions extends HttpRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpPost extends HttpEntityEnclosingRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpPut extends HttpEntityEnclosingRequestBase {
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HttpTrace extends HttpRequestBase {
|
|||
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
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.http.HttpResponse;
|
|||
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 @@ public abstract class AbstractHttpClient implements HttpClient {
|
|||
|
||||
// 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 abstract class AbstractHttpClient implements HttpClient {
|
|||
*/
|
||||
public final HttpResponse execute(HttpUriRequest request,
|
||||
HttpContext context)
|
||||
throws HttpException, IOException {
|
||||
throws IOException, ClientProtocolException {
|
||||
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException
|
||||
|
@ -476,7 +477,7 @@ public abstract class AbstractHttpClient implements HttpClient {
|
|||
|
||||
// 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 @@ public abstract class AbstractHttpClient implements HttpClient {
|
|||
// 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 @@ public abstract class AbstractHttpClient implements HttpClient {
|
|||
determineParams(request));
|
||||
}
|
||||
|
||||
return director.execute(target, request, execContext);
|
||||
try {
|
||||
return director.execute(target, request, execContext);
|
||||
} catch(HttpException httpException) {
|
||||
throw new ClientProtocolException(httpException);
|
||||
}
|
||||
} // execute
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.http.HttpStatus;
|
|||
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 @@ public class TestRedirects extends ServerTestBase {
|
|||
|
||||
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 @@ public class TestRedirects extends ServerTestBase {
|
|||
|
||||
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 @@ public class TestRedirects extends ServerTestBase {
|
|||
|
||||
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 @@ public class TestRedirects extends ServerTestBase {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ package org.apache.http.impl.client;
|
|||
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.HttpRequestInterceptor;
|
|||
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 @@ public class TestDefaultClientRequestDirector extends ServerTestBase {
|
|||
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 @@ public class TestDefaultClientRequestDirector extends ServerTestBase {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue