Source:
private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) { MongoConfiguration mongoConf = new MongoConfiguration(cast(parameters)); MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder(); optionsBuilder.connectTimeout(CONNECTION_TIMEOUT); optionsBuilder.serverSelectionTimeout(CONNECTION_TIMEOUT); optionsBuilder.maxWaitTime(CONNECTION_TIMEOUT); MongoClientURI connectionURI = new MongoClientURI(mongoConf.getMongoClientURI(), optionsBuilder); LOG.info("Testing connection against {}", connectionURI); try (MongoClient mongoClient = new MongoClient(connectionURI)) { mongoClient.getDatabase(connectionURI.getDatabase()).runCommand(Document.parse("{ ping: 1 }")); LOG.info("Testing connection successful!"); } catch (MongoSecurityException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription( VerificationError.StandardCode.AUTHENTICATION, String.format("Unable to authenticate %s against %s authentication database!", mongoConf.getUser(), mongoConf.getAdminDB())); builder.error(errorBuilder.build()); } catch (MongoTimeoutException e) { String description = null; VerificationError.StandardCode code = VerificationError.StandardCode.GENERIC; if (e.getMessage().contains("com.mongodb.MongoSecurityException")) { code = VerificationError.StandardCode.AUTHENTICATION; description = String.format("Unable to authenticate %s against %s authentication database!", mongoConf.getUser(), mongoConf.getAdminDB()); } else if (e.getMessage().contains("com.mongodb.MongoSocket") && e.getMessage().contains("Exception")) { description = String.format("Unable to connect to %s!", mongoConf.getHost()); } else { description = String.format("Generic exception while connecting to %s!", mongoConf.getHost()); } ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription( code, String.format(description)); builder.error(errorBuilder.build()); } }

Target:
private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) { ConnectionParamsConfiguration mongoConf = new ConnectionParamsConfiguration(cast(parameters)); MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder(); optionsBuilder.connectTimeout(CONNECTION_TIMEOUT); optionsBuilder.serverSelectionTimeout(CONNECTION_TIMEOUT); optionsBuilder.maxWaitTime(CONNECTION_TIMEOUT); MongoClientURI connectionURI = new MongoClientURI(mongoConf.getMongoClientURI(), optionsBuilder); LOG.info("Testing connection against {}", connectionURI); try (MongoClient mongoClient = new MongoClient(connectionURI)) { mongoClient.getDatabase(connectionURI.getDatabase()).runCommand(Document.parse("{ ping: 1 }")); LOG.info("Testing connection successful!"); } catch (MongoSecurityException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription( VerificationError.StandardCode.AUTHENTICATION, String.format("Unable to authenticate %s against %s authentication database!", mongoConf.getUser(), mongoConf.getAdminDB())); builder.error(errorBuilder.build()); } catch (MongoTimeoutException e) { String description; VerificationError.StandardCode code = VerificationError.StandardCode.GENERIC; if (e.getMessage().contains("com.mongodb.MongoSecurityException")) { code = VerificationError.StandardCode.AUTHENTICATION; description = String.format("Unable to authenticate %s against %s authentication database!", mongoConf.getUser(), mongoConf.getAdminDB()); } else if (e.getMessage().contains("com.mongodb.MongoSocket") && e.getMessage().contains("Exception")) { description = String.format("Unable to connect to %s!", mongoConf.getHost()); } else { description = String.format("Generic exception while connecting to %s!", mongoConf.getHost()); } ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription( code, String.format(description)); builder.error(errorBuilder.build()); } }