We used wso2 esb (version 4.0.3) to publish our web service. Our web service was added as a proxy service using the admin console in wso2. We want to expose / consume our web service only using https. After creating the stub, we did the following
- Create a jks file using java keytool.
- The wso2 certificate is exported and imported into the jks file.
- When adding the following web service, the following is added in the code.
System.setProperty ("javax.net.ssl.trustStore", "filename"); System.setProperty ("javax.net.ssl.trustStorePassword", "password");
Doing all this when we try to call a web service from java code, it only works when the URL is set using localhost. It does not work with 127.0.0.1 or the IP address of the computer, although we do have the correct mapping in the host file. When using the ip address, we get an error like javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
. This error occurs because the default certificate provided by wso2 has "localhost" as the common name. We can get rid of this problem by adding the following code snippet
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String string, SSLSession ssls) { return true; }});
But this can lead to security problems. Please suggest us how to solve this problem.
source share