public static void trustAllHosts ( ) { // Create a trust manager that does not validate certificate chains TrustManager [ ] trustAllCerts = new TrustManager [ ] { new X509TrustManager ( ) { public X509Certificate [ ] getAcceptedIssuers ( ) { return new X509Certificate [ ] { } ; } public void checkClientTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } public void checkServerTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } } } ; // Install the all-trusting trust manager try { SSLContext sslContext = SSLContext . getInstance ( "TLS" ) ; sslContext . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( sslContext . getSocketFactory ( ) ) ; HttpsURLConnection . setDefaultHostnameVerifier ( ( String var1 , SSLSession var2 ) -> { return true ; } ) ; } catch ( Exception exception ) { log . error ( exception ) ; } }
Sometimes a remote source is self - signed or not otherwise trusted