From 92d66f33555e39dd80e35cfd1bf38e06bd960c08 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 7 Jun 2011 08:25:24 +0000 Subject: [PATCH] HTTPCLIENT-1098: Avoid expensive reverse DNS lookup on connect timeout excpetion Contributed by Thomas Boettcher git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1132902 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 9 +++++++-- .../java/org/apache/http/conn/HttpInetSocketAddress.java | 6 ++++++ .../org/apache/http/conn/scheme/PlainSocketFactory.java | 3 +-- .../java/org/apache/http/conn/ssl/SSLSocketFactory.java | 3 +-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 7b6c6f421..755220bde 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,9 +1,14 @@ Changes since 4.1.1 -* [HTTPCLIENT-1097] BrowserCompatHostnameVerifier and StrictHostnameVerifier should handle wildcards in SSL certificates better. +* [HTTPCLIENT-1098] Avoid expensive reverse DNS lookup on connect timeout exception. + Contributed by Thomas Boettcher + +* [HTTPCLIENT-1097] BrowserCompatHostnameVerifier and StrictHostnameVerifier should handle + wildcards in SSL certificates better. Contributed by Sebastian Bazley -* [HTTPCLIENT-1092] If ClientPNames.VIRTUAL_HOST does not provide the port, derive it from the current request. +* [HTTPCLIENT-1092] If ClientPNames.VIRTUAL_HOST does not provide the port, derive it from the + current request. Contributed by Sebastian Bazley * [HTTPCLIENT-1087] NTLM proxy authentication fails on retry if the underlying connection is closed diff --git a/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java b/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java index abd902abc..62441576d 100644 --- a/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java +++ b/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java @@ -54,5 +54,11 @@ public class HttpInetSocketAddress extends InetSocketAddress { public HttpHost getHost() { return this.host; } + + @Override + public String toString() { + return this.host.getHostName() + ":" + getPort(); + } + } diff --git a/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java index 544ce0809..2de278e99 100644 --- a/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java +++ b/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java @@ -122,8 +122,7 @@ public class PlainSocketFactory implements SocketFactory, SchemeSocketFactory { sock.setSoTimeout(soTimeout); sock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { - throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/" - + remoteAddress.getAddress() + " timed out"); + throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out"); } return sock; } diff --git a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java index babe3440a..930d3aba1 100644 --- a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java +++ b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java @@ -375,8 +375,7 @@ public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSock sock.setSoTimeout(soTimeout); sock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { - throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/" - + remoteAddress.getAddress() + " timed out"); + throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out"); } SSLSocket sslsock; // Setup SSL layering if necessary