Search code examples
javaspringcitrixxen

Connection to xenserver7.2 from xapi throwing exception security.cert


Connection with Java XenServer API throwing the following Exception

org.apache.xmlrpc.XmlRpcException: Failed to read servers response: java.security.cert.CertificateException: No subject alternative names present
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:150)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at com.xensource.xenapi.Connection.dispatch(Connection.java:330)
at com.xensource.xenapi.Session.loginWithPassword(Session.java:614)
at TestBase.connect(TestBase.java:68)
at TestBase.RunTest(TestBase.java:55)
at RunTests.main(RunTests.java:94)

I do have a XenCenter and root access to XenServer 7.2 and I am also connected through XenCenter and trying to connect to remote xenserver using XenApi from the same system I am connected through xencenter.

Please help the way forward.


Solution

  • I had to use this in when I was making connection with xenserver to accept all certificates

    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    });
    
    connection = new Connection(new URL("https://" +           target.getHostname()));
    
    log.debug(String.format("logging in to '%s'...", target.getHostname()));
    Session.loginWithPassword(connection, target.getUsername(), target.getPassword(), APIVersion.latest().toString());
    log.debug("Success! Session API version is %s", connection.getAPIVersion().toString());