DefaultClientConnectionOperatorpublic class DefaultClientConnectionOperator extends Object implements ClientConnectionOperatorDefault implementation of a
{@link ClientConnectionOperator ClientConnectionOperator}.
It uses a {@link SchemeRegistry SchemeRegistry} to look up
{@link SocketFactory SocketFactory} objects. |
Fields Summary |
---|
protected SchemeRegistry | schemeRegistryThe scheme registry for looking up socket factories. |
Constructors Summary |
---|
public DefaultClientConnectionOperator(SchemeRegistry schemes)Creates a new client connection operator for the given scheme registry.
if (schemes == null) {
throw new IllegalArgumentException
("Scheme registry must not be null.");
}
schemeRegistry = schemes;
|
Methods Summary |
---|
public org.apache.http.conn.OperatedClientConnection | createConnection()
return new DefaultClientConnection();
| public void | openConnection(org.apache.http.conn.OperatedClientConnection conn, org.apache.http.HttpHost target, java.net.InetAddress local, org.apache.http.protocol.HttpContext context, org.apache.http.params.HttpParams params)
if (conn == null) {
throw new IllegalArgumentException
("Connection must not be null.");
}
if (target == null) {
throw new IllegalArgumentException
("Target host must not be null.");
}
// local address may be null
//@@@ is context allowed to be null?
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
if (conn.isOpen()) {
throw new IllegalArgumentException
("Connection must not be open.");
}
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
final SocketFactory sf = schm.getSocketFactory();
Socket sock = sf.createSocket();
conn.opening(sock, target);
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);
conn.openCompleted(sf.isSecure(sock), params);
| protected void | prepareSocket(java.net.Socket sock, org.apache.http.protocol.HttpContext context, org.apache.http.params.HttpParams params)Performs standard initializations on a newly created socket.
// context currently not used, but derived classes may need it
//@@@ is context allowed to be null?
sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
int linger = HttpConnectionParams.getLinger(params);
if (linger >= 0) {
sock.setSoLinger(linger > 0, linger);
}
| public void | updateSecureConnection(org.apache.http.conn.OperatedClientConnection conn, org.apache.http.HttpHost target, org.apache.http.protocol.HttpContext context, org.apache.http.params.HttpParams params)
if (conn == null) {
throw new IllegalArgumentException
("Connection must not be null.");
}
if (target == null) {
throw new IllegalArgumentException
("Target host must not be null.");
}
//@@@ is context allowed to be null?
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
if (!conn.isOpen()) {
throw new IllegalArgumentException
("Connection must be open.");
}
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
if (!(schm.getSocketFactory() instanceof LayeredSocketFactory)) {
throw new IllegalArgumentException
("Target scheme (" + schm.getName() +
") must have layered socket factory.");
}
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);
conn.update(sock, target, lsf.isSecure(sock), params);
//@@@ error handling: close the layered socket in case of exception?
|
|