Use InetSocketAddress instead of InetAddress in the HttpClientConnectionManager#connect method

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1440519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-01-30 16:59:07 +00:00
parent b1e5098828
commit 90fc40bbf2
8 changed files with 27 additions and 26 deletions

View File

@ -27,7 +27,7 @@
package org.apache.http.conn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpClientConnection;
@ -80,7 +80,7 @@ public interface HttpClientConnectionManager {
void connect(
HttpClientConnection conn,
HttpHost host, InetAddress localAddress,
HttpHost host, InetSocketAddress localAddress,
int connectTimeout,
HttpContext context) throws IOException;

View File

@ -28,6 +28,7 @@
package org.apache.http.conn.routing;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
@ -255,6 +256,10 @@ public final class HttpRoute implements RouteInfo, Cloneable {
}
public final InetSocketAddress getLocalSocketAddress() {
return this.localAddress != null ? new InetSocketAddress(this.localAddress, 0) : null;
}
public final int getHopCount() {
return proxyChain.length+1;
}

View File

@ -29,7 +29,6 @@ package org.apache.http.impl.conn;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@ -304,13 +303,12 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
public void connect(
final HttpClientConnection conn,
final HttpHost host,
final InetAddress local,
final InetSocketAddress localAddress,
final int connectTimeout,
final HttpContext context) throws IOException {
Args.notNull(conn, "Connection");
Args.notNull(host, "HTTP host");
Asserts.check(conn == this.conn, "Connection not obtained from this manager");
final InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
this.connectionOperator.connect(this.conn, host, localAddress,
connectTimeout, this.socketConfig, context);
}

View File

@ -28,7 +28,6 @@ package org.apache.http.impl.conn;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -297,7 +296,7 @@ public class PoolingHttpClientConnectionManager
public void connect(
final HttpClientConnection managedConn,
final HttpHost host,
final InetAddress local,
final InetSocketAddress localAddress,
final int connectTimeout,
final HttpContext context) throws IOException {
Args.notNull(managedConn, "Connection");
@ -313,7 +312,6 @@ public class PoolingHttpClientConnectionManager
if (socketConfig == null) {
socketConfig = SocketConfig.DEFAULT;
}
final InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
this.connectionOperator.connect(
conn, host, localAddress, connectTimeout, socketConfig, context);
}

View File

@ -353,7 +353,7 @@ public class MainClientExec implements ClientExecChain {
case HttpRouteDirector.CONNECT_TARGET:
this.connManager.connect(
managedConn,
route.getTargetHost(), route.getLocalAddress(),
route.getTargetHost(), route.getLocalSocketAddress(),
timeout > 0 ? timeout : 0,
context);
tracker.connectTarget(route.isSecure());
@ -361,7 +361,7 @@ public class MainClientExec implements ClientExecChain {
case HttpRouteDirector.CONNECT_PROXY:
this.connManager.connect(
managedConn,
route.getProxyHost(), route.getLocalAddress(),
route.getProxyHost(), route.getLocalSocketAddress(),
timeout > 0 ? timeout : 0,
context);
final HttpHost proxy = route.getProxyHost();
@ -434,7 +434,7 @@ public class MainClientExec implements ClientExecChain {
if (!managedConn.isOpen()) {
this.connManager.connect(
managedConn,
route.getProxyHost(), route.getLocalAddress(),
route.getProxyHost(), route.getLocalSocketAddress(),
timeout > 0 ? timeout : 0,
context);
}

View File

@ -146,7 +146,7 @@ public class MinimalClientExec implements ClientExecChain {
final int timeout = config.getConnectTimeout();
this.connManager.connect(
managedConn,
route.getTargetHost(), route.getLocalAddress(),
route.getTargetHost(), route.getLocalSocketAddress(),
timeout > 0 ? timeout : 0,
context);
} else {

View File

@ -28,7 +28,7 @@ package org.apache.http.impl.client.integration;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@ -297,7 +297,7 @@ public class TestAbortHandling extends IntegrationTestBase {
Mockito.doThrow(new ConnectException()).when(connmgr).connect(
Mockito.any(HttpClientConnection.class),
Mockito.any(HttpHost.class),
Mockito.any(InetAddress.class),
Mockito.any(InetSocketAddress.class),
Mockito.anyInt(),
Mockito.any(HttpContext.class));
@ -465,7 +465,7 @@ public class TestAbortHandling extends IntegrationTestBase {
public void connect(
final HttpClientConnection conn,
final HttpHost host,
final InetAddress localAddress,
final InetSocketAddress localAddress,
final int connectTimeout,
final HttpContext context) throws IOException {
throw new UnsupportedOperationException("just a mockup");

View File

@ -112,7 +112,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
final HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@ -146,7 +146,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
conn = getConnection(mgr, route);
Assert.assertFalse("connection should have been closed", conn.isOpen());
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
// repeat the communication, no need to prepare the request again
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
@ -200,7 +200,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
final HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@ -235,7 +235,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
Assert.assertFalse("connection should have been closed", conn.isOpen());
// repeat the communication, no need to prepare the request again
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
response = exec.execute(request, conn, context);
@ -270,7 +270,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
Assert.assertTrue("connection should have been closed", !conn.isOpen());
// repeat the communication, no need to prepare the request again
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
response = exec.execute(request, conn, context);
@ -297,7 +297,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
final HttpContext context = new BasicHttpContext();
final HttpClientConnection conn = getConnection(mgr, route);
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
Assert.assertEquals(1, mgr.getStats(route).getLeased());
@ -337,7 +337,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
final HttpContext context = new BasicHttpContext();
final HttpClientConnection conn = getConnection(mgr, route);
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
Assert.assertEquals(1, mgr.getStats(route).getLeased());
@ -385,7 +385,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
HttpClientConnection conn = getConnection(mgr, route);
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@ -457,7 +457,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
Assert.fail("expected SocketException");
} catch(final SocketException expected) {}
@ -511,7 +511,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
Assert.fail("IOException expected");
} catch(final IOException expected) {
}
@ -566,7 +566,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
mgr.connect(conn, route.getTargetHost(), route.getLocalSocketAddress(), 0, context);
Assert.fail("IOException expected");
} catch(final IOException expected) {
}