hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1615914 - in /httpcomponents/httpclient/branches/4.3.x/httpclient/src: main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
Date Tue, 05 Aug 2014 11:50:51 GMT
Author: olegk
Date: Tue Aug  5 11:50:51 2014
New Revision: 1615914

URL: http://svn.apache.org/r1615914
Log:
HTTPCLIENT-1536: default connection operator to use HttpHost#getAddress if available

Modified:
    httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
    httpcomponents/httpclient/branches/4.3.x/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java

Modified: httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java?rev=1615914&r1=1615913&r2=1615914&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
Tue Aug  5 11:50:51 2014
@@ -98,7 +98,8 @@ class HttpClientConnectionOperator {
             throw new UnsupportedSchemeException(host.getSchemeName() +
                     " protocol is not supported");
         }
-        final InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
+        final InetAddress[] addresses = host.getAddress() != null ?
+                new InetAddress[] { host.getAddress() } : this.dnsResolver.resolve(host.getHostName());
         final int port = this.schemePortResolver.resolve(host);
         for (int i = 0; i < addresses.length; i++) {
             final InetAddress address = addresses[i];

Modified: httpcomponents/httpclient/branches/4.3.x/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java?rev=1615914&r1=1615913&r2=1615914&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/branches/4.3.x/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
Tue Aug  5 11:50:51 2014
@@ -207,6 +207,38 @@ public class TestHttpClientConnectionOpe
     }
 
     @Test
+    public void testConnectExplicitAddress() throws Exception {
+        final HttpContext context = new BasicHttpContext();
+        final InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
+        final InetAddress ip = InetAddress.getByAddress(new byte[] {127, 0, 0, 23});
+        final HttpHost host = new HttpHost(ip);
+
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+        Mockito.when(schemePortResolver.resolve(host)).thenReturn(80);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
+        Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.anyInt(),
+                Mockito.<Socket>any(),
+                Mockito.<HttpHost>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<InetSocketAddress>any(),
+                Mockito.<HttpContext>any())).thenReturn(socket);
+
+        final InetSocketAddress localAddress = new InetSocketAddress(local, 0);
+        connectionOperator.connect(conn, host, localAddress, 1000, SocketConfig.DEFAULT,
context);
+
+        Mockito.verify(plainSocketFactory).connectSocket(
+                1000,
+                socket,
+                host,
+                new InetSocketAddress(ip, 80),
+                localAddress,
+                context);
+        Mockito.verify(dnsResolver, Mockito.never()).resolve(Mockito.anyString());
+        Mockito.verify(conn, Mockito.times(2)).bind(socket);
+    }
+
+    @Test
     public void testUpgrade() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("somehost", -1, "https");



Mime
View raw message