Connection timeout when connecting to mongo db through groovy script through open source soap ui
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:port/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.Solved16KViews0likes1CommentRetreiving data from Mongo db using Groovy and assigning it to a test case property
Hi, I'm looking to create a test step that can connect toMongoDB, run a query, and then assign the result to a test case property. I have the connection working and I can retrieve a result as a row count. However I cannot get the actual result to assign it to a test case property. I know how to assign a value to a test case property but simply cannot get the result in order to do that. Below is my existing code. I'm connecting to a MongoDB called database called 'digital', within that there is a collection called 'QuoteSummary'. Within 'QuoteSummary' I'm searching for a "quoteRefNo" where "workReferenceNo" = GPE0024879. Its the resulting "quoteRefNo" that I want to assign to a test case property. import com.gmongo.GMongoClient import com.mongodb.MongoCredential import com.mongodb.ServerAddress import com.mongodb.BasicDBObject def credentials = MongoCredential.createCredential('hidden_user', 'digital', 'hidden_pwsd' as char[]) def serverAddress = new ServerAddress('hidden_servername_and_port') def mongo = new GMongoClient(serverAddress, [credentials]) def db = mongo.getDB('digital') BasicDBObject query = new BasicDBObject("workReferenceNo":"GPE0024879") BasicDBObject query1 = new BasicDBObject(quoteRefNo: 1,_id: 0) def collection = db.getCollection('QuoteSummary') //log.info(collection.find(query).count()) log.info(collection.find((query),(query1)).count())Solved10KViews0likes5CommentsHow 'find' command to be used to fetch results from mongoDB using groovy in soap ui
Below is the groovy code snippet I have written. DB db = mongoClient.getDB( "qahmedb" ); DBCollection coll = db.getCollection("Hotel"); log.info "Collection Hotel selected successfully" DBCursorcursor = coll.find({City_en : 'Orlando' }); List list1 = new ArrayList(); while( cursor.hasNext() ) { def hotel = cursor.next() log.info "Found Hotels with ID $hotel._id and name $hotel.Title_en" } It is leading to error message as "ERROR:An error occurred [Cannot cast object 'DBCollection{database=DB{name='qahmedb'}, name='Hotel'}' with class 'com.mongodb.DBCollection' to class 'com.mongodb.DBCursor'], see error log for details" While if I am using direct find query without any condition likeDBCursorcursor = coll.find(); It gave results successfully without any error. Kindly help with the possible solutions. Thanks Deepali3.4KViews0likes7CommentsMongo Context varibale - Is it possible to use it throughout the test suite
Greetings, While working with MondoDB using gmongo (groovy wrapper), we open connection using mongoDB context, something like this: def mongoClient = new MongoClient( new ServerAddress(dbServer), Arrays.asList(credentials) ) context.gmongo = new GMongo( mongoClient ) context.mongoDB = context.gmongo.getDB(dbDatabase) In my current framework, I open connection and close it everytime I need to do something with mongodb. I am trying to somehow define the context once globally and use the variable to access mongodb throughout the test suite. Is there any way to do it ? Any help would be much appreciated.Solved3KViews0likes8Comments