Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1585

Trying to move Mongodb from HTTP to HTTPS and getting - com.mongodb.MongoSocketReadException: Prematurely reached end of stream error

$
0
0

I am Trying to move Mongodb from HTTP to HTTPS soI have changed mongod.conf file

net:port: 27017  bindIp: <required host names>  tls:    mode: requireTLS    certificateKeyFile: /path/mongodb.pem    CAFile: /path/mongodb.pemsecurity: authorization: "enabled"

**The command to connect with mongodb is **mongo --tls --tlsCertificateKeyFile path/mongodb.pem --tlsCAFile path/mongodb.pem --host <host_name> --port <port> -u <username> -p <password> --authenticationDatabase <database_name>

Code level changes:

String connectionString = String.format(        String connectionString = String.format("mongodb://%s:%s@%s:%s/%s?tls=true&tlsCAFile=%s&tlsCertificateKeyFile=%s","mongodb://%s:%s@%s:%s/%s",                username, password, mongoHost, mongoPort, mongoDB, tlsCAFile, tlsCertificateKeyFile                username, password, mongoHost, mongoPort, mongoDB        );

application.properties

spring.data.mongodb.uri=mongodb://<username>:<password>@<host>:<port>/<databasename>?tls=true&tlsCAFile=/path/mongodb.pem&tlsCertificateKeyFile=/path/mongodb.pem&connectTimeoutMS=60000&socketTimeoutMS=60000

But while testing after making these configurations i am getting

"level":"INFO ","exchange":"?","routingKey":"?","message":"No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=:, type=UNKNOWN, state=**********, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]}. Waiting for 30000 ms before timing out","stacktrace":""}

I am able to connect to mongodb both in mongo compass and from terminal, but not from java app. please help me with itWhat might be the possible solution or cause for this issue?


Viewing all articles
Browse latest Browse all 1585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>