Example usage for org.apache.http.conn.ssl SSLSocketFactory connectSocket

List of usage examples for org.apache.http.conn.ssl SSLSocketFactory connectSocket

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl SSLSocketFactory connectSocket.

Prototype

public Socket connectSocket(final Socket socket, final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress, final HttpParams params)
        throws IOException, UnknownHostException, ConnectTimeoutException 

Source Link

Usage

From source file:no.kantega.kwashc.server.test.SSLCipherSuiteTest.java

private HttpResponse checkClientForCiphers(Site site, int httpsPort, HttpClient httpclient, String[] ciphers)
        throws NoSuchAlgorithmException, KeyManagementException, IOException {
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new TrustManager[] { allowAllTrustManager }, null);

    SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000);

    SSLSocket socket = (SSLSocket) sf.createSocket(params);
    socket.setEnabledCipherSuites(ciphers);

    URL url = new URL(site.getAddress());

    InetSocketAddress address = new InetSocketAddress(url.getHost(), httpsPort);
    sf.connectSocket(socket, address, null, params);

    Scheme sch = new Scheme("https", httpsPort, sf);
    httpclient.getConnectionManager().getSchemeRegistry().register(sch);

    HttpGet request = new HttpGet(
            "https://" + url.getHost() + ":" + site.getSecureport() + url.getPath() + "blog");

    return httpclient.execute(request);
}

From source file:no.kantega.kwashc.server.test.SSLProtocolTest.java

private HttpResponse checkClient(Site site, int httpsPort, HttpClient httpclient, String[] protocols,
        String[] ciphers) throws NoSuchAlgorithmException, KeyManagementException, IOException {
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new TrustManager[] { allowAllTrustManager }, null);

    SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000);

    SSLSocket socket = (SSLSocket) sf.createSocket(params);
    if (protocols != null) {
        socket.setEnabledProtocols(protocols);
    }// www  .j a  v  a 2  s .  c  om
    if (ciphers != null) {
        socket.setEnabledCipherSuites(ciphers);
    }

    URL url = new URL(site.getAddress());

    InetSocketAddress address = new InetSocketAddress(url.getHost(), httpsPort);
    sf.connectSocket(socket, address, null, params);

    Scheme sch = new Scheme("https", httpsPort, sf);
    httpclient.getConnectionManager().getSchemeRegistry().register(sch);

    HttpGet request = new HttpGet(
            "https://" + url.getHost() + ":" + site.getSecureport() + url.getPath() + "blog");

    return httpclient.execute(request);
}