{"action":"created","issue":{"url":"https://api.github.com/repos/eugenp/tutorials/issues/329","labels_url":"https://api.github.com/repos/eugenp/tutorials/issues/329/labels{/name}","comments_url":"https://api.github.com/repos/eugenp/tutorials/issues/329/comments","events_url":"https://api.github.com/repos/eugenp/tutorials/issues/329/events","html_url":"https://github.com/eugenp/tutorials/issues/329","id":125841035,"number":329,"title":"How to allow connection SSL Sites without cert - insure way using RestTemplate?","user":{"login":"JavaHelper","id":8208031,"avatar_url":"https://avatars.githubusercontent.com/u/8208031?v=3","gravatar_id":"","url":"https://api.github.com/users/JavaHelper","html_url":"https://github.com/JavaHelper","followers_url":"https://api.github.com/users/JavaHelper/followers","following_url":"https://api.github.com/users/JavaHelper/following{/other_user}","gists_url":"https://api.github.com/users/JavaHelper/gists{/gist_id}","starred_url":"https://api.github.com/users/JavaHelper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JavaHelper/subscriptions","organizations_url":"https://api.github.com/users/JavaHelper/orgs","repos_url":"https://api.github.com/users/JavaHelper/repos","events_url":"https://api.github.com/users/JavaHelper/events{/privacy}","received_events_url":"https://api.github.com/users/JavaHelper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-10T19:52:26Z","updated_at":"2016-01-17T19:58:22Z","closed_at":null,"body":"Could you please guide on this issue http://stackoverflow.com/questions/34705126/get-request-gives-connection-refused ?\r\n"},"comment":{"url":"https://api.github.com/repos/eugenp/tutorials/issues/comments/172371861","html_url":"https://github.com/eugenp/tutorials/issues/329#issuecomment-172371861","issue_url":"https://api.github.com/repos/eugenp/tutorials/issues/329","id":172371861,"user":{"login":"JavaHelper","id":8208031,"avatar_url":"https://avatars.githubusercontent.com/u/8208031?v=3","gravatar_id":"","url":"https://api.github.com/users/JavaHelper","html_url":"https://github.com/JavaHelper","followers_url":"https://api.github.com/users/JavaHelper/followers","following_url":"https://api.github.com/users/JavaHelper/following{/other_user}","gists_url":"https://api.github.com/users/JavaHelper/gists{/gist_id}","starred_url":"https://api.github.com/users/JavaHelper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JavaHelper/subscriptions","organizations_url":"https://api.github.com/users/JavaHelper/orgs","repos_url":"https://api.github.com/users/JavaHelper/repos","events_url":"https://api.github.com/users/JavaHelper/events{/privacy}","received_events_url":"https://api.github.com/users/JavaHelper/received_events","type":"User","site_admin":false},"created_at":"2016-01-17T19:58:22Z","updated_at":"2016-01-17T19:58:22Z","body":"Please close this ticket. Sorry for inconvenience. Probably you won't see any further tickets here. \r\n\r\nJust for your knowledge. We can connect to the SSL protected site by insure way by allowing connections to SSL sites without certs. Below code works'\r\n\r\n```\r\nstatic {\r\n        disableSslVerification();\r\n    }\r\n\r\n    private static void disableSslVerification() {\r\n        try{\r\n            // Create a trust manager that does not validate certificate chains\r\n            TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {\r\n                public X509Certificate[] getAcceptedIssuers() {\r\n                    return null;\r\n                }\r\n                public void checkClientTrusted(X509Certificate[] certs, String authType) {\r\n                }\r\n                public void checkServerTrusted(X509Certificate[] certs, String authType) {\r\n                }\r\n            }\r\n            };\r\n\r\n            // Install the all-trusting trust manager\r\n            SSLContext sc = SSLContext.getInstance(\"SSL\");\r\n            sc.init(null, trustAllCerts, new java.security.SecureRandom());\r\n            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());\r\n\r\n            // Create all-trusting host name verifier\r\n            HostnameVerifier allHostsValid = new HostnameVerifier() {\r\n                public boolean verify(String hostname, SSLSession session) {\r\n                    return true;\r\n                }\r\n            };\r\n\r\n            // Install the all-trusting host verifier\r\n            HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);\r\n        } catch (NoSuchAlgorithmException e) {\r\n            e.printStackTrace();\r\n        } catch (KeyManagementException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n\r\n    public static void main(String[] args) {\r\n        HttpHeaders headers = new HttpHeaders();\r\n        headers.add(\"Accept\", \"application/json\");\r\n        headers.add(\"Content-Type\", MediaType.APPLICATION_FORM_URLENCODED.toString());\r\n        headers.add(\"Authorization\", \"Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXX\");\r\n\r\n        String url = \"https://XXXXXXXXXXXXX:8243/token\";\r\n\r\n        String dataJSON = \"grant_type=password&username=admin&password=admin\";\r\n\r\n        RestTemplate restTemplate = new RestTemplate();\r\n        HttpEntity<String> entity = new HttpEntity<String>(dataJSON,headers);\r\n        HttpEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);\r\n        System.out.println(\"O/P : \"+response.getBody());\r\n    }\r\n```"}}