Example usage for org.apache.http.conn.scheme Scheme getSchemeSocketFactory

List of usage examples for org.apache.http.conn.scheme Scheme getSchemeSocketFactory

Introduction

In this page you can find the example usage for org.apache.http.conn.scheme Scheme getSchemeSocketFactory.

Prototype

public final SchemeSocketFactory getSchemeSocketFactory() 

Source Link

Document

Obtains the socket factory.

Usage

From source file:com.subgraph.vega.internal.http.requests.connection.SocksModeClientConnectionOperator.java

@Override
public void openConnection(OperatedClientConnection conn, HttpHost target, InetAddress local,
        HttpContext context, HttpParams params) throws IOException {
    if (!isSocksMode) {
        super.openConnection(conn, target, local, context, params);
        return;//  w w w.jav  a  2s.com
    }
    final Scheme scheme = schemeRegistry.getScheme(target.getSchemeName());
    final SchemeSocketFactory sf = scheme.getSchemeSocketFactory();

    final int port = scheme.resolvePort(target.getPort());
    Socket sock = sf.createSocket(params);
    conn.opening(sock, target);
    InetSocketAddress remoteAddress = InetSocketAddress.createUnresolved(target.getHostName(), port);
    InetSocketAddress localAddress = null;
    if (local != null) {
        localAddress = new InetSocketAddress(local, 0);
    }
    try {
        Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
        if (sock != connsock) {
            sock = connsock;
            conn.opening(sock, target);
        }
        prepareSocket(sock, context, params);
        conn.openCompleted(sf.isSecure(sock), params);
        return;
    } catch (ConnectException ex) {
        throw new HttpHostConnectException(target, ex);
    }
}

From source file:nl.esciencecenter.octopus.webservice.JobLauncherServiceTest.java

@Test
public void useInsecureSSL_NoHostnameVerifier()
        throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
    HttpClient httpClient = new DefaultHttpClient();

    service.useInsecureSSL(httpClient);/*from w  w  w .ja  v  a  2s .c  o m*/

    Scheme scheme = httpClient.getConnectionManager().getSchemeRegistry().get("https");
    SSLSocketFactory factory = (SSLSocketFactory) scheme.getSchemeSocketFactory();
    assertEquals(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,
            factory.getHostnameVerifier());
}

From source file:org.apache.http.impl.conn.DefaultClientConnectionOperator.java

public void openConnection(final OperatedClientConnection conn, final HttpHost target, final InetAddress local,
        final HttpContext context, final HttpParams params) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(target, "Target host");
    Args.notNull(params, "HTTP parameters");
    Asserts.check(!conn.isOpen(), "Connection must not be open");

    final SchemeRegistry registry = getSchemeRegistry(context);
    final Scheme schm = registry.getScheme(target.getSchemeName());
    final SchemeSocketFactory sf = schm.getSchemeSocketFactory();

    final InetAddress[] addresses = resolveHostname(target.getHostName());
    final int port = schm.resolvePort(target.getPort());
    for (int i = 0; i < addresses.length; i++) {
        final InetAddress address = addresses[i];
        final boolean last = i == addresses.length - 1;

        Socket sock = sf.createSocket(params);
        conn.opening(sock, target);//from ww w .j  a v  a  2s  . c  o  m

        final InetSocketAddress remoteAddress = new HttpInetSocketAddress(target, address, port);
        InetSocketAddress localAddress = null;
        if (local != null) {
            localAddress = new InetSocketAddress(local, 0);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connecting to " + remoteAddress);
        }
        try {
            final Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
            if (sock != connsock) {
                sock = connsock;
                conn.opening(sock, target);
            }
            prepareSocket(sock, context, params);
            conn.openCompleted(sf.isSecure(sock), params);
            return;
        } catch (final ConnectException ex) {
            if (last) {
                throw ex;
            }
        } catch (final ConnectTimeoutException ex) {
            if (last) {
                throw ex;
            }
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connect to " + remoteAddress + " timed out. "
                    + "Connection will be retried using another IP address");
        }
    }
}

From source file:org.apache.http.impl.conn.DefaultClientConnectionOperator.java

public void updateSecureConnection(final OperatedClientConnection conn, final HttpHost target,
        final HttpContext context, final HttpParams params) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(target, "Target host");
    Args.notNull(params, "Parameters");
    Asserts.check(conn.isOpen(), "Connection must be open");

    final SchemeRegistry registry = getSchemeRegistry(context);
    final Scheme schm = registry.getScheme(target.getSchemeName());
    Asserts.check(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory,
            "Socket factory must implement SchemeLayeredSocketFactory");
    final SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
    final Socket sock = lsf.createLayeredSocket(conn.getSocket(), target.getHostName(),
            schm.resolvePort(target.getPort()), params);
    prepareSocket(sock, context, params);
    conn.update(sock, target, lsf.isSecure(sock), params);
}