I attach a patch as possible solution for mongodb3 support.
On Sat, Jul 4, 2015 at 2:12 AM, Gary Gregory <[email protected]> wrote:
> On Fri, Jul 3, 2015 at 12:30 PM, Jose Luis Valencia <
> [email protected]> wrote:
>
>> Driver 3.x support all previous mongo server versions and the unique
>> incompatibility factor between 2.x and 3.x drivers is that function which
>> was deprecated in 2.12 itself.
>> I also would like to say that log4j doesn't support connections to mongo
>> databases that don't need authentication.
>>
>
> That was addressed in LOG4J2-403 which will be in 2.4. You can pick this
> up in a 2.4-SNAPSHOT build.
>
> Gary
>
>
>>
>> On Fri, Jul 3, 2015 at 1:12 PM, Gary Gregory <[email protected]>
>> wrote:
>>
>>> FYI: I'm pretty sure that we can only support the 2.x or 3.x driver but
>>> not both at the same time without some nasty tricks.
>>>
>>> On Fri, Jul 3, 2015 at 9:38 AM, Ralph Goers <[email protected]>
>>> wrote:
>>>
>>>> At the very least, please create a Jira issue.
>>>>
>>>> Ralph
>>>>
>>>> On Jul 3, 2015, at 9:17 AM, Gary Gregory <[email protected]>
>>>> wrote:
>>>>
>>>> Patches welcome! :-)
>>>>
>>>> Gary
>>>>
>>>>
>>>> -------- Original message --------
>>>> From: Jose Luis Valencia <[email protected]>
>>>> Date: 07/03/2015 08:12 (GMT-08:00)
>>>> To: [email protected]
>>>> Subject: log4j2 NoSql appender MongoDB 3 driver support
>>>>
>>>> I am using log4j 2.3, I tried to setup a NoSql appender using mongoDb
>>>> 3.0.2 and I got this exception:
>>>>
>>>> Caused by: java.lang.NoSuchMethodError:
>>>> com.mongodb.DB.isAuthenticated()Z
>>>>
>>>> at
>>>> org.apache.logging.log4j.nosql.appender.mongodb.MongoDbProvider.createNoSqlProvider(MongoDbProvider.java:178)
>>>> ... 90 more
>>>>
>>>> com.mongodb.DB.isAuthenticated()
>>>> was removed in mongodb-java-driver since 3.0 and was deprecated since
>>>> 2.12. It would be useful if log4j suports new
>>>> mongodb-java-driver 3.0
>>>>
>>>> Thank you!
>>>>
>>>> JOSÉ VALENCIA
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: [email protected] | [email protected]
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> José L. Valencia Gutierrez
>> <http://www.rocoto.com.pe>
>>
>
>
>
> --
> E-Mail: [email protected] | [email protected]
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
--
José L. Valencia Gutierrez
<http://www.rocoto.com.pe>
Index: log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java
<+>UTF-8
===================================================================
--- log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java (revision 8df207b9183339ec9c8bface521e3c6e8865d057)
+++ log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/mongodb/MongoDbProvider.java (revision )
@@ -18,12 +18,10 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.List;
-import com.mongodb.DB;
-import com.mongodb.MongoClient;
-import com.mongodb.ServerAddress;
-import com.mongodb.WriteConcern;
+import com.mongodb.*;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -153,15 +151,26 @@
} else if (databaseName != null && databaseName.length() > 0) {
description = "database=" + databaseName;
try {
+ ServerAddress serverAddress;
if (server != null && server.length() > 0) {
final int portInt = AbstractAppender.parseInt(port, 0);
description += ", server=" + server;
if (portInt > 0) {
description += ", port=" + portInt;
- database = new MongoClient(server, portInt).getDB(databaseName);
+ serverAddress = new ServerAddress(server, portInt);
} else {
- database = new MongoClient(server).getDB(databaseName);
+ serverAddress = new ServerAddress(server);
}
+ if (username != null && username.length() > 0 && password != null && password.length() > 0) {
+ description += ", username=" + username + ", passwordHash="
+ + NameUtil.md5(password + MongoDbProvider.class.getName());
+ MongoCredential credential = MongoCredential.createCredential(username,
+ databaseName, password.toCharArray());
+ database = new MongoClient(serverAddress, Arrays.asList(credential)).getDB(databaseName);
+ }
+ else{
+ database = new MongoClient(serverAddress).getDB(databaseName);
+ }
} else {
database = new MongoClient().getDB(databaseName);
}
@@ -175,19 +184,11 @@
return null;
}
- if (!database.isAuthenticated()) {
- if (username != null && username.length() > 0 && password != null && password.length() > 0) {
- description += ", username=" + username + ", passwordHash="
- + NameUtil.md5(password + MongoDbProvider.class.getName());
- MongoDbConnection.authenticate(database, username, password);
- } else {
- try {
- database.getCollectionNames(); // Check if the database actually requires authentication
- } catch (Exception e) {
+ try {
+ database.getCollectionNames(); // Check if the database actually requires authentication
+ } catch (Exception e) {
- LOGGER.error("The database is not already authenticated so you must supply a username and password for the MongoDB provider.", e);
+ LOGGER.error("The database is not already authenticated", e);
- return null;
+ return null;
- }
- }
}
WriteConcern writeConcern;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]