Skip to content

Commit

Permalink
ATS-13 update Mongo Java Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
mm committed Aug 13, 2019
1 parent 645249b commit 5bde40d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -200,7 +200,7 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.5.0</version>
<version>3.10.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -39,9 +39,7 @@ public void invoke(Request request, Response response) throws IOException, Servl
getNext().invoke(request, response);
} finally {
long start = System.currentTimeMillis();
if (!Utils.isTemplateRequest(request)) {
storeSession(request, response);
}
storeSession(request, response);
long duration = System.currentTimeMillis() - start;
if (log.isDebugEnabled() && duration > 0) {
log.debug(String.format("handling session for %s took %sms", request.getServletPath(), duration));
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/org/appng/tomcat/session/mongo/MongoStore.java
Expand Up @@ -60,7 +60,7 @@ public class MongoStore extends StoreBase {
private final Log log = Utils.getLog(MongoStore.class);

/** Property used to store the Session's ID */
private static final String idProperty = "_id";
private static final String idProperty = "session_id";

/** Property used to store the Session's context name */
protected static final String appContextProperty = "app";
Expand Down Expand Up @@ -174,7 +174,7 @@ public class MongoStore extends StoreBase {
/** The {@link ReadPreference}, using {@link ReadPreference#primary()} for maximum consistency by default */
protected ReadPreference readPreference = ReadPreference.primary();

/** The {@link ReadConcern}, using {@link ReadConcern#MAJORITY} for maximum consistency by default */
/** The {@link ReadConcern}, using {@link ReadConcern#DEFAULT} for maximum consistency by default */
protected ReadConcern readConcern = ReadConcern.DEFAULT;

/** Should a TTL index be used to expire sessions ? */
Expand Down Expand Up @@ -461,26 +461,24 @@ private void getConnection() throws LifecycleException {
}
MongoClientOptions options = MongoClientOptions.builder().connectTimeout(connectionTimeoutMs)
.maxWaitTime(connectionWaitTimeoutMs).connectionsPerHost(maxPoolSize).writeConcern(writeConcern)
.readPreference(readPreference).readConcern(readConcern).build();
.readPreference(readPreference).readConcern(readConcern).requiredReplicaSetName(replicaSet).build();

List<ServerAddress> hosts = new ArrayList<ServerAddress>();
String[] dbHosts = this.hosts.split(",");
for (String dbHost : dbHosts) {
for (String dbHost : this.hosts.split(",")) {
String[] hostInfo = dbHost.split(":");
ServerAddress address = new ServerAddress(hostInfo[0], Integer.parseInt(hostInfo[1]));
hosts.add(address);
hosts.add(new ServerAddress(hostInfo[0], Integer.parseInt(hostInfo[1])));
}

info("%s [%s]: Connecting to MongoDB [%s]", getStoreName(), this.getName(), this.hosts);

List<MongoCredential> credentials = new ArrayList<MongoCredential>();
if (this.username != null || this.password != null) {
info("%s [%s]: Authenticating using [%s]", getStoreName(), this.getName(), this.username);
for (int i = 0; i < hosts.size(); i++) {
credentials.add(MongoCredential.createCredential(username, dbName, password.toCharArray()));
}
MongoCredential credential = MongoCredential.createCredential(username, dbName,
password.toCharArray());
this.mongoClient = new MongoClient(hosts, credential, options);
} else {
this.mongoClient = new MongoClient(hosts, options);
}
this.mongoClient = new MongoClient(hosts, credentials, options);
}

info("%s [%s]: Using Database [%s]", getStoreName(), this.getName(), this.dbName);
Expand Down

0 comments on commit 5bde40d

Please sign in to comment.