Tweaked HttpInetSocketAddress class; updated javadocs

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1158312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-08-16 15:00:08 +00:00
parent 5227866cd9
commit 4bb50b352c
4 changed files with 21 additions and 14 deletions

View File

@ -41,24 +41,23 @@ public class HttpInetSocketAddress extends InetSocketAddress {
private static final long serialVersionUID = -6650701828361907957L;
private final HttpHost host;
private final HttpHost httphost;
public HttpInetSocketAddress(final HttpHost host, final InetAddress addr, int port) {
public HttpInetSocketAddress(final HttpHost httphost, final InetAddress addr, int port) {
super(addr, port);
if (host == null) {
if (httphost == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
this.host = host;
this.httphost = httphost;
}
public HttpHost getHost() {
return this.host;
public HttpHost getHttpHost() {
return this.httphost;
}
@Override
public String toString() {
return this.host.getHostName() + ":" + getPort();
return this.httphost.getHostName() + ":" + getPort();
}
}

View File

@ -32,8 +32,7 @@
import java.net.UnknownHostException;
/**
* A {@link SocketFactory SocketFactory} for layered sockets (SSL/TLS).
* See there for things to consider when implementing a socket factory.
* Extended {@link SchemeSocketFactory} interface for layered sockets such as SSL/TLS.
*
* @since 4.1
*/

View File

@ -32,7 +32,9 @@
import java.net.Socket;
import java.net.UnknownHostException;
import org.apache.http.HttpHost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpInetSocketAddress;
import org.apache.http.params.HttpParams;
/**
@ -63,12 +65,17 @@ public interface SchemeSocketFactory {
/**
* Connects a socket to the target host with the given remote address.
* <p/>
* Please note that {@link HttpInetSocketAddress} class should be used in order to pass
* the target remote address along with the original {@link HttpHost} value used to resolve
* the address. The use of {@link HttpInetSocketAddress} can also ensure that no reverse
* DNS lookup will be performed if the target remote address was specified as an IP address.
*
* @param sock the socket to connect, as obtained from
* {@link #createSocket(HttpParams) createSocket}.
* <code>null</code> indicates that a new socket
* should be created and connected.
* @param remoteAddress the remote address to connect to
* @param remoteAddress the remote address to connect to.
* @param localAddress the local address to bind the socket to, or
* <code>null</code> for any
* @param params additional {@link HttpParams parameters} for connecting
@ -82,6 +89,8 @@ public interface SchemeSocketFactory {
* can not be determined
* @throws ConnectTimeoutException if the socket cannot be connected
* within the time limit defined in the <code>params</code>
*
* @see HttpInetSocketAddress
*/
Socket connectSocket(
Socket sock,

View File

@ -385,7 +385,7 @@ public Socket connectSocket(
String hostname;
if (remoteAddress instanceof HttpInetSocketAddress) {
hostname = ((HttpInetSocketAddress) remoteAddress).getHost().getHostName();
hostname = ((HttpInetSocketAddress) remoteAddress).getHttpHost().getHostName();
} else {
hostname = remoteAddress.getHostName();
}
@ -395,8 +395,8 @@ public Socket connectSocket(
if (sock instanceof SSLSocket) {
sslsock = (SSLSocket) sock;
} else {
sslsock = (SSLSocket) this.socketfactory.createSocket(sock,
hostname, remoteAddress.getPort(), true);
int port = remoteAddress.getPort();
sslsock = (SSLSocket) this.socketfactory.createSocket(sock, hostname, port, true);
prepareSocket(sslsock);
}
if (this.hostnameVerifier != null) {