Error connecting JMX caused by SSLHandshakeException
<p>I am a newbie to JMX. I need to create a custom JMX client that would connect to remote server and read data from mbeans.</p>

<p>Here is the app code that I have so far:</p>

<pre><code>String url = "service:jmx:rmi:///jndi/rmi://host:port/jmxrmi";
JMXServiceURL serviceURL = new JMXServiceURL(url);
Map env = new HashMap();
String[] creds = { "role", "password" };
env.put(JMXConnector.CREDENTIALS, creds);
JMXConnector cc = JMXConnectorFactory.connect(serviceURL, env);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
</code></pre>

<p>When I launch my app I get following error (modified to add full stack trace):</p>

<pre><code>Exception in thread "main" java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:304)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:308)
    at Main.main(Main.java:21)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
    at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2430)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
 Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.DataOutputStream.flush(DataOutputStream.java:123)
    ... 9 more
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:229)
 Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
    at sun.security.validator.Validator.validate(Validator.java:260)
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
    ... 20 more
    at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
    ... 26 more
 Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
</code></pre>

<p>Any help would be appreciated.</p>