4 package org.opendaylight.mwtn.dcaeConnector.test;
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
10 import java.net.URLConnection;
11 import java.security.cert.X509Certificate;
13 import javax.net.ssl.HostnameVerifier;
14 import javax.net.ssl.HttpsURLConnection;
15 import javax.net.ssl.SSLContext;
16 import javax.net.ssl.TrustManager;
17 import javax.net.ssl.X509TrustManager;
23 public class DcaePrivateTester {
26 public static void test(URL url, boolean readFromServer) throws Exception {
27 // Create a trust manager that does not validate certificate chains
28 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
30 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
34 public void checkClientTrusted(X509Certificate[] certs, String authType) {
37 public void checkServerTrusted(X509Certificate[] certs, String authType) {
40 // Install the all-trusting trust manager
41 final SSLContext sc = SSLContext.getInstance("TLS");
42 sc.init(null, trustAllCerts, new java.security.SecureRandom());
43 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
44 // Create all-trusting host name verifier
45 HostnameVerifier allHostsValid = (hostname, session) -> true;
47 // Install the all-trusting host verifier
48 HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
50 //URL url = new URL("https://www.google.com");
51 URLConnection con = url.openConnection();
52 System.out.println("Connection background: "+con.getClass().getName()+" "+url.getHost());
55 final Reader reader = new InputStreamReader(con.getInputStream());
56 final BufferedReader br = new BufferedReader(reader);
58 while ((line = br.readLine()) != null) {
59 System.out.println(line);
67 // httpTestUrl=https://plan.fritz.box:9092/ux/#
68 // keyStore=etc/clientkeystore
69 // keyStorePassword=daylight2016
70 public static void main(String[] args) {
72 String urlString = "https://www.google.de";
73 //String urlString = "https://plan.fritz.box:9092/ux/#";
74 //String urlString = "http://plan.fritz.box:9091/ux/#";
75 //String urlString = "http://127.0.0.1:30000/eventListener/v3";
78 test(new URL(urlString), true);
79 } catch (Exception e) {
80 System.out.println("(..something..) failed");
84 System.out.println("Test HTTPS");
86 final HttpsClient httpTestClient;
87 httpTestClient = new HttpsClient();
89 httpTestClient.testIt(
90 //"https://plan.fritz.box:9092/ux/#",
91 "https://www.google.de",
92 "/home/herbert/odl/distribution-karaf-0.5.1-Boron-SR1/etc/clientkeystore",