MongoDB Atlas Issue Connecting with Java

Hi All,

I have created an account on MongoDB Atlas and tried connecting to MongoDB Atlas Cluster using the Java code.

With the same java code I am able to connect to On-Premise MongoDB but not the Atlas Cluster.

INFO: Exception in monitor thread while connecting to server ssc-cluster-01-shard-00-02.9cbnp.mongodb.net:27017
com.mongodb.MongoSocketWriteException: Exception sending message
	at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:525)
	at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:413)
	at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:269)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:253)
	at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83)
	at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:106)
	at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address 13.235.32.72 

Hi @Samir_Benjamin,

I think you are hitting a known issue where atlas CA certificate is not present in your jdk certificate trust store:
https://docs.atlas.mongodb.com/reference/faq/security/#hard-coded-certificate-authority

Please download the certificate from the link above and import it with keytool command to your trust store.

Best
Pavel

I think I had this issue when I was using the Oracle SDK but I solve this issue by using the OpenJDK instead.