HTTPCLIENT-822: Default socket factories to re-throw SocketTimeoutException as ConnectTimeoutException in case of connect failure due to time out
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@744525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd5061b2ab
commit
d855722988
|
@ -1,3 +1,14 @@
|
|||
Changes since 4.0 beta 2
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-822] Default socket factories to rethrow SocketTimeoutException as
|
||||
ConnectTimeoutException in case of connect failure due to a time out.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* [HTTPCLIENT-813] Fixed default port resolution. Invalid ports no longer
|
||||
get replaced with the default port value.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
Release 4.0 beta 2
|
||||
-------------------
|
||||
|
||||
|
@ -9,10 +20,6 @@ bundle combining HttpClient and HttpMime jars.
|
|||
|
||||
All upstream projects are strongly encouraged to upgrade.
|
||||
|
||||
* [HTTPCLIENT-813] Fixed default port resolution. Invalid ports no longer
|
||||
get replaced with the default port value.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* Fixed NPE in DefaultRequestDirector thrown when retrying a failed
|
||||
request over a proxied connection.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
|
|
@ -41,7 +41,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.SocketFactory;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -131,12 +130,12 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
|
|||
Collections.shuffle(addresses);
|
||||
|
||||
IOException lastEx = null;
|
||||
for (InetAddress address: addresses) {
|
||||
for (InetAddress remoteAddress: addresses) {
|
||||
try {
|
||||
sock.connect(new InetSocketAddress(address, port), timeout);
|
||||
sock.connect(new InetSocketAddress(remoteAddress, port), timeout);
|
||||
break;
|
||||
} catch (SocketTimeoutException ex) {
|
||||
throw ex;
|
||||
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
|
||||
} catch (IOException ex) {
|
||||
// create new socket
|
||||
sock = new Socket();
|
||||
|
@ -185,28 +184,4 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
|
|||
|
||||
} // isSecure
|
||||
|
||||
|
||||
/**
|
||||
* Compares this factory with an object.
|
||||
* There is only one instance of this class.
|
||||
*
|
||||
* @param obj the object to compare with
|
||||
*
|
||||
* @return iff the argument is this object
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj == this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a hash code for this object.
|
||||
* All instances of this class have the same hash code.
|
||||
* There is only one instance of this class.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return PlainSocketFactory.class.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,9 @@ import java.io.IOException;
|
|||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
|
@ -115,9 +117,11 @@ public final class PlainSocketFactory implements SocketFactory {
|
|||
} else {
|
||||
remoteAddress = new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
sock.connect(remoteAddress, timeout);
|
||||
|
||||
try {
|
||||
sock.connect(remoteAddress, timeout);
|
||||
} catch (SocketTimeoutException ex) {
|
||||
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
|
||||
}
|
||||
return sock;
|
||||
|
||||
} // connectSocket
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
package org.apache.http.conn.ssl;
|
||||
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.apache.http.conn.scheme.HostNameResolver;
|
||||
import org.apache.http.conn.scheme.LayeredSocketFactory;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
|
@ -47,6 +48,7 @@ import java.io.IOException;
|
|||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
|
@ -318,9 +320,11 @@ public class SSLSocketFactory implements LayeredSocketFactory {
|
|||
} else {
|
||||
remoteAddress = new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
sslsock.connect(remoteAddress, connTimeout);
|
||||
|
||||
try {
|
||||
sock.connect(remoteAddress, connTimeout);
|
||||
} catch (SocketTimeoutException ex) {
|
||||
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
|
||||
}
|
||||
sslsock.setSoTimeout(soTimeout);
|
||||
try {
|
||||
hostnameVerifier.verify(host, sslsock);
|
||||
|
|
Loading…
Reference in New Issue