Example usage for org.apache.http.conn ClientConnectionManager getSchemeRegistry

List of usage examples for org.apache.http.conn ClientConnectionManager getSchemeRegistry

Introduction

In this page you can find the example usage for org.apache.http.conn ClientConnectionManager getSchemeRegistry.

Prototype

SchemeRegistry getSchemeRegistry();

Source Link

Document

Obtains the scheme registry used by this manager.

Usage

From source file:net.bither.image.http.BaseHttpResponse.java

private DefaultHttpClient getThreadSafeHttpClient() {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    ClientConnectionManager mgr = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HttpSetting.HTTP_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HttpSetting.HTTP_SO_TIMEOUT);
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()),
            params);/*w w  w.j a  va2  s.  c  om*/

    return httpClient;
}

From source file:uk.ac.brighton.ci360.bigarrow.PlacesAPISearch.java

@SuppressWarnings("unused")
private HttpClient sslClient(HttpClient client) {
    try {//from www.  j  a  v a 2 s.co m
        X509TrustManager tm = new X509TrustManager() {
            public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, new TrustManager[] { tm }, null);
        SSLSocketFactory ssf = new MySSLSocketFactory(ctx);
        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        ClientConnectionManager ccm = client.getConnectionManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        sr.register(new Scheme("https", ssf, 443));
        return new DefaultHttpClient(ccm, client.getParams());
    } catch (Exception ex) {
        return null;
    }
}

From source file:ilarkesto.net.ApacheHttpDownloader.java

private HttpClient wrapClientForDisabledServerChecking(HttpClient client) {
    try {//from  w  w  w  .j av a 2  s.  c o  m
        X509TrustManager tm = new X509TrustManager() {

            @Override
            public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, new TrustManager[] { tm }, null);
        SSLSocketFactory ssf = new UnsecureSSLSocketFactory(ctx);
        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        ClientConnectionManager ccm = client.getConnectionManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        sr.register(new Scheme("https", ssf, 443));
        return new DefaultHttpClient(ccm, client.getParams());
    } catch (Exception ex) {
        return null;
    }
}

From source file:net.bither.http.BaseHttpResponse.java

private DefaultHttpClient getThreadSafeHttpClient() {
    if (getHttpType() == HttpType.BitherApi) {
        PersistentCookieStore persistentCookieStore = PersistentCookieStore.getInstance();
        if (persistentCookieStore.getCookies() == null || persistentCookieStore.getCookies().size() == 0) {
            CookieFactory.initCookie();//from  www.  ja v a 2  s. c o m
        }
    }
    DefaultHttpClient httpClient = new DefaultHttpClient();
    ClientConnectionManager mgr = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HttpSetting.HTTP_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HttpSetting.HTTP_SO_TIMEOUT);
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()),
            params);
    setCookieStore(httpClient);
    return httpClient;
}

From source file:org.fedoraproject.eclipse.packager.api.UploadSourceCommand.java

/**
 * Wrap a basic HttpClient object in a Fedora SSL enabled HttpClient (which includes
 * Fedora SSL authentication cert) object.
 * /*  w ww .  j  a  v  a  2s .  c  o m*/
 * @param base The HttpClient to wrap.
 * @return The SSL wrapped HttpClient.
 * @throws GeneralSecurityException
 * @throws IOException
 */
private HttpClient fedoraSslEnable(HttpClient base)
        throws GeneralSecurityException, FileNotFoundException, IOException {

    // Get a SSL related instance for setting up SSL connections.
    FedoraSSL fedoraSSL = FedoraSSLFactory.getInstance();
    SSLSocketFactory sf = new SSLSocketFactory(fedoraSSL.getInitializedSSLContext(), // may throw FileNotFoundE
            SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm = base.getConnectionManager();
    SchemeRegistry sr = ccm.getSchemeRegistry();
    Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$
    sr.register(https);
    return new DefaultHttpClient(ccm, base.getParams());
}

From source file:org.fedoraproject.eclipse.packager.api.UploadSourceCommand.java

/**
 * Wrap a basic HttpClient object in an all trusting SSL enabled
 * HttpClient object.//  w w  w .j  a  va2s.c om
 * 
 * @param base The HttpClient to wrap.
 * @return The SSL wrapped HttpClient.
 * @throws GeneralSecurityException
 * @throws IOException
 */
private HttpClient trustAllSslEnable(HttpClient base) throws GeneralSecurityException {
    // Get an initialized SSL context
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        @Override
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        @Override
        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }

        @Override
        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }
    } };

    // set up the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("SSL"); //$NON-NLS-1$
    sc.init(null, trustAllCerts, new java.security.SecureRandom());

    SSLSocketFactory sf = new SSLSocketFactory(sc, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm = base.getConnectionManager();
    SchemeRegistry sr = ccm.getSchemeRegistry();
    Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$
    sr.register(https);
    return new DefaultHttpClient(ccm, base.getParams());
}

From source file:com.gorillalogic.monkeytalk.ant.RunTask.java

private String sendFormPost(String url, File proj, Map<String, String> additionalParams) throws IOException {

    HttpClient base = new DefaultHttpClient();
    SSLContext ctx = null;/*from  ww w  .  ja va  2 s . c  om*/

    try {
        ctx = SSLContext.getInstance("TLS");
    } catch (NoSuchAlgorithmException ex) {
        log("exception in sendFormPost():");
    }

    X509TrustManager tm = new X509TrustManager() {
        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        @Override
        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
                throws java.security.cert.CertificateException {
        }

        @Override
        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType)
                throws java.security.cert.CertificateException {
        }
    };

    try {
        ctx.init(null, new TrustManager[] { tm }, null);
    } catch (KeyManagementException ex) {
        log("exception in sendFormPost():");
    }

    SSLSocketFactory ssf = new SSLSocketFactory(ctx);
    ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm = base.getConnectionManager();
    SchemeRegistry sr = ccm.getSchemeRegistry();
    sr.register(new Scheme("https", ssf, 443));

    HttpClient client = new DefaultHttpClient(ccm, base.getParams());
    try {
        HttpPost post = new HttpPost(url);

        MultipartEntity multipart = new MultipartEntity();
        for (String key : additionalParams.keySet())
            multipart.addPart(key, new StringBody(additionalParams.get(key), Charset.forName("UTF-8")));

        if (proj != null) {
            multipart.addPart("uploaded_file", new FileBody(proj));
        }

        post.setEntity(multipart);

        HttpResponse resp = client.execute(post);

        HttpEntity out = resp.getEntity();

        InputStream in = out.getContent();
        return FileUtils.readStream(in);
    } catch (Exception ex) {
        throw new IOException("POST failed", ex);
    } finally {
        try {
            client.getConnectionManager().shutdown();
        } catch (Exception ex) {
            // ignore
        }
    }
}

From source file:com.ibm.watson.developer_cloud.service.WatsonService.java

/**
 * Gets the thread safe client.//w  w w  .  j a  v a2 s . c  om
 * 
 * @return the thread safe client
 */
private HttpClient getThreadSafeClient() {

    DefaultHttpClient client = new DefaultHttpClient(getDefaultRequestParams());
    ClientConnectionManager mgr = client.getConnectionManager();
    HttpParams params = client.getParams();

    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);

    return client;
}