diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/DnsResolver.java b/httpclient5/src/main/java/org/apache/hc/client5/http/DnsResolver.java index 1818363dc..fdd5221dd 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/DnsResolver.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/DnsResolver.java @@ -28,7 +28,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collections; @@ -68,13 +67,13 @@ public interface DnsResolver { String resolveCanonicalHostname(String host) throws UnknownHostException; /** - * Returns a list of {@link SocketAddress} for the given host with the given port. + * Returns a list of {@link InetSocketAddress} for the given host with the given port. * - * @see SocketAddress + * @see InetSocketAddress * * @since 5.5 */ - default List resolve(String host, int port) throws UnknownHostException { + default List resolve(String host, int port) throws UnknownHostException { final InetAddress[] inetAddresses = resolve(host); if (inetAddresses == null) { return Collections.singletonList(InetSocketAddress.createUnresolved(host, port)); @@ -83,5 +82,4 @@ default List resolve(String host, int port) throws UnknownHostExc .map(e -> new InetSocketAddress(e, port)) .collect(Collectors.toList()); } - } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java index 47bcb8732..33a4cfcf8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java @@ -163,7 +163,7 @@ public void connect( final SocketAddress socksProxyAddress = socketConfig.getSocksProxyAddress(); final Proxy socksProxy = socksProxyAddress != null ? new Proxy(Proxy.Type.SOCKS, socksProxyAddress) : null; - final List remoteAddresses; + final List remoteAddresses; if (endpointHost.getAddress() != null) { remoteAddresses = Collections.singletonList( new InetSocketAddress(endpointHost.getAddress(), this.schemePortResolver.resolve(endpointHost.getSchemeName(), endpointHost))); @@ -172,7 +172,7 @@ public void connect( remoteAddresses = this.dnsResolver.resolve(endpointHost.getHostName(), port); } for (int i = 0; i < remoteAddresses.size(); i++) { - final InetSocketAddress remoteAddress = (InetSocketAddress) remoteAddresses.get(i); + final InetSocketAddress remoteAddress = remoteAddresses.get(i); final boolean last = i == remoteAddresses.size() - 1; onBeforeSocketConnect(context, endpointHost); if (LOG.isDebugEnabled()) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java index 4f2274747..fb92f490c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java @@ -108,7 +108,7 @@ public void cancelled() { LOG.debug("{} resolving remote address", remoteEndpoint.getHostName()); } - final List remoteAddresses; + final List remoteAddresses; try { remoteAddresses = dnsResolver.resolve(remoteEndpoint.getHostName(), remoteEndpoint.getPort()); if (remoteAddresses == null || remoteAddresses.isEmpty()) { diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java index 973d90835..cc58551a2 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java @@ -31,7 +31,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; -import java.net.SocketAddress; import java.net.SocketTimeoutException; import java.util.Arrays; import java.util.Collections; @@ -93,7 +92,7 @@ void testConnect() throws Exception { final InetAddress ip1 = InetAddress.getByAddress(new byte[] {127, 0, 0, 1}); final InetAddress ip2 = InetAddress.getByAddress(new byte[] {127, 0, 0, 2}); final int port = 80; - final List resolvedAddresses = Arrays.asList( + final List resolvedAddresses = Arrays.asList( new InetSocketAddress(ip1, port), new InetSocketAddress(ip2, port) ); @@ -137,7 +136,7 @@ void testConnectWithTLSUpgrade() throws Exception { .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1) .build(); - final List resolvedAddresses = Arrays.asList( + final List resolvedAddresses = Arrays.asList( new InetSocketAddress(ip1, port), new InetSocketAddress(ip2, port) ); @@ -173,7 +172,7 @@ void testConnectTimeout() throws Exception { final int port = 80; final InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1}); final InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2}); - final List resolvedAddresses = Arrays.asList( + final List resolvedAddresses = Arrays.asList( new InetSocketAddress(ip1, port), new InetSocketAddress(ip2, port) ); @@ -194,7 +193,7 @@ void testConnectFailure() throws Exception { final InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1}); final InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2}); final int port = 80; - final List resolvedAddresses = Arrays.asList( + final List resolvedAddresses = Arrays.asList( new InetSocketAddress(ip1, port), new InetSocketAddress(ip2, port) ); @@ -311,7 +310,7 @@ void testConnectWithDisableDnsResolution() throws Exception { final InetAddress local = InetAddress.getByAddress(new byte[]{127, 0, 0, 0}); final int port = 80; - final List resolvedAddresses = Collections.singletonList( + final List resolvedAddresses = Collections.singletonList( InetSocketAddress.createUnresolved(host.getHostName(), port) ); Mockito.when(dnsResolver.resolve(host.getHostName(), port)).thenReturn(resolvedAddresses); @@ -354,7 +353,7 @@ void testConnectWithDnsResolutionAndFallback() throws Exception { final InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2}); // Update to match the new `resolve` implementation that returns a list of SocketAddress - final List resolvedAddresses = Arrays.asList( + final List resolvedAddresses = Arrays.asList( new InetSocketAddress(ip1, port), new InetSocketAddress(ip2, port) ); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequesterTest.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequesterTest.java index 5c95f5e46..e2ec5696b 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequesterTest.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequesterTest.java @@ -37,7 +37,6 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -73,7 +72,7 @@ void setUp() { void testConnectWithMultipleAddresses() throws Exception { final InetAddress address1 = InetAddress.getByAddress(new byte[]{10, 0, 0, 1}); final InetAddress address2 = InetAddress.getByAddress(new byte[]{10, 0, 0, 2}); - final List remoteAddresses = Arrays.asList( + final List remoteAddresses = Arrays.asList( new InetSocketAddress(address1, 8080), new InetSocketAddress(address2, 8080) ); @@ -115,7 +114,7 @@ void testConnectWithMultipleAddresses() throws Exception { void testConnectSuccessfulAfterRetries() throws Exception { final InetAddress address1 = InetAddress.getByAddress(new byte[]{10, 0, 0, 1}); final InetAddress address2 = InetAddress.getByAddress(new byte[]{10, 0, 0, 2}); - final List remoteAddresses = Arrays.asList( + final List remoteAddresses = Arrays.asList( new InetSocketAddress(address1, 8080), new InetSocketAddress(address2, 8080) );