package org.springframework.integration.samples.rest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class HttpsTest {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.keyStore","/azizkhani/keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "pass");
// full log for debugging
System.setProperty("javax.net.debug", "all");
try {
try {
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
if (hostname.equals("ansarrootca")) {
return true;
}
return false;
}
});
URL url = new URL("https://site:3443");
InputStream is = url.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String inputLine = null;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}