Monday, August 13, 2018

HTTPS hostname wrong: should be or org.springframework.web.client.ResourceAccessException

Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://WEBROOT.com:65300/code/service":HTTPS hostname wrong: should be <WEBROOT.com>; nested exception is java.io.IOException: HTTPS hostname wrong: should be <WEBROOT.com>
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:584)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:529)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:447)
at service.UploadRestClient.run(UploadRestClient.java:54)
at service.UploadDocument.main(UploadDocument.java:19)
Caused by: java.io.IOException: HTTPS hostname wrong: should be <WEBROOT.com>
at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.java:612)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:537)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:81)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:568)
... 4 more

Add below code in your java file and run it .Replace
mytargethostname with your domain name which you are trying to access

static {
 

    javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
    new javax.net.ssl.HostnameVerifier(){

        public boolean verify(String |hostname|,
                javax.net.ssl.SSLSession sslSession) {
            if (hostname.equals("mytargethostname")) {
                return true;
            }
            return false;
        }
    });
}

No comments:

Post a Comment

How to check whether operating system is 64 bit or 32bit?

What is 32 and 64 bit operating system? The terms 32-bit and 64-bit refer to the way a computer's processor that is CPU, handles info...