[JAVA-2792] Server Connection Created: 26/Feb/18  Updated: 11/Sep/19  Resolved: 01/Mar/18

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: pritam dhuri Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-1958 SCRAM-SHA1 authentication is not avai... Closed

 Description   

I trying to connect server but I am getting this error

Error
_com.mongodb.MongoTimeoutException:
Timed out after 3000 ms while waiting to connect. Client view of cluster state is
{type=UNKNOWN,
servers=[{
address=<server_address>:27017,
type=UNKNOWN,
state=CONNECTING,
exception=

{ com.mongodb.MongoException: java.lang.NoClassDefFoundError: com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient }

,
caused by

{java.lang.NoClassDefFoundError: com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient}

}]_

This is my Code:
_MongoClientOptions.Builder o = MongoClientOptions.builder().serverSelectionTimeout(3000);
MongoCredential credential = MongoCredential.createCredential("admin", "<database_name>","admin".toCharArray());

// Creating a Mongo client
MongoClient mongo = new MongoClient( new ServerAddress("<server_address>" , 27017),credential,o.build());

System.out.println("Connected to the database successfully ");

// Accessing the database
MongoDatabase database = mongo.getDatabase("<database_name>");
System.out.println("Collection created successfully");
// Retrieving a collection
MongoCollection<Document> collection = database.getCollection("<collection_name>");
System.out.println("Collection sampleCollection selected successfully ");

//Getting the iterable object
FindIterable<Document> iterDoc = collection.find();
int i = 1;

String s = null;
// Getting the iterator
Iterator it = null;
try {
it = iterDoc.iterator();
while (it.hasNext())

{ System.out.println(it.next()); s+=it.next().toString(); i++; }

} catch (Exception e)

{ e.printStackTrace(); Log.i("TAG",""+e); }

return s;_



 Comments   
Comment by Ross Lawley [ 01/Mar/18 ]

Thanks pritam@affwl.com - that makes more sense now - due to the limitations of Android JRE the classes aren't available to support Scram Sha 1 authentication. Currently, there are no plans to support this, so I'm closing the ticket as Won't Fix.

Comment by pritam dhuri [ 01/Mar/18 ]

Hi Ross Lawley..
Thanks for your response, but I am still facing issues while connection to my android app..

Error Message
com.mongodb.MongoTimeoutException: Timed out after 3000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=<server_name>, type=UNKNOWN, state=CONNECTING, exception=

{com.mongodb.MongoException: java.lang.NoClassDefFoundError: com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient}

, caused by {java.lang.NoClassDefFoundError: com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient}}]

Comment by Ross Lawley [ 27/Feb/18 ]

Hi pritam@affwl.com,

The java.lang.NoClassDefFoundError: com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient error points to an incorrectly setup Mongo Java Driver.

Please check the class path and ensure you have all the dependencies installed - crucial if downloading the jars manually and not using the uber jar. Please see the installation guide for more information.

Just for future reference the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support.

All the best,

Ross

Generated at Thu Feb 08 08:58:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.