Fixed the connector to be able to get multiple hosts
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib--mongodb@134362 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fb00434a27
commit
ec3546e8ee
|
@ -138,7 +138,7 @@ public class PersistenceMongoDB extends PersistenceBackend {
|
|||
logger.debug("Preparing Connection for {}", this.getClass().getSimpleName());
|
||||
this.configuration = configuration;
|
||||
|
||||
String url = configuration.getProperty(URL_PROPERTY_KEY);
|
||||
String completeURL = configuration.getProperty(URL_PROPERTY_KEY);
|
||||
String username = configuration.getProperty(USERNAME_PROPERTY_KEY);
|
||||
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
||||
String dbName = configuration.getProperty(DB_NAME);
|
||||
|
@ -146,10 +146,16 @@ public class PersistenceMongoDB extends PersistenceBackend {
|
|||
MongoCredential credential = MongoCredential.createScramSha1Credential(
|
||||
username, dbName, password.toCharArray());
|
||||
|
||||
url = url.startsWith("http://") ? url.replace("http://", "") : url;
|
||||
ServerAddress serverAddress = new ServerAddress(url);
|
||||
String[] urls = completeURL.split(";");
|
||||
List<ServerAddress> serverAddresses = new ArrayList<>();
|
||||
for(String url : urls){
|
||||
url = url.startsWith("http://") ? url.replace("http://", "") : url;
|
||||
url = url.startsWith("https://") ? url.replace("https://", "") : url;
|
||||
ServerAddress serverAddress = new ServerAddress(url);
|
||||
serverAddresses.add(serverAddress);
|
||||
}
|
||||
|
||||
mongoClient = new MongoClient(serverAddress,
|
||||
mongoClient = new MongoClient(serverAddresses,
|
||||
Arrays.asList(credential), mongoClientOptions); //, MONGO_CLIENT_OPTIONS);
|
||||
|
||||
mongoDatabase = mongoClient.getDatabase(dbName);
|
||||
|
|
Reference in New Issue