title: Connecting to MongoDb with SSL from JAVA app
body: <p>I have a <code>MongoDb</code> instance running(single instance) with <code>SSL</code> enabled. I am able to connect to it with <code>RoboMongo</code> where on <code>SSL</code> tab I provide the following :</p>
  
  <pre><code>CA File : /path to my certificate/testCA.pem 
  PEM certificate/key: /path to my key/testKey.pem
  </code></pre>
  
  <p>Which successfully connects. Now I'm trying to connect to the same mondodb from java app. I imported the testCA.pem into cacerts using the following command:</p>
  
  <pre><code>keytool -import -keystore cacerts -file testCA.pem -storepass changeit
  </code></pre>
  
  <p>and I can see a new entry added to the store. Tried to add the other key into it and it says invalid certificate. On the Java app I set system property as following:</p>
  
  <pre><code>System.setProperty ("javax.net.ssl.trustStore","C:\\Program Files\\Java\\jre1.8.0_91\\lib\\security\\cacerts");
  System.setProperty ("javax.net.ssl.trustStorePassword","changeit");
  </code></pre>
  
  <p>and I'm getting the following error:</p>
  
  <pre><code>org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=test.mongo.com:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.io.EOFException}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=test.mongo.com:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.io.EOFException}}]
      at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:75)
      at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2075)
      at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1918)
  </code></pre>
  
  <p>What am I missing here, thanks in advance!</p>