int port = 0;
try {
port = Integer.parseInt(mongoPort);
} catch (NumberFormatException e) {
throw new MongoConnectionException(ErrorCodes.INVALID_PORT, "You have entered an invalid port number !");
}
ConnectionDetails connectionDetails = new ConnectionDetails(host, port, user, password, databases);
String connectionId = null;
try {
connectionId = authService.authenticate(connectionDetails, existingConnectionIdsInSession);
} catch (IllegalArgumentException m) {
throw new MongoConnectionException(ErrorCodes.INVALID_ARGUMENT, "You have entered an invalid data !");
} catch (MongoInternalException m) {
// Throws when cannot connect to localhost.com
throw new MongoConnectionException(ErrorCodes.HOST_UNKNOWN, m.getMessage());
} catch (MongoException m) {
throw new MongoConnectionException(ErrorCodes.MONGO_CONNECTION_EXCEPTION, "Connection Failed. Check if MongoDB is running at the given host and port.");
}
if (existingConnectionIdsInSession == null) {
existingConnectionIdsInSession = new HashSet<String>();
session.setAttribute("existingConnectionIdsInSession", existingConnectionIdsInSession);
}