To fix it, add a javax.net.ssl.HostnameVerifier() method to override the existing hostname verifier like this :

Before having a look at this issue resolver, go through the tutorial using SSL with jax-ws webservice

import com.roytuts.service.Hello;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
 
public class HelloSSLClient{
 
    static {
        //for localhost testing only
        javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
        new javax.net.ssl.HostnameVerifier(){
 
            public boolean verify(String hostname,
                    javax.net.ssl.SSLSession sslSession) {
                if (hostname.equals("localhost")) {
                    return true;
                }
                return false;
            }
        });
    }
 
    public static void main(String[] args) throws Exception {
 
        URL url = new URL("https://localhost:8443/jax-ws-ssl/hello?wsdl");
        QName qname = new QName("http://service.roytuts.com/",
                "HelloImplService");
        Service service = Service.create(url, qname);
        Hello hello = service.getPort(Hello.class);
        System.out.println(hello.sayHello("Soumitra"));
 
    }
}

Output

Hello Soumitra

 

It’s working fine now.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *