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

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

Introduction

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

Prototype

public static SSLSocketFactory getSocketFactory() throws SSLInitializationException 

Source Link

Document

Obtains default SSL socket factory with an SSL context based on the standard JSSE trust material (cacerts file in the security properties directory).

Usage

From source file:com.deliciousdroid.client.HttpClientFactory.java

public static HttpClient getThreadSafeClient() {

    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 100);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
    ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager mgr = new ThreadSafeClientConnManager(params, schemeRegistry);
    HttpClient client = new DefaultHttpClient(mgr, params);

    return client;
}

From source file:net.sf.dvstar.transmission.protocol.TestConnection.java

public static void testConnection() throws Exception {
    // make sure to use a proxy that supports CONNECT
    HttpHost target = new HttpHost("195.74.67.237", 80, "http");
    HttpHost proxy = new HttpHost("192.168.4.7", 3128, "http");

    // general setup
    SchemeRegistry supportedSchemes = new SchemeRegistry();

    // Register the "http" and "https" protocol schemes, they are
    // required by the default operator to look up socket factories.
    supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, true);

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, supportedSchemes);

    DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params);

    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpGet req = new HttpGet("/");

    System.out.println("executing request to " + target + " via " + proxy);
    HttpResponse rsp = httpclient.execute(target, req);
    HttpEntity entity = rsp.getEntity();

    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    Header[] headers = rsp.getAllHeaders();
    for (int i = 0; i < headers.length; i++) {
        System.out.println(headers[i]);
    }//w ww. j  av a  2  s.c o  m
    System.out.println("----------------------------------------");

    if (entity != null) {
        System.out.println(EntityUtils.toString(entity));
    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:com.odoo.core.rpc.http.OdooSafeClient.java

private static void createThreadSafeClient(boolean forceSecure) {
    httpClient = new DefaultHttpClient();
    ClientConnectionManager mgr = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();
    SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();

    if (forceSecure) {
        schemeRegistry.register(new Scheme("https", getSecureConnectionSetting(), 443));
    } else {//from w  ww.j  a  va 2 s .co  m
        HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        schemeRegistry.register(new Scheme("https", socketFactory, 443));
    }

    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params);
}

From source file:com.sparkplatform.api.core.ConnectionApacheHttps.java

@Override
protected final void resetChild() {
    try {// w w  w .j a  va2s .c  om
        SSLSocketFactory sf = SSLSocketFactory.getSocketFactory();
        @SuppressWarnings("deprecation")
        Scheme https = new Scheme("https", sf, SSL_PORT); // Android constructor
        getClient().getConnectionManager().getSchemeRegistry().register(https);
        setHost(new HttpHost(getConfig().getEndpoint(), SSL_PORT, "https"));
    } catch (Exception e) {
        logger.error("Failed to setup SSL authentication for the client (https disabled).", e);
    }
}

From source file:net.issarlk.androbunny.utils.AbHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    return new ThreadSafeClientConnManager(getParams(), registry);
}

From source file:org.openqa.selenium.remote.internal.HttpClientFactory.java

private static ClientConnectionManager getClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(registry);
    cm.setMaxTotal(2000);/*from w  w  w .ja  v a 2  s  .  c o m*/
    cm.setDefaultMaxPerRoute(2000);
    return cm;
}

From source file:jacky.song.android.util.net.HttpConnector.java

private static HttpClient createClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUseExpectContinue(params, true);

    ConnManagerParams.setTimeout(params, 1000);

    HttpConnectionParams.setConnectionTimeout(params, 2000);
    HttpConnectionParams.setSoTimeout(params, 4000);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

From source file:com.pursuer.reader.easyrss.Utils.java

public static DefaultHttpClient createHttpClient() {
    final HttpParams config = new BasicHttpParams();
    HttpProtocolParams.setVersion(config, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(config, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(config, Utils.class.getName());

    final SchemeRegistry reg = new SchemeRegistry();
    reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg);

    final DefaultHttpClient client = new DefaultHttpClient(manager, config);
    client.getParams().setParameter("http.socket.timeout", 30 * 1000);
    return client;
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubHttpProvider.java

public GitHubHttpProvider() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(MAX_TOTAL_CONN);
    connectionManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("locahost", 80);
    connectionManager.setMaxPerRoute(new HttpRoute(localhost), MAX_LOCALHOST_CONN);
}

From source file:org.ale.scanner.zotero.web.HttpsClient.java

public static ThreadSafeClientConnManager setupSSLConnMan(HttpParams params) {
    SchemeRegistry registry = new SchemeRegistry();

    PlainSocketFactory pf = PlainSocketFactory.getSocketFactory();
    SSLSocketFactory sf = SSLSocketFactory.getSocketFactory();
    sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);

    registry.register(new Scheme("http", pf, 80));
    registry.register(new Scheme("https", (SocketFactory) sf, 443));

    return new ThreadSafeClientConnManager(params, registry);
}