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:org.eclipse.koneki.protocols.omadm.client.http.internal.DMHttpClient.java

public DMHttpClient() {
    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); //$NON-NLS-1$
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); //$NON-NLS-1$
    this.httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry));
}

From source file:com.google.appinventor.components.runtime.util.WebServiceUtil.java

/**
 * Returns the one <code>WebServiceUtil</code> instance
 * @return the one <code>WebServiceUtil</code> instance
 *///from  w w w . j  a v  a2  s  . c  om
public static WebServiceUtil getInstance() {
    // This needs to be here instead of in the constructor because
    // it uses classes that are in the AndroidSDK and thus would
    // cause Stub! errors when running the component descriptor.
    synchronized (httpClientSynchronizer) {
        if (httpClient == null) {
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
            BasicHttpParams params = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
            HttpConnectionParams.setSoTimeout(params, 20 * 1000);
            ConnManagerParams.setMaxTotalConnections(params, 20);
            ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
            WebServiceUtil.httpClient = new DefaultHttpClient(manager, params);
        }
    }
    return INSTANCE;
}

From source file:org.codegist.crest.io.http.HttpClientFactory.java

public static HttpClient create(CRestConfig crestConfig, Class<?> source) {
    HttpClient httpClient = crestConfig.get(source.getName() + HTTP_CLIENT);
    if (httpClient != null) {
        return httpClient;
    }/*from   ww  w. j a v  a 2  s  .  co  m*/

    int concurrencyLevel = crestConfig.getConcurrencyLevel();
    if (concurrencyLevel > 1) {
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(concurrencyLevel));
        ConnManagerParams.setMaxTotalConnections(params, concurrencyLevel);

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

        ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
        httpClient = new DefaultHttpClient(cm, params);
    } else {
        httpClient = new DefaultHttpClient();
    }
    ((DefaultHttpClient) httpClient).setRoutePlanner(new ProxySelectorRoutePlanner(
            httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()));
    return httpClient;
}

From source file:net.eve.finger.server.JSONAuth.java

public JSONAuth() {
    // Create a thread safe HTTPS client
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(schemeRegistry);
    httpClient = new DefaultHttpClient(cm);
}

From source file:com.fuzhouxiu.coretransfer.net.core.TcpSocket.java

/** Creates a new UdpSocket */
public TcpSocket(IpAddress ipaddr, int port, String host) throws java.io.IOException {
    //      socket = new Socket(ipaddr.getInetAddress(), port); modified
    SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getSocketFactory();
    if (host == null)
        socket = new Socket();
    else/*from w ww  . j  a  v  a 2  s  .co  m*/
        socket = f.createSocket();
    if (lock)
        throw new java.io.IOException();
    lock = true;
    try {
        socket.connect(new InetSocketAddress(ipaddr.toString(), port),
                Thread.currentThread().getName().equals("main") ? 1000 : 10000);
    } catch (java.io.IOException e) {
        lock = false;
        throw e;
    }
    if (host != null) {
        HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
        SSLSession s = ((SSLSocket) socket).getSession();
        if (!hv.verify(host, s)) {
            lock = false;
            throw new java.io.IOException();
        }
    }
    lock = false;
}

From source file:com.android.dumprendertree2.FsUtils.java

private static HttpClient getHttpClient() {
    if (sHttpClient == null) {
        HttpParams params = new BasicHttpParams();

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(/*w w  w.  j  ava2 s .  co m*/
                new Scheme("http", PlainSocketFactory.getSocketFactory(), ForwarderManager.HTTP_PORT));
        schemeRegistry.register(
                new Scheme("https", SSLSocketFactory.getSocketFactory(), ForwarderManager.HTTPS_PORT));

        ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
        sHttpClient = new DefaultHttpClient(connectionManager, params);
        HttpConnectionParams.setSoTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS);
        HttpConnectionParams.setConnectionTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS);
    }
    return sHttpClient;
}

From source file:net.ecfirm.ec.ec1.net.EcNetHelper.java

