I have been trying to connect to mongodb using the following groovy script through open source soap UI.
I have already plaved gmongo 1.5 jar and mongo java driver jar 3.10.1 in soap ui lib folder.
I use soap ui 5.3.0 version. Mongo db version is 3.6
I have added SSL settings in preferences, included truststore file.
-------------------------------------------------------------------------------------
import com.gmongo.GMongo
import com.mongodb.BasicDBObject
import com.mongodb.DB
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import com.mongodb.*
import com.mongodb.MongoException
def javaMongo = new MongoClient(new MongoClientURI("mongodb://<username>:<password>@server
ort/env?ssl=true&replicaSet=XXX"))
def db = javaMongo.getDB('XXX')
def table = db.getCollection("XXX");
def query = new BasicDBObject("XXX", "XX")
def cursor = table.find(query)
try {
while(cursor.hasNext()) {
log.info cursor.next()
}
} finally {
cursor.close()
}
--------------------------------------------------------------------------------
But I get the following error :
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@7ff24094. Client view of cluster state is {type=REPLICA_SET, servers=[{address=XXX:XXX, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address XXXXX found}, caused by {java.security.cert.CertificateException: No subject alternative names matching IP address XXXXXX found}}] error at line: 25
I have tried using this script as well:
------------------------------------------------------------------
@Grab('com.gmongo:gmongo:1.5')
import com.gmongo.GMongoClient
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress
import com.mongodb.BasicDBObject
import com.mongodb.*
ENV = 'XXX'
def global_config = [
stage: [ database: 'XXX', username: 'XXXX', password: 'XXXX', server: 'XXXX', port: XXX ]
]
def config = global_config[ENV];
def credential = MongoCredential.createMongoCRCredential(config.username, config.database, config.password as char[])
def mongo = new GMongoClient(new ServerAddress(config.server, config.port), [ credential ])
def db = mongo.getDB(config.database)
log.info db
def collection1 = db.getCollection("XXXXX")
log.info collection1.find().first()
--------------------------------------------------------------------
This gives me the following exception:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=XXXX:XX, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Connection reset}}] error at line: 31
Have also included changes in testrunner.bat file:
set java_opts=%java_opts% -dsoapui.https.protocols=TLSv1,TLSv1.2,SSLv3
set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.browser.disabled="true"
Added this in vmoptions file:
-Dsoapui.https.protocols=SSLv3,TLSv1.2
-Dsun.security.ssl.allowUnsafeRenegotiation=true
Also imported truststore file in the project level, WS-Security Configurations tab.
Inspite of all these changes, I see the connection issue.
Please help me in resolving the errors and help in connecting to the db.