diff --git a/log4j-jdbc-dbcp2/pom.xml b/log4j-jdbc-dbcp2/pom.xml
index 70882c37f0f..f0854bf4295 100644
--- a/log4j-jdbc-dbcp2/pom.xml
+++ b/log4j-jdbc-dbcp2/pom.xml
@@ -27,7 +27,7 @@
log4j-jdbc-dbcp2
- Apache Log4j JDBC DBCP 2
+ Apache Log4j JDBC: DBCP 2 datasourceConnection source for the JDBC Appender using Apache Commons DBCP2.
diff --git a/log4j-jdbc-jndi/.log4j-plugin-processing-activator b/log4j-jdbc-jndi/.log4j-plugin-processing-activator
new file mode 100644
index 00000000000..ba133f36961
--- /dev/null
+++ b/log4j-jdbc-jndi/.log4j-plugin-processing-activator
@@ -0,0 +1 @@
+This file is here to activate the `plugin-processing` Maven profile.
diff --git a/log4j-jdbc-jndi/pom.xml b/log4j-jdbc-jndi/pom.xml
new file mode 100644
index 00000000000..6fc8e394da6
--- /dev/null
+++ b/log4j-jdbc-jndi/pom.xml
@@ -0,0 +1,109 @@
+
+
+
+ 4.0.0
+
+ org.apache.logging.log4j
+ log4j
+ ${revision}
+ ../log4j-parent
+
+
+ log4j-jdbc-jndi
+ Apache Log4j JDBC: JNDI datasource
+ Connection source for the JDBC Appender using JNDI.
+
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+
+ org.apache.logging.log4j
+ log4j-jdbc
+
+
+
+ org.apache.logging.log4j
+ log4j-jndi
+
+
+
+ org.apache.logging.log4j
+ log4j-plugins
+
+
+
+ org.apache.logging.log4j
+ log4j-core-test
+ test
+
+
+
+ org.apache.logging.log4j
+ log4j-jndi-test
+ test
+
+
+
+ org.apache.commons
+ commons-lang3
+ test
+
+
+
+ com.h2database
+ h2
+ test
+
+
+
+ org.hsqldb
+ hsqldb
+ test
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.junit.vintage
+ junit-vintage-engine
+ test
+
+
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+
+
diff --git a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSource.java b/log4j-jdbc-jndi/src/main/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSource.java
similarity index 66%
rename from log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSource.java
rename to log4j-jdbc-jndi/src/main/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSource.java
index 333a20ca40f..422aba34a1f 100644
--- a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSource.java
+++ b/log4j-jdbc-jndi/src/main/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSource.java
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
import java.sql.Connection;
import java.sql.SQLException;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.jdbc.appender.internal.JndiUtil;
+import org.apache.logging.log4j.jdbc.appender.AbstractConnectionSource;
+import org.apache.logging.log4j.jndi.JndiManager;
import org.apache.logging.log4j.plugins.Configurable;
import org.apache.logging.log4j.plugins.Plugin;
import org.apache.logging.log4j.plugins.PluginAttribute;
@@ -29,11 +31,14 @@
import org.apache.logging.log4j.util.Strings;
/**
- * A {@link JdbcAppender} connection source that uses a {@link DataSource} to connect to the database.
+ * A {@link org.apache.logging.log4j.jdbc.appender.JdbcAppender} connection source that uses a {@link DataSource} to connect to the database.
*/
@Configurable(elementType = "connectionSource", printObject = true)
@Plugin("DataSource")
public final class DataSourceConnectionSource extends AbstractConnectionSource {
+ private static final String DOC_URL =
+ "https://logging.staged.apache.org/log4j/3.x/manual/systemproperties.html#properties-jndi-support";
+ static final String JNDI_MANAGER_NAME = "org.apache.logging.log4j.jdbc.jndi.DataSourceConnectionSource";
private static final Logger LOGGER = StatusLogger.getLogger();
private final DataSource dataSource;
@@ -62,8 +67,10 @@ public String toString() {
*/
@PluginFactory
public static DataSourceConnectionSource createConnectionSource(@PluginAttribute final String jndiName) {
- if (!JndiUtil.isJndiJdbcEnabled()) {
- LOGGER.error("JNDI must be enabled by setting log4j2.enableJndiJdbc=true");
+ if (!JndiManager.isJndiJdbcEnabled()) {
+ LOGGER.error(
+ "JNDI must be enabled by setting `log4j.jndi.enableJdbc=\"true\"`\nSee {} for more details.",
+ DOC_URL);
return null;
}
if (Strings.isEmpty(jndiName)) {
@@ -71,11 +78,16 @@ public static DataSourceConnectionSource createConnectionSource(@PluginAttribute
return null;
}
- final DataSource dataSource = JndiUtil.getDataSource(jndiName);
- if (dataSource == null) {
- return null;
+ try {
+ final DataSource dataSource =
+ JndiManager.getDefaultManager(JNDI_MANAGER_NAME).lookup(jndiName);
+ if (dataSource != null) {
+ return new DataSourceConnectionSource(jndiName, dataSource);
+ }
+ LOGGER.error("Failed to retrieve JNDI data source with name {}.", jndiName);
+ } catch (final NamingException e) {
+ LOGGER.error("Failed to retrieve JNDI data source with name {}.", jndiName, e);
}
-
- return new DataSourceConnectionSource(jndiName, dataSource);
+ return null;
}
}
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderDataSourceTest.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/AbstractJdbcAppenderDataSourceTest.java
similarity index 89%
rename from log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderDataSourceTest.java
rename to log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/AbstractJdbcAppenderDataSourceTest.java
index 33e0f4dc5b9..92bd0780aad 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderDataSourceTest.java
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/AbstractJdbcAppenderDataSourceTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
import static org.apache.logging.log4j.core.test.TestConstants.JNDI_ENABLE_JDBC;
import static org.junit.Assert.assertEquals;
@@ -34,14 +34,12 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
import org.apache.logging.log4j.core.util.Throwables;
-import org.apache.logging.log4j.jdbc.appender.internal.JndiUtil;
import org.apache.logging.log4j.jndi.test.junit.JndiRule;
import org.h2.util.IOUtils;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
@@ -62,23 +60,19 @@ public static void beforeClass() {
protected AbstractJdbcAppenderDataSourceTest(final JdbcRule jdbcRule) {
this.rules = RuleChain.emptyRuleChain()
.around(new JndiRule(
- JndiUtil.JNDI_MANAGER_NAME,
+ DataSourceConnectionSource.JNDI_MANAGER_NAME,
"java:/comp/env/jdbc/TestDataSourceAppender",
createMockDataSource()))
.around(jdbcRule)
- .around(new LoggerContextRule("org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml"));
+ .around(new LoggerContextRule("AbstractJdbcAppenderDataSourceTest.xml"));
this.jdbcRule = jdbcRule;
}
private DataSource createMockDataSource() {
try {
final DataSource dataSource = mock(DataSource.class);
- given(dataSource.getConnection()).willAnswer(new Answer() {
- @Override
- public Connection answer(final InvocationOnMock invocation) throws Throwable {
- return jdbcRule.getConnectionSource().getConnection();
- }
- });
+ given(dataSource.getConnection()).willAnswer((Answer)
+ invocation -> jdbcRule.getConnectionSource().getConnection());
return dataSource;
} catch (final SQLException e) {
Throwables.rethrow(e);
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSourceTest.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSourceTest.java
similarity index 92%
rename from log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSourceTest.java
rename to log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSourceTest.java
index eb949024aa4..9dc5d8c4977 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/DataSourceConnectionSourceTest.java
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/DataSourceConnectionSourceTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
import static org.apache.logging.log4j.core.test.TestConstants.JNDI_ENABLE_JDBC;
import static org.junit.Assert.assertEquals;
@@ -22,13 +22,12 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
+import static org.mockito.BDDMockito.mock;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.apache.logging.log4j.jdbc.appender.internal.JndiUtil;
import org.apache.logging.log4j.jndi.test.junit.JndiRule;
import org.junit.Rule;
import org.junit.Test;
@@ -45,7 +44,7 @@ public static Object[][] data() {
return new Object[][] {{"java:/comp/env/jdbc/Logging01"}, {"java:/comp/env/jdbc/Logging02"}};
}
- private static final String CONFIG = "log4j-fatalOnly.xml";
+ private static final String CONFIG = "DataSourceConnectionSourceTest.xml";
@Rule
public final RuleChain rules;
@@ -54,7 +53,8 @@ public static Object[][] data() {
private final String jndiURL;
public DataSourceConnectionSourceTest(final String jndiURL) {
- this.rules = RuleChain.outerRule(new JndiRule(JndiUtil.JNDI_MANAGER_NAME, jndiURL, dataSource))
+ this.rules = RuleChain.outerRule(
+ new JndiRule(DataSourceConnectionSource.JNDI_MANAGER_NAME, jndiURL, dataSource))
.around(new LoggerContextRule(CONFIG));
this.jndiURL = jndiURL;
}
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderH2DataSourceTest.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderH2DataSourceTest.java
similarity index 95%
rename from log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderH2DataSourceTest.java
rename to log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderH2DataSourceTest.java
index 8046fa51d0d..1a94e949105 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderH2DataSourceTest.java
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderH2DataSourceTest.java
@@ -14,12 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
-/**
- *
- */
public class JdbcAppenderH2DataSourceTest extends AbstractJdbcAppenderDataSourceTest {
+
public JdbcAppenderH2DataSourceTest() {
super(new JdbcRule(
JdbcH2TestHelper.TEST_CONFIGURATION_SOURCE_MEM,
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderHsqldbDataSourceTest.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderHsqldbDataSourceTest.java
similarity index 93%
rename from log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderHsqldbDataSourceTest.java
rename to log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderHsqldbDataSourceTest.java
index 4bc68c5f732..c5a6ff07561 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderHsqldbDataSourceTest.java
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderHsqldbDataSourceTest.java
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import org.apache.logging.log4j.jdbc.appender.AbstractConnectionSource;
/**
*
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderMapMessageDataSourceTest.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderMapMessageDataSourceTest.java
similarity index 95%
rename from log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderMapMessageDataSourceTest.java
rename to log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderMapMessageDataSourceTest.java
index 125a17db70e..f57b1e1c8ac 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/JdbcAppenderMapMessageDataSourceTest.java
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcAppenderMapMessageDataSourceTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.jdbc.appender;
+package org.apache.logging.log4j.jdbc.jndi;
import static org.apache.logging.log4j.core.test.TestConstants.JNDI_ENABLE_JDBC;
import static org.junit.Assert.assertFalse;
@@ -34,7 +34,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
import org.apache.logging.log4j.core.util.Throwables;
-import org.apache.logging.log4j.jdbc.appender.internal.JndiUtil;
import org.apache.logging.log4j.jndi.test.junit.JndiRule;
import org.apache.logging.log4j.message.MapMessage;
import org.junit.Assert;
@@ -73,12 +72,11 @@ protected JdbcAppenderMapMessageDataSourceTest(final JdbcRule jdbcRule) {
// @formatter:off
this.rules = RuleChain.emptyRuleChain()
.around(new JndiRule(
- JndiUtil.JNDI_MANAGER_NAME,
+ DataSourceConnectionSource.JNDI_MANAGER_NAME,
"java:/comp/env/jdbc/TestDataSourceAppender",
createMockDataSource()))
.around(jdbcRule)
- .around(new LoggerContextRule(
- "org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml"));
+ .around(new LoggerContextRule("JdbcAppenderMapMessageDataSourceTest.xml"));
// @formatter:on
this.jdbcRule = jdbcRule;
}
diff --git a/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcH2TestHelper.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcH2TestHelper.java
new file mode 100644
index 00000000000..7e2a7220c84
--- /dev/null
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcH2TestHelper.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.jdbc.jndi;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.apache.logging.log4j.jdbc.appender.AbstractConnectionSource;
+import org.apache.logging.log4j.jdbc.appender.ConnectionSource;
+
+public class JdbcH2TestHelper {
+
+ private static final String CONNECTION_STRING = "jdbc:h2:mem:Log4j";
+ private static final String USERNAME = "sa";
+ private static final String PASSWORD = "";
+
+ public static ConnectionSource TEST_CONFIGURATION_SOURCE_MEM = new AbstractConnectionSource() {
+ @Override
+ public Connection getConnection() throws SQLException {
+ return DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD);
+ }
+ };
+}
diff --git a/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcRule.java b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcRule.java
new file mode 100644
index 00000000000..8f833d50272
--- /dev/null
+++ b/log4j-jdbc-jndi/src/test/java/org/apache/logging/log4j/jdbc/jndi/JdbcRule.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.jdbc.jndi;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
+import org.apache.logging.log4j.jdbc.appender.ConnectionSource;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+
+/**
+ * JUnit rule to set up a database. This will create a table using the configure creation statement on startup, run its
+ * wrapped test(s), then execute a drop table statement on shutdown, and finally will attempt execute a {@code SHUTDOWN}
+ * command afterward (e.g., for H2, HSQLDB). When used in integration tests, this rule should be the outer rule in a
+ * chain with {@link LoggerContextRule}.
+ *
+ * @since 2.8
+ */
+public class JdbcRule implements TestRule {
+
+ private final ConnectionSource connectionSource;
+ private final String createTableStatement;
+ private final String dropTableStatement;
+
+ /**
+ * Creates a JdbcRule using a {@link ConnectionSource} and a table creation statement.
+ *
+ * @param connectionSource a required source for obtaining a Connection.
+ * @param createTableStatement an optional SQL DDL statement to create a table for use in a JUnit test.
+ * @param dropTableStatement an optional SQL DDL statement to drop the created table.
+ */
+ public JdbcRule(
+ final ConnectionSource connectionSource,
+ final String createTableStatement,
+ final String dropTableStatement) {
+ this.connectionSource = Objects.requireNonNull(connectionSource, "connectionSource");
+ this.createTableStatement = createTableStatement;
+ this.dropTableStatement = dropTableStatement;
+ }
+
+ @Override
+ public org.junit.runners.model.Statement apply(
+ final org.junit.runners.model.Statement base, final Description description) {
+ return new org.junit.runners.model.Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try (final Connection connection = getConnection();
+ final Statement statement = connection.createStatement()) {
+ try {
+ if (StringUtils.isNotEmpty(createTableStatement)) {
+ statement.executeUpdate(createTableStatement);
+ }
+ base.evaluate();
+ } finally {
+ if (StringUtils.isNotEmpty(dropTableStatement)) {
+ statement.executeUpdate(dropTableStatement);
+ }
+ statement.execute("SHUTDOWN");
+ }
+ }
+ }
+ };
+ }
+
+ public Connection getConnection() throws SQLException {
+ return connectionSource.getConnection();
+ }
+
+ public ConnectionSource getConnectionSource() {
+ return connectionSource;
+ }
+}
diff --git a/log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml b/log4j-jdbc-jndi/src/test/resources/AbstractJdbcAppenderDataSourceTest.xml
similarity index 81%
rename from log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml
rename to log4j-jdbc-jndi/src/test/resources/AbstractJdbcAppenderDataSourceTest.xml
index c589410db49..1b6cd3f1829 100644
--- a/log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml
+++ b/log4j-jdbc-jndi/src/test/resources/AbstractJdbcAppenderDataSourceTest.xml
@@ -15,8 +15,11 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-
+
@@ -33,7 +36,7 @@
-
+
diff --git a/log4j-jdbc/src/test/resources/log4j-fatalOnly.xml b/log4j-jdbc-jndi/src/test/resources/DataSourceConnectionSourceTest.xml
similarity index 73%
rename from log4j-jdbc/src/test/resources/log4j-fatalOnly.xml
rename to log4j-jdbc-jndi/src/test/resources/DataSourceConnectionSourceTest.xml
index b3e386f33e4..95ac8003f83 100644
--- a/log4j-jdbc/src/test/resources/log4j-fatalOnly.xml
+++ b/log4j-jdbc-jndi/src/test/resources/DataSourceConnectionSourceTest.xml
@@ -15,19 +15,13 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
diff --git a/log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml b/log4j-jdbc-jndi/src/test/resources/JdbcAppenderMapMessageDataSourceTest.xml
similarity index 79%
rename from log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml
rename to log4j-jdbc-jndi/src/test/resources/JdbcAppenderMapMessageDataSourceTest.xml
index 0d2a9e24879..b3926b2e5e4 100644
--- a/log4j-jdbc/src/test/resources/org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml
+++ b/log4j-jdbc-jndi/src/test/resources/JdbcAppenderMapMessageDataSourceTest.xml
@@ -15,8 +15,11 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-
+
@@ -31,7 +34,7 @@
-
+
diff --git a/log4j-jdbc/pom.xml b/log4j-jdbc/pom.xml
index ebfd6988396..494b2d6983b 100644
--- a/log4j-jdbc/pom.xml
+++ b/log4j-jdbc/pom.xml
@@ -30,89 +30,66 @@
Apache Log4j JDBCApache Log4j Java Database Connectivity (JDBC).
-
- ${basedir}/..
-
-
-
-
- org.apache.logging.log4j.jndi;resolution:=optional
-
-
-
+
org.apache.logging.log4j
- log4j-core
+ log4j-api
+
org.apache.logging.log4j
- log4j-jndi
- true
+ log4j-core
+
org.apache.logging.log4j
- log4j-api-test
- test
+ log4j-plugins
+
org.apache.logging.log4jlog4j-core-testtest
-
- org.apache.logging.log4j
- log4j-jndi-test
- test
-
-
- commons-io
- commons-io
- test
-
+
org.apache.commonscommons-lang3test
-
- commons-logging
- commons-logging
- test
-
+
com.h2databaseh2test
-
- org.hamcrest
- hamcrest
- test
-
+
org.hsqldbhsqldbtest
+
- org.junit.jupiter
- junit-jupiter-engine
+ junit
+ junittest
+
org.junit.vintagejunit-vintage-enginetest
+
org.mockitomockito-coretest
+
diff --git a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/internal/JndiUtil.java b/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/internal/JndiUtil.java
deleted file mode 100644
index 9eca48f064f..00000000000
--- a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/internal/JndiUtil.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.jdbc.appender.internal;
-
-import javax.naming.NamingException;
-import javax.sql.DataSource;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.jdbc.appender.DataSourceConnectionSource;
-import org.apache.logging.log4j.jndi.JndiManager;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * This class is solely for the purpose of keeping DataSourceConnectionSource from getting a NoClassDefFoundError.
- */
-public final class JndiUtil {
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- /**
- * Manager name used for accessing the {@link JndiManager} instance.
- */
- public static final String JNDI_MANAGER_NAME = DataSourceConnectionSource.class.getCanonicalName();
-
- private JndiUtil() {}
-
- public static DataSource getDataSource(final String jndiName) {
- try {
- final DataSource dataSource =
- JndiManager.getDefaultManager(JNDI_MANAGER_NAME).lookup(jndiName);
- if (dataSource == null) {
- LOGGER.error("No data source found with JNDI name [" + jndiName + "].");
- return null;
- }
- return dataSource;
- } catch (final NamingException e) {
- LOGGER.error(e.getMessage(), e);
- return null;
- }
- }
-
- public static boolean isJndiJdbcEnabled() {
- return JndiManager.isJndiJdbcEnabled();
- }
-}
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderFactoryMethodTest.java b/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderFactoryMethodTest.java
index 2b1e58c3e41..69b5bf88faa 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderFactoryMethodTest.java
+++ b/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/AbstractJdbcAppenderFactoryMethodTest.java
@@ -50,8 +50,7 @@ public abstract class AbstractJdbcAppenderFactoryMethodTest {
protected AbstractJdbcAppenderFactoryMethodTest(final JdbcRule jdbcRule, final String databaseType) {
this.rules = RuleChain.emptyRuleChain()
.around(jdbcRule)
- .around(new LoggerContextRule(
- "org/apache/logging/log4j/jdbc/appender/log4j2-" + databaseType + "-factory-method.xml"));
+ .around(new LoggerContextRule(getClass().getSimpleName() + ".xml"));
this.jdbcRule = jdbcRule;
}
diff --git a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/FactoryMethodConnectionSourceTest.java b/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/FactoryMethodConnectionSourceTest.java
index b67b71aa8af..b2a9189dc83 100644
--- a/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/FactoryMethodConnectionSourceTest.java
+++ b/log4j-jdbc/src/test/java/org/apache/logging/log4j/jdbc/appender/FactoryMethodConnectionSourceTest.java
@@ -33,7 +33,7 @@
public class FactoryMethodConnectionSourceTest {
private static final ThreadLocal