[
https://issues.apache.org/jira/browse/HTTPCLIENT-911?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oleg Kalnichevski updated HTTPCLIENT-911:
-----------------------------------------
Attachment: HTTPCLIENT-911.patch
The cause of the problem is a very stupid behavior of java.net.URI class.
Apparently the URI constructor quietly ignores the host it considers invalid
and simply uses null instead.
I am attaching a patch that should help handle the situation a bit more
gracefully.
Oleg
---
DefaultHttpClient httpclient = new DefaultHttpClient();
URI uri = new URI("http://0.test_file.com/data");
System.out.println("Target scheme: " + uri.getScheme());
System.out.println("Target host: " + uri.getHost());
System.out.println("Target port: " + uri.getPort());
HttpGet httpget = new HttpGet(uri);
HttpResponse rsp = httpclient.execute(httpget);
HttpEntity entity = rsp.getEntity();
System.out.println("----------------------------------------");
System.out.println(rsp.getStatusLine());
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
---
---
Target scheme: http
Target host: null
Target port: -1
Exception in thread "main" org.apache.http.client.ClientProtocolException: URI
does not specify a valid host name: http://0.test_file.com/data
at
org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:638)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:624)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:602)
at tests.ClientExecuteDirect.main(ClientExecuteDirect.java:58)
---
> Support underscore in domain name, or provide better exception
> --------------------------------------------------------------
>
> Key: HTTPCLIENT-911
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-911
> Project: HttpComponents HttpClient
> Issue Type: Improvement
> Components: HttpClient
> Affects Versions: 4.0.1
> Reporter: Ziv Horesh
> Priority: Minor
> Fix For: 4.1 Alpha2
>
> Attachments: HTTPCLIENT-911.patch
>
>
> When calling on HttpClient.execute with a url that contain underscore ('_'),
> you get NullPointerException.
> Tracing it down show that java.net.Uri complains that it is illegal name.
> Which is true according to the RFC.
> But it seems that most browser allow it, and some companies support it.
> I think HttpClient should either support underscores, or atleast provide a
> better exception.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]