0

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)

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84

1 Answers1

0

I was looking in to your issue, after looking at this link: https://www.ibm.com/support/knowledgecenter/en/SS9J9E/ioc/ts_liberty_ip.html

I Think your DNS records are not correct, which states: you are trying to perform a SSL handshake with an URL which does not exist.

Could you reach the URL in your browser or using Curl?

If this is not the case, then I think the CN (Common Name) of your cerificate is not matching the domain of the url you are connecting to

Dilyano Senders
  • 199
  • 1
  • 9