You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by kw...@apache.org on 2013/01/10 12:26:13 UTC
svn commit: r1431284 - in /httpcomponents/httpclient/branches/4.2.x: ./
httpclient/src/main/java/org/apache/http/impl/client/
httpclient/src/test/java/org/apache/http/impl/client/
Author: kwright
Date: Thu Jan 10 11:26:12 2013
New Revision: 1431284
URL: http://svn.apache.org/viewvc?rev=1431284&view=rev
Log:
Fix for HTTPCLIENT-1296. Fix NPE when -1 used for port in virtual host and no target is specified.
Modified:
httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1431284&r1=1431283&r2=1431284&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Thu Jan 10 11:26:12 2013
@@ -10,6 +10,10 @@ Users of HttpClient 4.x are advised to u
Changelog
-------------------
+* [HTTPCLIENT-1296] NPE gets thrown if you combine a default host with a virtual host
+ that has a -1 value for the port.
+ Contributed by Karl Wright <daddywri at gmail.com>
+
* [HTTPCLIENT-1290] 304 cached response never reused with If-modified-since conditional
requests.
Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>
Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1431284&r1=1431283&r2=1431284&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java (original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java Thu Jan 10 11:26:12 2013
@@ -417,7 +417,8 @@ public class DefaultRequestDirector impl
// HTTPCLIENT-1092 - add the port if necessary
if (virtualHost != null && virtualHost.getPort() == -1) {
- int port = target.getPort();
+ HttpHost host = (target != null) ? target : origRoute.getTargetHost();
+ int port = host.getPort();
if (port != -1){
virtualHost = new HttpHost(virtualHost.getHostName(), port, virtualHost.getSchemeName());
}
Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=1431284&r1=1431283&r2=1431284&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java (original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java Thu Jan 10 11:26:12 2013
@@ -54,6 +54,8 @@ import org.apache.http.protocol.HttpCont
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.util.EntityUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -362,6 +364,24 @@ public class TestDefaultClientRequestDir
}
@Test
+ public void testDefaultPortVirtualHost() throws Exception {
+ this.localServer.register("*", new SimpleService());
+ this.httpclient = new DefaultHttpClient();
+ HttpHost target = getServerHttp();
+ HttpHost hostHost = new HttpHost(target.getHostName(),-1,target.getSchemeName());
+
+ httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST,target);
+ httpclient.getParams().setParameter(ClientPNames.VIRTUAL_HOST,hostHost);
+
+ HttpGet httpget = new HttpGet("/stuff");
+ HttpContext context = new BasicHttpContext();
+
+ HttpResponse response = this.httpclient.execute(null, httpget, context);
+ Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+ EntityUtils.consume(response.getEntity());
+ }
+
+ @Test
public void testRelativeRequestURIWithFragment() throws Exception {
this.localServer.register("*", new SimpleService());
HttpHost target = getServerHttp();