Code example for SSLSocketFactory

Methods: setHostnameVerifier

0
 
        try { 
            try { 
                SSLContext sslcontext = SSLContext.getInstance("TLS");
                sslcontext.init(new KeyManager[0], new TrustManager[] { TRUST_EVEYONE_MANAGER }, new SecureRandom());
                SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslcontext);
                sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
            } catch (NoSuchMethodError e) {
                /* fallback to use custom AndroidSSLSocketFactory */ 
                logger.warn(e.getMessage());
                logger.warn("try android ssl socket factory: " + com.google.jplurk.net.AndroidSSLSocketFactory.class);
                com.google.jplurk.net.AndroidSSLSocketFactory androidSSLSocketFactory = new com.google.jplurk.net.AndroidSSLSocketFactory((KeyStore)null);
                androidSSLSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                schemeRegistry.register(new Scheme("https", androidSSLSocketFactory, 443));
            } 
            
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }