use of com.mongodb.connection.ClusterSettings in project mongo-java-driver by mongodb.
the class Fixture method getMongoClientBuilderFromConnectionString.
public static MongoClientSettings.Builder getMongoClientBuilderFromConnectionString() {
SslSettings.Builder sslSettingsBuilder = SslSettings.builder().applyConnectionString(getConnectionString());
if (System.getProperty("java.version").startsWith("1.6.")) {
sslSettingsBuilder.invalidHostNameAllowed(true);
}
ClusterSettings clusterSettings = ClusterSettings.builder().applyConnectionString(getConnectionString()).build();
ConnectionPoolSettings connectionPoolSettings = ConnectionPoolSettings.builder().applyConnectionString(getConnectionString()).build();
SocketSettings socketSettings = SocketSettings.builder().applyConnectionString(getConnectionString()).build();
return MongoClientSettings.builder().clusterSettings(clusterSettings).connectionPoolSettings(connectionPoolSettings).serverSettings(ServerSettings.builder().build()).credentialList(getConnectionString().getCredentialList()).sslSettings(sslSettingsBuilder.build()).socketSettings(socketSettings);
}
use of com.mongodb.connection.ClusterSettings in project spring-boot by spring-projects.
the class ReactiveMongoClientFactory method createNetworkMongoClient.
private MongoClient createNetworkMongoClient(MongoClientSettings settings) {
if (hasCustomAddress() || hasCustomCredentials()) {
if (this.properties.getUri() != null) {
throw new IllegalStateException("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified");
}
Builder builder = builder(settings);
if (hasCustomCredentials()) {
List<MongoCredential> credentials = new ArrayList<>();
String database = this.properties.getAuthenticationDatabase() == null ? this.properties.getMongoClientDatabase() : this.properties.getAuthenticationDatabase();
credentials.add(MongoCredential.createCredential(this.properties.getUsername(), database, this.properties.getPassword()));
builder.credentialList(credentials);
}
String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost();
int port = this.properties.getPort() != null ? this.properties.getPort() : MongoProperties.DEFAULT_PORT;
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(host, port))).build();
builder.clusterSettings(clusterSettings);
return MongoClients.create(builder.build());
}
ConnectionString connectionString = new ConnectionString(this.properties.determineUri());
return MongoClients.create(createBuilder(settings, connectionString).build());
}
use of com.mongodb.connection.ClusterSettings in project spring-boot by spring-projects.
the class ReactiveMongoClientFactory method createEmbeddedMongoClient.
private MongoClient createEmbeddedMongoClient(MongoClientSettings settings, int port) {
Builder builder = builder(settings);
String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost();
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(host, port))).build();
builder.clusterSettings(clusterSettings);
return MongoClients.create(builder.build());
}
use of com.mongodb.connection.ClusterSettings in project spring-boot by spring-projects.
the class ReactiveMongoClientFactoryTests method extractServerAddresses.
private List<ServerAddress> extractServerAddresses(MongoClient client) {
MongoClientSettings settings = client.getSettings();
ClusterSettings clusterSettings = settings.getClusterSettings();
List<ServerAddress> allAddresses = clusterSettings.getHosts();
return allAddresses;
}
use of com.mongodb.connection.ClusterSettings in project spring-boot by spring-projects.
the class MongoClientFactoryTests method extractServerAddresses.
private List<ServerAddress> extractServerAddresses(MongoClient client) {
Cluster cluster = (Cluster) ReflectionTestUtils.getField(client, "cluster");
ClusterSettings clusterSettings = (ClusterSettings) ReflectionTestUtils.getField(cluster, "settings");
List<ServerAddress> allAddresses = clusterSettings.getHosts();
return allAddresses;
}
Aggregations