Search in sources :

Example 6 with LayeredSocketFactory

use of org.apache.http.conn.scheme.LayeredSocketFactory in project XobotOS by xamarin.

the class DefaultClientConnectionOperator method updateSecureConnection.

// openConnection
// non-javadoc, see interface ClientConnectionOperator
public void updateSecureConnection(OperatedClientConnection conn, HttpHost target, HttpContext context, HttpParams params) throws IOException {
    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(), schm.resolvePort(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?
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) LayeredSocketFactory(org.apache.http.conn.scheme.LayeredSocketFactory) Socket(java.net.Socket) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)6 Socket (java.net.Socket)6 HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)6 LayeredSocketFactory (org.apache.http.conn.scheme.LayeredSocketFactory)6 Scheme (org.apache.http.conn.scheme.Scheme)6 InetAddress (java.net.InetAddress)3 SocketException (java.net.SocketException)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 PlainSocketFactory (org.apache.http.conn.scheme.PlainSocketFactory)3 SocketFactory (org.apache.http.conn.scheme.SocketFactory)3