private static SSLSocketFactory getSocketFactory(File trustStore) throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException {
        KeyStore keystore = KeyStore.getInstance("JKS");

        InputStream truststoreInputStream = null;
        try {
            truststoreInputStream = new FileInputStream(trustStore);
            keystore.load(truststoreInputStream, KEYSTORE_PW);
        } finally {
            if (truststoreInputStream != null) {
                truststoreInputStream.close();
            }
        }

        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
        trustManagerFactory.init(keystore);
        TrustManager[] trustMangers = trustManagerFactory.getTrustManagers();

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustMangers, null);

        SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
        return sslSocketFactory;
    }
private static SSLSocketFactory getSocketFactory ( File trustStore ) throws KeyStoreException , FileNotFoundException , IOException , NoSuchAlgorithmException , CertificateException , KeyManagementException { KeyStore keystore = KeyStore . getInstance ( "JKS" ) ; InputStream truststoreInputStream = null ; try { truststoreInputStream = new FileInputStream ( trustStore ) ; keystore . load ( truststoreInputStream , KEYSTORE_PW ) ; } finally { if ( truststoreInputStream != null ) { truststoreInputStream . close ( ) ; } } TrustManagerFactory trustManagerFactory = TrustManagerFactory . getInstance ( "PKIX" ) ; trustManagerFactory . init ( keystore ) ; TrustManager [ ] trustMangers = trustManagerFactory . getTrustManagers ( ) ; SSLContext sslContext = SSLContext . getInstance ( "TLS" ) ; sslContext . init ( null , trustMangers , null ) ; SSLSocketFactory sslSocketFactory = sslContext . getSocketFactory ( ) ; return sslSocketFactory ; }
Returns an SSLSocketFactory needed to connect to an SSL mongo server. The socket factory is created using the testTruststore.jks.

@return
@throws KeyStoreException
@throws FileNotFoundException
@throws IOException
@throws NoSuchAlgorithmException
@throws CertificateException
@throws KeyManagementException