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.phonty.improved.Balance.java

public Balance(String url, Context _context) {
    context = _context;/*w  ww .j  a  va2  s.  com*/
    APIURL = url;
    httppost = new HttpPost(APIURL);
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params, context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
}

From source file:com.phonty.improved.Calls.java

public Calls(String url, Context _context) {
    context = _context;// w  ww.  j  av a 2 s .c  o  m
    APIURL = url;
    httppost = new HttpPost(APIURL);
    httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params, context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE);
    client.setCookieStore(cookieStore);
    VALUES = new ArrayList<CallItem>();
    type = "Calls:";

}

From source file:com.phonty.improved.Rates.java

public Rates(String url, Context _context) {
    context = _context;/*  w w  w  .  ja va2s . c o  m*/
    APIURL = url;
    httppost = new HttpPost(APIURL);
    httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params, context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE);
    client.setCookieStore(cookieStore);
    VALUES = new ArrayList<PriceItem>();
    type = "Calls:";

}

From source file:com.decody.android.core.json.JSONClient.java

public JSONClient(GsonFactory factory, boolean https) {
    this.factory = factory;

    if (https) {//from   ww w  . jav a2 s.  c  o  m
        HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        DefaultHttpClient client = new DefaultHttpClient();

        SchemeRegistry registry = new SchemeRegistry();
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        registry.register(new Scheme("https", socketFactory, 443));
        SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);

        this.client = new DefaultHttpClient(mgr, client.getParams());
    } else {
        client = new DefaultHttpClient();
    }
}

From source file:com.lonepulse.zombielink.executor.ConfigurationService.java

/**
 * <p>The <i>out-of-the-box</i> configuration for an instance of {@link HttpClient} which will be used 
 * for executing all endpoint requests. Below is a detailed description of all configured properties.</p> 
 * <br>/*from  www  .j  a v  a  2 s.c  o  m*/
 * <ul>
 * <li>
 * <p><b>HttpClient</b></p>
 * <br>
 * <p>It registers two {@link Scheme}s:</p>
 * <br>
 * <ol>
 *    <li><b>HTTP</b> on port <b>80</b> using sockets from {@link PlainSocketFactory#getSocketFactory}</li>
 *    <li><b>HTTPS</b> on port <b>443</b> using sockets from {@link SSLSocketFactory#getSocketFactory}</li>
 * </ol>
 * 
 * <p>It uses a {@link PoolingClientConnectionManager} with the maximum number of client connections 
 * per route set to <b>4</b> and the total set to <b>128</b>.</p>
 * </li>
 * </ul>
 * @return the instance of {@link HttpClient} which will be used for request execution
 * <br><br>
 * @since 1.3.0
 */
@Override
public Configuration getDefault() {

    return new Configuration() {

        @Override
        public HttpClient httpClient() {

            try {

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

                PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(schemeRegistry);
                pccm.setMaxTotal(200);
                pccm.setDefaultMaxPerRoute(20);

                return new DefaultHttpClient(pccm);
            } catch (Exception e) {

                throw new ConfigurationFailedException(e);
            }
        }
    };
}

From source file:com.bigdata.rdf.sail.webapp.client.DefaultClientConnectionManagerFactory.java

/**
 * Return a {@link SchemeRegistry} which has been pre-configured for HTTP
 * and HTTPS./*from  w  ww .  j a v a2 s  . co  m*/
 */
protected SchemeRegistry newSchemeRegistry() {

    final SchemeRegistry schemeRegistry = new SchemeRegistry();

    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    return schemeRegistry;

}

From source file:com.twotoasters.android.hoot.HootTransportHttpClient.java

@Override
public void setup(Hoot hoot) {
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 10);
    ConnManagerParams.setTimeout(params, hoot.getTimeout());
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpConnectionParams.setConnectionTimeout(params, hoot.getTimeout());
    HttpConnectionParams.setSoTimeout(params, hoot.getTimeout());
    HttpConnectionParams.setTcpNoDelay(params, true);

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

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    mClient = new DefaultHttpClient(cm, params);
    if (hoot.isBasicAuth()) {
        mClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(hoot.getBasicAuthUsername(), hoot.getBasicAuthPassword()));
    }//from  www .  j  av a 2 s  .  com
}

From source file:com.hoccer.api.RESTfulApiTest.java

public RESTfulApiTest() {
    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    ConnManagerParams.setMaxTotalConnections(httpParams, 100);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    mHttpClient = new HttpClientWithKeystore(cm, httpParams);
}

From source file:com.vinaysshenoy.easyoauth.http.HttpManager.java

private void initHttpClient() {

    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setUserAgent(params, mHttpConfig.userAgent);
    HttpProtocolParams.setVersion(params, mHttpConfig.httpVersion);
    HttpProtocolParams.setContentCharset(params, mHttpConfig.contentCharset);

    HttpConnectionParams.setStaleCheckingEnabled(params, mHttpConfig.enableStaleChecking);
    HttpConnectionParams.setConnectionTimeout(params, mHttpConfig.connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, mHttpConfig.socketTimeout);
    HttpConnectionParams.setSocketBufferSize(params, mHttpConfig.socketBufferSize);

    HttpClientParams.setRedirecting(params, mHttpConfig.isRedirecting);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(/* ww w  .  j  a  v a 2  s  .  c o m*/
            new Scheme(HttpConfig.KEY_HTTP, PlainSocketFactory.getSocketFactory(), mHttpConfig.httpPort));
    schemeRegistry.register(
            new Scheme(HttpConfig.KEY_HTTPS, SSLSocketFactory.getSocketFactory(), mHttpConfig.httpsPort));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
    mHttpClient = new DefaultHttpClient(manager, params);
}

From source file:devza.app.android.droidnetkey.UsageAction.java

public UsageAction(Context context, TextView usage, TextView cost) {
    this.context = context;
    this.cost = cost;
    this.usage = usage;

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

    //HTTP Paramaters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, USER_AGENT);
    HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT);
    SingleClientConnManager cm = new SingleClientConnManager(params, registry);

    this.client = new DefaultHttpClient(cm, params);

}