Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEclipse
firstline1
titleWorkaround Code for making HTTPS calls
linenumberstrue
collapsetrue
        final TrustManager[] trustAllCerts = new TrustManager[] {
		  new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new ArrayList<X509Certificate>().toArray(new X509Certificate[0]);
            }

            public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
            }

            public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
            }
          }
        };

        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        final HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(final String hostname, final SSLSession session) {
                return true;
            }
        };

...