private String httpsQuery ( ) { String response = null ; try { // Create a trust manager that does not validate certificate chains TrustManager [ ] trustAllCerts = new TrustManager [ ] { new LocalX509TrustManager ( ) } ; // Install the all-trusting trust manager final SSLContext sc = SSLContext . getInstance ( "SSL" ) ; sc . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( sc . getSocketFactory ( ) ) ; // Create all-trusting host name verifier HostnameVerifier allHostsValid = new LocalHostnameVerifier ( ) ; HttpsURLConnection . setDefaultHostnameVerifier ( allHostsValid ) ; URL restUrl = new URL ( this . url ) ; HttpsURLConnection conn = ( HttpsURLConnection ) restUrl . openConnection ( ) ; response = query ( conn ) ; } catch ( Exception e ) { this . logger . severe ( "Cannot issue GET on URL " + this . url + ". Monitoring notification is discarded." ) ; Utils . logException ( this . logger , e ) ; } return response ; }
Query a https URL ignoring certificates .