summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-01-06 18:14:25 -0800
committerJesse Wilson <jessewilson@google.com>2011-01-06 18:19:25 -0800
commit2d8fd9bea30efcae4cc418e223f2c61febe0caa0 (patch)
tree0ee4fa60286ff5efd27281649ad6f81a796de593
parent843bcb6f4f65c0cdca327c6467813b88c52042f3 (diff)
downloadexternal_apache-http-2d8fd9bea30efcae4cc418e223f2c61febe0caa0.zip
external_apache-http-2d8fd9bea30efcae4cc418e223f2c61febe0caa0.tar.gz
external_apache-http-2d8fd9bea30efcae4cc418e223f2c61febe0caa0.tar.bz2
Help the caller along if a malformed URI is used to make an HTTP request.
We had problems where we gave a cryptic error when the user's request URL like "www.example.org/api/json/get_stuff" is interpretted as a relative path rather than a fully qualified address: java.lang.IllegalStateException: Target host must not be null, or set in parameters. The new message breaks the address into parts to make this more clear: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=www.example.org/api/json/get_stuff Change-Id: Ie102718dc15b92d68835f1c34b538639f500eeaa http://code.google.com/p/android/issues/detail?id=9929
-rw-r--r--src/org/apache/http/impl/client/DefaultRequestDirector.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/org/apache/http/impl/client/DefaultRequestDirector.java b/src/org/apache/http/impl/client/DefaultRequestDirector.java
index b8f380b..bfdddd6 100644
--- a/src/org/apache/http/impl/client/DefaultRequestDirector.java
+++ b/src/org/apache/http/impl/client/DefaultRequestDirector.java
@@ -67,6 +67,7 @@ import org.apache.http.client.RedirectHandler;
import org.apache.http.client.UserTokenHandler;
import org.apache.http.client.methods.AbortableHttpRequest;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.client.protocol.ClientContext;
@@ -575,8 +576,21 @@ public class DefaultRequestDirector implements RequestDirector {
ClientPNames.DEFAULT_HOST);
}
if (target == null) {
- throw new IllegalStateException
- ("Target host must not be null, or set in parameters.");
+ // BEGIN android-changed
+ // If the URI was malformed, make it obvious where there's no host component
+ String scheme = null;
+ String host = null;
+ String path = null;
+ URI uri;
+ if (request instanceof HttpUriRequest
+ && (uri = ((HttpUriRequest) request).getURI()) != null) {
+ scheme = uri.getScheme();
+ host = uri.getHost();
+ path = uri.getPath();
+ }
+ throw new IllegalStateException( "Target host must not be null, or set in parameters."
+ + " scheme=" + scheme + ", host=" + host + ", path=" + path);
+ // END android-changed
}
return this.routePlanner.determineRoute(target, request, context);