public static DefaultHttpClient getThreadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    /////////*from w w w  .jav a2 s.  c  om*/
    client.getParams().setParameter("http.protocol.expect-continue", false);
    client.getParams().setParameter("http.connection.timeout", EcConst.NET_HTTP_CONN_TIMEOUT);
    //client.getParams().setParameter("http.socket.timeout", );
    ////////
    HttpParams params = client.getParams();
    ////////
    ConnManagerParams.setMaxTotalConnections(params, EcConst.NET_HTTP_CONN);
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(EcConst.NET_HTTP_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("localhost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), EcConst.NET_HTTP_CONN_PER_ROUTE);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    mgr.getSchemeRegistry().register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    mgr.getSchemeRegistry().register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ////////
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
    return client;
}

From source file:com.base.httpclient.HttpJsonClient.java

/**
 * httpClient/* w w w.j a va  2 s.c o  m*/
 * @return
 */
public static DefaultHttpClient getHttpClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    HttpParams httpParams = new BasicHttpParams();
    cm.setMaxTotal(10);//   
    cm.setDefaultMaxPerRoute(5);// ? 
    HttpConnectionParams.setConnectionTimeout(httpParams, 60000);//
    HttpConnectionParams.setSoTimeout(httpParams, 60000);//?
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(httpParams, false);
    httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    DefaultHttpClient httpClient = new DefaultHttpClient(cm, httpParams);
    //httpClient.setCookieStore(null);
    httpClient.getCookieStore().clear();
    httpClient.getCookieStore().getCookies().clear();
    //   httpClient.setHttpRequestRetryHandler(new HttpJsonClient().new HttpRequestRetry());//?
    return httpClient;
}

From source file:com.juick.android.JettyWsClient.java

public boolean connect(String host, int port, String location, String headers) {
    try {//from www. ja  v  a  2s.  com

        SSLSocketFactory sf = SSLSocketFactory.getSocketFactory();
        HttpParams params = new BasicHttpParams();
        sock = sf.connectSocket(sock, host, port, null, 0, params);

        is = sock.getInputStream();
        os = sock.getOutputStream();

        String handshake = "GET " + location + " HTTP/1.1\r\n" + "Host: " + host + "\r\n"
                + "Connection: Upgrade\r\n" + "Upgrade: WebSocket\r\n" + "Sec-WebSocket-Version: 13\r\n"
                + "Sec-WebSocket-Key: 9 9 9 9\r\n" + "Sec-WebSocket-Protocol: sample\r\n";
        if (headers != null) {
            handshake += headers;
        }
        handshake += "\r\n";
        os.write(handshake.getBytes());
        return true;
    } catch (Exception e) {
        System.err.println(e);
        //e.printStackTrace();
        return false;
    }
}

From source file:edu.syr.bytecast.githubcampfire.CampfirePost.java

public CampfirePostReply post(String message) {
    //see: http://stackoverflow.com/questions/2603691/android-httpclient-and-https
    try {/*from ww w. ja  va2 s .  co m*/
        String xml_message = "<message><type>TextMessage</type><body>" + message + "</body></message>";

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

        BasicSchemeFactory factory = new BasicSchemeFactory();

        HttpParams params = new BasicHttpParams();
        params.setParameter("realm", "https://trifort.campfirenow.com/");

        SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);
        String url = "https://trifort.campfirenow.com/room/" + m_room + "/speak.xml";
        HttpPost post = new HttpPost(url);
        post.setHeader("Content-type", "application/xml");

        AuthScheme scheme = factory.newInstance(params);
        Header header = scheme.authenticate(new UsernamePasswordCredentials(m_apiKey), post);

        HttpEntity entity = new StringEntity(xml_message);
        post.setEntity(entity);
        post.setHeader(header);
        HttpResponse response = client.execute(post);

        return new CampfirePostReply(response);
    } catch (Exception ex) {//post.setEntity;
        ex.printStackTrace();
        return null;
    }
}