code: public static synchronized void setupSslVerification(String host) throws Exception {
          if (sslVerificationHosts == null)
              sslVerificationHosts = new ArrayList<String>();
  
          if (!sslVerificationHosts.contains(host)) {
  
              TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
              // initialize tmf with the default trust store
              tmf.init((KeyStore)null);
  
              // get the default trust manager
              X509TrustManager defaultTm = null;
              for (TrustManager tm : tmf.getTrustManagers()) {
                  if (tm instanceof X509TrustManager) {
                      defaultTm = (X509TrustManager) tm;
                      break;
                  }
              }
  
              TrustManager[] trustManager = new TrustManager[] { new BlindTrustManager(defaultTm, host) };
              SSLContext sc = SSLContext.getInstance("SSL");
              sc.init(null, trustManager, new java.security.SecureRandom());
              HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  
              HostnameVerifier defaultHv = HttpsURLConnection.getDefaultHostnameVerifier();
              HostnameVerifier hostnameVerifier = new DesignatedHostnameVerifier(defaultHv, host);
              HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
  
              sslVerificationHosts.add(host);
          }
      }
docs: Idempotent.