I'm trying to execute the below lines of code:
public static String invokeRestService(String request) throws Exception {
try {
URL url = new URL("https://XXXXXXX:8403/v1/payment/test/req");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setDoOutput(true);
OutputStreamWriter osw = new OutputStreamWriter(urlConnection.getOutputStream());
osw.write(request);
osw.flush();
osw.close();
System.out.println(urlConnection.getResponseCode());
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
Whenever I tried to run the above code I observed the below error message and It says that SSL failed but When I tried to hit the same endpoint URL through postman without any authorization header it works as expected and return 200 response code as expected. I'm facing this exception when I tried to hit that endpoint through JAVA code. Is there anyway to setup the SSL explicit ? or How can I use the system default SSL?
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)