skip to Main Content

com.mongodb.MongoSocketWriteException: Exception sending message

Caused by: javax.net.ssl.SSLException: Received fatal alert:
internal_error

While trying to connect mongodb using Springboot getting error

MongoSocketWriteExcepption caused by javax.net.ssl.sslexception

2

Answers


  1. If you are connecting to atlas cluster on cloud, you can take a look at your ip address again, if your current ip address is added to the access list under Network Access option. So, on Atlas home page, in left bar, you will see Security –> network access –> ip access list –> Add current ip address.

    Hope it helps!!

    Login or Signup to reply.
  2. Make sure you are importing the provided .pem file to your JRE cacerts which is a certificate provided by MongoDB server.

    The certificate need to be imported to ${java_home}/jre/lib/security/cacerts

    using the command keytool -import -trustcacerts -file testCA.pem -keystore cacerts -storepass "changeit"

    Also, make sure you are using right JRE while executing your code where the .pem certificate was exported.

      //Following properties sets required ssl settings while executing the code.
    
      System.setProperty ("javax.net.ssl.trustStore",JAVA_HOME + "\lib\security\cacerts");
      System.setProperty ("javax.net.ssl.trustStorePassword","changeit");
    
    //Create SSL context
    SslContext sslContext = SslContextBuilder.forClient()
        .sslProvider(SslProvider.OPENSSL)
        .build();
    
    //Apply SSL settings
    MongoClientSettings settings = MongoClientSettings.builder()
        .applyToSslSettings(builder -> builder.enabled(true))
        .streamFactoryFactory(NettyStreamFactoryFactory.builder()
                .sslContext(sslContext)
                .build()).build();
    
    //Create MongoClient using ssl settings
    MongoClient client = MongoClients.create(settings);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search