HTTPCLIENT-697: Throw a more intelligible exception when connection to a remote host cannot be established.
Contributed by Oleg Kalnichevski Reviewed by Ortwin Glück git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@589382 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a8e875970d
commit
e445d72146
|
@ -1,5 +1,9 @@
|
|||
Changes since release 4.0 Alpha 1
|
||||
|
||||
* [HTTPCLIENT-697] Throw a more intelligible exception when connection
|
||||
to a remote host cannot be established.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* [HTTPCLIENT-689] Caching of SimpleDateFormat in DateUtils
|
||||
Contributed by Daniel Müller <strider at digitalstrider.com>
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
|
||||
public class HttpHostConnectException extends ConnectException {
|
||||
|
||||
private static final long serialVersionUID = -3194482710275220224L;
|
||||
|
||||
private final HttpHost host;
|
||||
|
||||
public HttpHostConnectException(final HttpHost host, final ConnectException cause) {
|
||||
super("Connection to " + host + " refused");
|
||||
this.host = host;
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
public HttpHost getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.Socket;
|
||||
import java.net.InetAddress;
|
||||
|
||||
|
@ -40,6 +41,7 @@ import org.apache.http.params.HttpParams;
|
|||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
import org.apache.http.conn.Scheme;
|
||||
import org.apache.http.conn.SchemeRegistry;
|
||||
import org.apache.http.conn.SocketFactory;
|
||||
|
@ -128,9 +130,13 @@ public class DefaultClientConnectionOperator
|
|||
Socket sock = sf.createSocket();
|
||||
conn.announce(sock);
|
||||
|
||||
try {
|
||||
sock = sf.connectSocket(sock, target.getHostName(),
|
||||
schm.resolvePort(target.getPort()),
|
||||
local, 0, params);
|
||||
} catch (ConnectException ex) {
|
||||
throw new HttpHostConnectException(target, ex);
|
||||
}
|
||||
prepareSocket(sock, context, params);
|
||||
|
||||
final boolean secure = sf.isSecure(sock);
|
||||
|
@ -180,15 +186,16 @@ public class DefaultClientConnectionOperator
|
|||
") must have layered socket factory.");
|
||||
}
|
||||
|
||||
final LayeredSocketFactory ssf =
|
||||
(LayeredSocketFactory)schm.getSocketFactory();
|
||||
final Socket sock = ssf.createSocket
|
||||
final LayeredSocketFactory lsf = (LayeredSocketFactory) schm.getSocketFactory();
|
||||
final Socket sock;
|
||||
try {
|
||||
sock = lsf.createSocket
|
||||
(conn.getSocket(), target.getHostName(), target.getPort(), true);
|
||||
} catch (ConnectException ex) {
|
||||
throw new HttpHostConnectException(target, ex);
|
||||
}
|
||||
prepareSocket(sock, context, params);
|
||||
|
||||
final boolean secure = ssf.isSecure(sock);
|
||||
|
||||
conn.update(sock, target, secure, params);
|
||||
conn.update(sock, target, lsf.isSecure(sock), params);
|
||||
//@@@ error handling: close the layered socket in case of exception?
|
||||
|
||||
} // updateSecureConnection
|
||||
|
|
Loading…
Reference in New Issue