This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch jee-deletion in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 18f11f72259c2ca9fbe83847109929875e3f8eab Author: Volkan Yazıcı <[email protected]> AuthorDate: Mon Nov 20 12:06:59 2023 +0100 Delete JMS appender (#1966) --- log4j-1.2-api/bnd.bnd | 3 +- log4j-1.2-api/pom.xml | 7 - .../log4j/util/PropertiesUtilOrderTest.java | 5 - log4j-core-its/pom.xml | 27 +- log4j-core-test/pom.xml | 5 - .../log4j/core/test/categories/Appenders.java | 1 - .../src/main/resources/Log4j-config.xsd | 11 - .../java/org/apache/logging/log4j/core/Layout.java | 7 - log4j-core/src/main/resources/Log4j-config.xsd | 11 - log4j-distribution/pom.xml | 12 - log4j-gctests/pom.xml | 6 - log4j-jms/pom.xml | 125 ------ .../logging/log4j/jms/appender/JmsAppender.java | 241 ----------- .../logging/log4j/jms/appender/JmsManager.java | 477 --------------------- .../logging/log4j/jms/appender/package-info.java | 28 -- .../log4j/jms/appender/JmsAppenderTest.java | 190 -------- log4j-jms/src/test/resources/JmsAppenderTest.xml | 45 -- log4j-parent/pom.xml | 15 - pom.xml | 7 - src/site/asciidoc/manual/appenders.adoc | 141 ------ src/site/asciidoc/manual/architecture.adoc | 2 +- src/site/asciidoc/manual/messages.adoc | 2 +- src/site/asciidoc/manual/systemproperties.adoc | 2 +- src/site/asciidoc/runtime-dependencies.adoc | 3 - src/site/markdown/log4j-jms.md | 33 -- src/site/markdown/log4j-jmx-gui.md | 22 - src/site/markdown/manual/compatibility.md | 1 - src/site/site.xml | 12 +- 28 files changed, 13 insertions(+), 1428 deletions(-) diff --git a/log4j-1.2-api/bnd.bnd b/log4j-1.2-api/bnd.bnd index 4ea244d57f..65c847d955 100644 --- a/log4j-1.2-api/bnd.bnd +++ b/log4j-1.2-api/bnd.bnd @@ -23,5 +23,4 @@ org.osgi.core;static=true;transitive=false,\ org.osgi.framework;static=true;transitive=false,\ org.apache.logging.log4j;substitute="log4j-api",\ - org.apache.logging.log4j.core;substitute="log4j-core";transitive=false;static=true,\ - javax.jms.api;substitute="javax.jms-api" + org.apache.logging.log4j.core;substitute="log4j-core";transitive=false;static=true diff --git a/log4j-1.2-api/pom.xml b/log4j-1.2-api/pom.xml index 3883b7f18d..d7969bf933 100644 --- a/log4j-1.2-api/pom.xml +++ b/log4j-1.2-api/pom.xml @@ -40,8 +40,6 @@ <bnd-extra-package-options> <!-- JMX support --> com.sun.jdmk.comm;resolution:=optional, - <!-- JMS is optional --> - javax.jms;substitute="javax.jms-api";version="[1.1,3)";resolution:=optional, <!-- Log4j Core is optional --> org.apache.logging.log4j.core.*;resolution:=optional </bnd-extra-package-options> @@ -49,11 +47,6 @@ <!-- we have an `bnd.bnd` file to override the parent's defaults --> </properties> <dependencies> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <scope>provided</scope> - </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertiesUtilOrderTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertiesUtilOrderTest.java index 984dfb51fb..5952131c38 100644 --- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertiesUtilOrderTest.java +++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertiesUtilOrderTest.java @@ -90,7 +90,6 @@ public class PropertiesUtilOrderTest { env.set("log4j2.*.Configuration.statusLoggerLevel", "ERROR"); env.set("log4j2.*.StatusLogger.entries", "200"); env.set("log4j2.my-app.StatusLogger.entries", "500"); - sysProps.set("log4j2.*.JNDI.enableJMS", "false"); sysProps.set("log4j2.my-app.Configuration.mergeStrategy", "org.apache.CustomMergeStrategy"); sysProps.set("log4j2.*.Web.isWebApp", "true"); PropertiesUtil.getProperties().reload(); @@ -102,14 +101,10 @@ public class PropertiesUtilOrderTest { assertTrue(contextProperties.hasProperty(TestProperty.CONFIG_TEST1)); // Context environment properties should override system-wide environment definition. assertEquals("500", contextProperties.getStringProperty(LoggingSystemProperty.STATUS_MAX_ENTRIES)); - // System property value should be recognized. - assertEquals("false", util.getStringProperty(TestProperty.JNDI_JMS, "true")); // Context system property should override Context property from file. assertEquals("org.apache.CustomMergeStrategy", contextProperties.getStringProperty(TestProperty.CONFIG_MERGE_STRATEGY)); // Recognize system-wide environment variable. assertEquals("200", util.getStringProperty(LoggingSystemProperty.STATUS_MAX_ENTRIES)); - // Context properties in file should override system-wide system property. - assertEquals("true", contextProperties.getStringProperty(TestProperty.JNDI_JMS, "false")); // System-wide system property should be used when no other value is available. assertEquals("true", contextProperties.getStringProperty(LoggingSystemProperty.IS_WEBAPP)); // Context property in file should override system-wide property in file. diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml index b148cf27f0..b206fb65dc 100644 --- a/log4j-core-its/pom.xml +++ b/log4j-core-its/pom.xml @@ -38,13 +38,6 @@ <maven.test.skip>true</maven.test.skip> </properties> <dependencies> - <!-- Used for JMS appenders (needs an implementation of course) --> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <scope>provided</scope> - <optional>true</optional> - </dependency> <!-- Alternative implementation of BlockingQueue using Conversant Disruptor for AsyncAppender --> <dependency> <groupId>com.conversantmedia</groupId> @@ -144,23 +137,6 @@ <artifactId>log4j-layout-jackson-xml</artifactId> <scope>test</scope> </dependency> - <!-- JPA, JNDI and JMS tests --> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-broker</artifactId> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_1.1_spec</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest</artifactId> @@ -223,8 +199,7 @@ <excludes> <exclude>**/ForceNoDefClassFoundError.*</exclude> </excludes> - <groups>org.apache.logging.log4j.core.test.categories.PerformanceTests, - org.apache.logging.log4j.core.test.categories.Appenders$Jms</groups> + <groups>org.apache.logging.log4j.core.test.categories.PerformanceTests</groups> </configuration> </plugin> <plugin> diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml index 3389f8ef28..54394325d3 100644 --- a/log4j-core-test/pom.xml +++ b/log4j-core-test/pom.xml @@ -106,11 +106,6 @@ <artifactId>commons-compress</artifactId> <optional>true</optional> </dependency> - <!-- JNDI and JMS tests --> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </dependency> <!-- Alternative implementation of BlockingQueue using Conversant Disruptor for AsyncAppender --> <dependency> <groupId>com.conversantmedia</groupId> diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Appenders.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Appenders.java index d830db3d0f..a8aaee98b4 100644 --- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Appenders.java +++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/categories/Appenders.java @@ -24,7 +24,6 @@ public interface Appenders { interface AsyncJcTools {} interface Cassandra {} interface CouchDb {} - interface Jms {} interface Jpa {} interface Kafka {} interface MongoDb {} diff --git a/log4j-core-test/src/main/resources/Log4j-config.xsd b/log4j-core-test/src/main/resources/Log4j-config.xsd index 5868cdb162..8f6687459e 100644 --- a/log4j-core-test/src/main/resources/Log4j-config.xsd +++ b/log4j-core-test/src/main/resources/Log4j-config.xsd @@ -647,9 +647,6 @@ <element name="Console" type="tns:ConsoleAppenderType" minOccurs="0" /> <element name="Flume" type="tns:FlumeAppenderType" minOccurs="0" /> <element name="JeroMQ" type="tns:JeroMQAppenderType" minOccurs="0" /> - <element name="JMS" type="tns:JMSAppenderType" minOccurs="0" /> - <element name="JMSQueue" type="tns:JMSAppenderType" minOccurs="0" /> - <element name="JMSTopic" type="tns:JMSAppenderType" minOccurs="0" /> <element name="Kafka" type="tns:KafkaAppenderType" minOccurs="0" /> <element name="Rewrite" type="tns:RewriteAppenderType" minOccurs="0" /> <element name="Routing" type="tns:RoutingAppenderType" minOccurs="0" /> @@ -839,14 +836,6 @@ </complexContent> </complexType> - <complexType name="JMSAppenderType"> - <complexContent> - <extension base="tns:AbstractAppenderType"> - <anyAttribute processContents="lax" /> - </extension> - </complexContent> - </complexType> - <complexType name="KafkaAppenderType"> <complexContent> <extension base="tns:AbstractAppenderType"> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/Layout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/Layout.java index 9c7a81dc31..70e2f57fd1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/Layout.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/Layout.java @@ -60,13 +60,6 @@ public interface Layout extends Encoder<LogEvent> { */ byte[] toByteArray(LogEvent event); - /** - * Returns the character set used for encoding log events. - */ - default Charset getCharset() { - return StandardCharsets.UTF_8; - } - /** * Serializes the log event into a String. * diff --git a/log4j-core/src/main/resources/Log4j-config.xsd b/log4j-core/src/main/resources/Log4j-config.xsd index 5868cdb162..8f6687459e 100644 --- a/log4j-core/src/main/resources/Log4j-config.xsd +++ b/log4j-core/src/main/resources/Log4j-config.xsd @@ -647,9 +647,6 @@ <element name="Console" type="tns:ConsoleAppenderType" minOccurs="0" /> <element name="Flume" type="tns:FlumeAppenderType" minOccurs="0" /> <element name="JeroMQ" type="tns:JeroMQAppenderType" minOccurs="0" /> - <element name="JMS" type="tns:JMSAppenderType" minOccurs="0" /> - <element name="JMSQueue" type="tns:JMSAppenderType" minOccurs="0" /> - <element name="JMSTopic" type="tns:JMSAppenderType" minOccurs="0" /> <element name="Kafka" type="tns:KafkaAppenderType" minOccurs="0" /> <element name="Rewrite" type="tns:RewriteAppenderType" minOccurs="0" /> <element name="Routing" type="tns:RoutingAppenderType" minOccurs="0" /> @@ -839,14 +836,6 @@ </complexContent> </complexType> - <complexType name="JMSAppenderType"> - <complexContent> - <extension base="tns:AbstractAppenderType"> - <anyAttribute processContents="lax" /> - </extension> - </complexContent> - </complexType> - <complexType name="KafkaAppenderType"> <complexContent> <extension base="tns:AbstractAppenderType"> diff --git a/log4j-distribution/pom.xml b/log4j-distribution/pom.xml index d3cd08a8c7..4483fe7f35 100644 --- a/log4j-distribution/pom.xml +++ b/log4j-distribution/pom.xml @@ -297,18 +297,6 @@ <version>${project.version}</version> <classifier>sources</classifier> </dependency> - <!-- log4j-jms --> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jms</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jms</artifactId> - <version>${project.version}</version> - <classifier>sources</classifier> - </dependency> <!-- log4j-jndi --> <dependency> <groupId>org.apache.logging.log4j</groupId> diff --git a/log4j-gctests/pom.xml b/log4j-gctests/pom.xml index 68fd66ddcd..5cefc13f70 100644 --- a/log4j-gctests/pom.xml +++ b/log4j-gctests/pom.xml @@ -169,12 +169,6 @@ <artifactId>commons-lang3</artifactId> <scope>test</scope> </dependency> - <!-- JNDI and JMS tests --> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.apache.groovy</groupId> <artifactId>groovy-dateutil</artifactId> diff --git a/log4j-jms/pom.xml b/log4j-jms/pom.xml deleted file mode 100644 index 6ade95cd13..0000000000 --- a/log4j-jms/pom.xml +++ /dev/null @@ -1,125 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j</artifactId> - <version>${revision}</version> - <relativePath>../log4j-parent</relativePath> - </parent> - - <artifactId>log4j-jms</artifactId> - <name>Apache Log4j JMS</name> - <description>Apache Log4j Java Message Service (JMS).</description> - <properties> - <log4jParentDir>${basedir}/..</log4jParentDir> - <docLabel>Log4j JMS Documentation</docLabel> - <projectDir>/log4j-jms</projectDir> - - <!-- - ~ OSGi and JPMS options - --> - <bnd-extra-module-options> - <!-- Filebased module names must be `static` --> - javax.jms.api;substitute="javax.jms-api";static=true;transitive=false - </bnd-extra-module-options> - </properties> - - <dependencies> - <!-- Used for JMS appenders (needs an implementation of course) --> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jndi</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jndi-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> - <!-- Mocking framework for use with JUnit --> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <!-- Useful mock classes and utilities --> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <annotationProcessorPaths combine.children="append"> - <path> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-plugin-processor</artifactId> - <version>${project.version}</version> - </path> - </annotationProcessorPaths> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsAppender.java deleted file mode 100644 index 4eb8cafe7f..0000000000 --- a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsAppender.java +++ /dev/null @@ -1,241 +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.jms.appender; - -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import javax.jms.JMSException; - -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.Filter; -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AbstractAppender; -import org.apache.logging.log4j.core.appender.AbstractManager; -import org.apache.logging.log4j.core.config.Property; -import org.apache.logging.log4j.core.util.Constants; -import org.apache.logging.log4j.jms.appender.JmsManager.JmsManagerConfiguration; -import org.apache.logging.log4j.plugins.Configurable; -import org.apache.logging.log4j.plugins.Plugin; -import org.apache.logging.log4j.plugins.PluginAliases; -import org.apache.logging.log4j.plugins.PluginBuilderAttribute; -import org.apache.logging.log4j.plugins.PluginFactory; -import org.apache.logging.log4j.plugins.validation.constraints.Required; - -/** - * Generic JMS Appender plugin for both queues and topics. This Appender replaces the previous split ones. However, - * configurations set up for the 2.0 version of the JMS appenders will still work. - */ -@Configurable(elementType = Appender.ELEMENT_TYPE, printObject = true) -@Plugin("JMS") -@PluginAliases({ "JMSQueue", "JMSTopic" }) -public class JmsAppender extends AbstractAppender { - - public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B> - implements org.apache.logging.log4j.plugins.util.Builder<JmsAppender> { - - public static final int DEFAULT_RECONNECT_INTERVAL_MILLIS = 5000; - - @PluginBuilderAttribute - private String factoryName; - - @PluginBuilderAttribute - private String providerUrl; - - @PluginBuilderAttribute - private String urlPkgPrefixes; - - @PluginBuilderAttribute - private String securityPrincipalName; - - @PluginBuilderAttribute(sensitive = true) - private String securityCredentials; - - @PluginBuilderAttribute - @Required(message = "A javax.jms.ConnectionFactory JNDI name must be specified") - private String factoryBindingName; - - @PluginBuilderAttribute - @PluginAliases({ "queueBindingName", "topicBindingName" }) - @Required(message = "A javax.jms.Destination JNDI name must be specified") - private String destinationBindingName; - - @PluginBuilderAttribute - private String userName; - - @PluginBuilderAttribute(sensitive = true) - private char[] password; - - @PluginBuilderAttribute - private long reconnectIntervalMillis = DEFAULT_RECONNECT_INTERVAL_MILLIS; - - @PluginBuilderAttribute - private boolean immediateFail; - - // Programmatic access only for now. - private JmsManager jmsManager; - - private Builder() { - } - - @SuppressWarnings("resource") // actualJmsManager and jndiManager are managed by the JmsAppender - @Override - public JmsAppender build() { - if (!Constants.JNDI_JMS_ENABLED) { - LOGGER.error("JNDI has not been enabled. The log4j2.enableJndi property must be set to true"); - return null; - } - JmsManager actualJmsManager = jmsManager; - JmsManagerConfiguration configuration = null; - if (actualJmsManager == null) { - final Properties additionalProperties = null; - final Properties jndiProperties = JmsManager.createJndiProperties(factoryName, providerUrl, - urlPkgPrefixes, securityPrincipalName, securityCredentials, additionalProperties); - configuration = new JmsManagerConfiguration(jndiProperties, factoryBindingName, destinationBindingName, - userName, password, false, reconnectIntervalMillis); - actualJmsManager = AbstractManager.getManager(getName(), JmsManager.FACTORY, configuration); - } - if (actualJmsManager == null) { - // JmsManagerFactory has already logged an ERROR. - return null; - } - try { - return new JmsAppender(getName(), getFilter(), getLayout(), isIgnoreExceptions(), getPropertyArray(), actualJmsManager); - } catch (final JMSException e) { - // Never happens since the ctor no longer actually throws a JMSException. - throw new IllegalStateException(e); - } - } - - public B setDestinationBindingName(final String destinationBindingName) { - this.destinationBindingName = destinationBindingName; - return asBuilder(); - } - - public B setFactoryBindingName(final String factoryBindingName) { - this.factoryBindingName = factoryBindingName; - return asBuilder(); - } - - public B setFactoryName(final String factoryName) { - this.factoryName = factoryName; - return asBuilder(); - } - - public B setImmediateFail(final boolean immediateFail) { - this.immediateFail = immediateFail; - return asBuilder(); - } - - public B setJmsManager(final JmsManager jmsManager) { - this.jmsManager = jmsManager; - return asBuilder(); - } - - public B setPassword(final char[] password) { - this.password = password; - return asBuilder(); - } - - public B setProviderUrl(final String providerUrl) { - this.providerUrl = providerUrl; - return asBuilder(); - } - - public B setReconnectIntervalMillis(final long reconnectIntervalMillis) { - this.reconnectIntervalMillis = reconnectIntervalMillis; - return asBuilder(); - } - - public B setSecurityCredentials(final String securityCredentials) { - this.securityCredentials = securityCredentials; - return asBuilder(); - } - - public B setSecurityPrincipalName(final String securityPrincipalName) { - this.securityPrincipalName = securityPrincipalName; - return asBuilder(); - } - - public B setUrlPkgPrefixes(final String urlPkgPrefixes) { - this.urlPkgPrefixes = urlPkgPrefixes; - return asBuilder(); - } - - public B setUserName(final String userName) { - this.userName = userName; - return asBuilder(); - } - - /** - * Does not include the password. - */ - @Override - public String toString() { - return "Builder [name=" + getName() + ", factoryName=" + factoryName + ", providerUrl=" + providerUrl - + ", urlPkgPrefixes=" + urlPkgPrefixes + ", securityPrincipalName=" + securityPrincipalName - + ", securityCredentials=" + securityCredentials + ", factoryBindingName=" + factoryBindingName - + ", destinationBindingName=" + destinationBindingName + ", username=" + userName + ", layout=" - + getLayout() + ", filter=" + getFilter() + ", ignoreExceptions=" + isIgnoreExceptions() - + ", jmsManager=" + jmsManager + "]"; - } - - } - - @PluginFactory - public static Builder newBuilder() { - return new Builder(); - } - - private final JmsManager manager; - - /** - * @param name The Appender's name. - * @param filter The filter to attach to the Appender, if any. - * @param layout The layout to use to render the event. - * @param ignoreExceptions true if exceptions should be ignore, false otherwise. - * @param properties TODO - * @param manager The JMSManager. - * @throws JMSException - * not thrown as of 2.9 but retained in the signature for compatibility, will be removed in 3.0. - */ - protected JmsAppender(final String name, final Filter filter, final Layout layout, - final boolean ignoreExceptions, final Property[] properties, final JmsManager manager) throws JMSException { - super(name, filter, layout, ignoreExceptions, properties); - this.manager = manager; - } - - @Override - public void append(final LogEvent event) { - this.manager.send(event, getLayout()); - } - - public JmsManager getManager() { - return manager; - } - - @Override - public boolean stop(final long timeout, final TimeUnit timeUnit) { - setStopping(); - boolean stopped = super.stop(timeout, timeUnit, false); - stopped &= this.manager.stop(timeout, timeUnit); - setStopped(); - return stopped; - } - -} diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsManager.java deleted file mode 100644 index d000fb615e..0000000000 --- a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsManager.java +++ /dev/null @@ -1,477 +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.jms.appender; - -import java.util.Properties; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.naming.NamingException; - -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AbstractManager; -import org.apache.logging.log4j.core.appender.AppenderLoggingException; -import org.apache.logging.log4j.core.appender.ManagerFactory; -import org.apache.logging.log4j.core.util.Log4jThread; -import org.apache.logging.log4j.jndi.JndiManager; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * Consider this class <b>private</b>; it is only <b>public</b> for access by integration tests. - * - * <p> - * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects - * involving a configured ConnectionFactory and Destination. - * </p> - */ -public class JmsManager extends AbstractManager { - - public static class JmsManagerConfiguration { - private final Properties jndiProperties; - private final String connectionFactoryName; - private final String destinationName; - private final String userName; - private final char[] password; - private final boolean immediateFail; - private final boolean retry; - private final long reconnectIntervalMillis; - - JmsManagerConfiguration(final Properties jndiProperties, final String connectionFactoryName, - final String destinationName, final String userName, final char[] password, final boolean immediateFail, - final long reconnectIntervalMillis) { - this.jndiProperties = jndiProperties; - this.connectionFactoryName = connectionFactoryName; - this.destinationName = destinationName; - this.userName = userName; - this.password = password; - this.immediateFail = immediateFail; - this.reconnectIntervalMillis = reconnectIntervalMillis; - this.retry = reconnectIntervalMillis > 0; - } - - public String getConnectionFactoryName() { - return connectionFactoryName; - } - - public String getDestinationName() { - return destinationName; - } - - public JndiManager getJndiManager() { - return JndiManager.getJndiManager(getJndiProperties()); - } - - public Properties getJndiProperties() { - return jndiProperties; - } - - public char[] getPassword() { - return password; - } - - public long getReconnectIntervalMillis() { - return reconnectIntervalMillis; - } - - public String getUserName() { - return userName; - } - - public boolean isImmediateFail() { - return immediateFail; - } - - public boolean isRetry() { - return retry; - } - - @Override - public String toString() { - return "JmsManagerConfiguration [jndiProperties=" + jndiProperties + ", connectionFactoryName=" - + connectionFactoryName + ", destinationName=" + destinationName + ", userName=" + userName - + ", immediateFail=" + immediateFail + ", retry=" + retry + ", reconnectIntervalMillis=" - + reconnectIntervalMillis + "]"; - } - - } - - private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsManagerConfiguration> { - - @Override - public JmsManager createManager(final String name, final JmsManagerConfiguration data) { - try { - return new JmsManager(name, data); - } catch (final Exception e) { - logger().error("Error creating JmsManager using JmsManagerConfiguration [{}]", data, e); - return null; - } - } - } - - /** - * Creates the JNDI properties. Keeps caller from being dependent on JndiManager. - * @param factoryName - * Fully qualified class name of an implementation of {@link javax.naming.spi.InitialContextFactory}. - * @param providerUrl - * The provider URL to use for the JNDI connection (specific to the above factory). - * @param urlPkgPrefixes - * A colon-separated list of package prefixes for the class name of the factory class that will create a - * URL context factory - * @param securityPrincipal - * The name of the identity of the Principal. - * @param securityCredentials - * The security credentials of the Principal. - * @param additionalProperties - * Any additional JNDI environment properties to set or {@code null} for none. - * @return the Properties for the provided parameters. - */ - public static Properties createJndiProperties(final String factoryName, final String providerUrl, - final String urlPkgPrefixes, final String securityPrincipal, final String securityCredentials, - final Properties additionalProperties) { - return JndiManager.createProperties(factoryName, providerUrl, urlPkgPrefixes, - securityPrincipal, securityCredentials, additionalProperties); - } - - /** - * Handles reconnecting to JMS on a Thread. - */ - private final class Reconnector extends Log4jThread { - - private final CountDownLatch latch = new CountDownLatch(1); - - private volatile boolean shutdown; - - private final Object owner; - - private Reconnector(final Object owner) { - super("JmsManager-Reconnector"); - this.owner = owner; - } - - public void latch() { - try { - latch.await(); - } catch (final InterruptedException ex) { - // Ignore the exception. - } - } - - void reconnect() throws NamingException, JMSException { - final JndiManager jndiManager2 = getJndiManager(); - final Connection connection2 = createConnection(jndiManager2); - final Session session2 = createSession(connection2); - final Destination destination2 = createDestination(jndiManager2); - final MessageProducer messageProducer2 = createMessageProducer(session2, destination2); - connection2.start(); - synchronized (owner) { - jndiManager = jndiManager2; - connection = connection2; - session = session2; - destination = destination2; - messageProducer = messageProducer2; - reconnector = null; - shutdown = true; - } - logger().debug("Connection reestablished to {}", configuration); - } - - @Override - public void run() { - while (!shutdown) { - try { - sleep(configuration.getReconnectIntervalMillis()); - reconnect(); - } catch (final InterruptedException | JMSException | NamingException e) { - logger().debug("Cannot reestablish JMS connection to {}: {}", configuration, e.getLocalizedMessage(), - e); - } finally { - latch.countDown(); - } - } - } - - public void shutdown() { - shutdown = true; - } - - } - - static final JmsManagerFactory FACTORY = new JmsManagerFactory(); - - /** - * Gets a JmsManager using the specified configuration parameters. - * - * @param name The name to use for this JmsManager. - * @param jndiProperties JNDI properties. - * @param connectionFactoryName The binding name for the {@link javax.jms.ConnectionFactory}. - * @param destinationName The binding name for the {@link javax.jms.Destination}. - * @param userName The userName to connect with or {@code null} for no authentication. - * @param password The password to use with the given userName or {@code null} for no authentication. - * @param immediateFail Whether or not to fail immediately with a {@link AppenderLoggingException} when - * connecting to JMS fails. - * @param reconnectIntervalMillis How to log sleep in milliseconds before trying to reconnect to JMS. - * @return The JmsManager as configured. - */ - public static JmsManager getJmsManager(final String name, final Properties jndiProperties, - final String connectionFactoryName, final String destinationName, final String userName, - final char[] password, final boolean immediateFail, final long reconnectIntervalMillis) { - final JmsManagerConfiguration configuration = new JmsManagerConfiguration(jndiProperties, connectionFactoryName, - destinationName, userName, password, immediateFail, reconnectIntervalMillis); - return getManager(name, FACTORY, configuration); - } - - private final JmsManagerConfiguration configuration; - - private volatile Reconnector reconnector; - private volatile JndiManager jndiManager; - private volatile Connection connection; - private volatile Session session; - private volatile Destination destination; - private volatile MessageProducer messageProducer; - - private JmsManager(final String name, final JmsManagerConfiguration configuration) { - super(null, name); - this.configuration = configuration; - this.jndiManager = configuration.getJndiManager(); - try { - this.connection = createConnection(this.jndiManager); - this.session = createSession(this.connection); - this.destination = createDestination(this.jndiManager); - this.messageProducer = createMessageProducer(this.session, this.destination); - this.connection.start(); - } catch (NamingException | JMSException e) { - this.reconnector = createReconnector(); - this.reconnector.start(); - } - } - - private boolean closeConnection() { - if (connection == null) { - return true; - } - final Connection temp = connection; - connection = null; - try { - temp.close(); - return true; - } catch (final JMSException e) { - StatusLogger.getLogger().debug( - "Caught exception closing JMS Connection: {} ({}); continuing JMS manager shutdown", - e.getLocalizedMessage(), temp, e); - return false; - } - } - - private boolean closeJndiManager() { - if (jndiManager == null) { - return true; - } - final JndiManager tmp = jndiManager; - jndiManager = null; - tmp.close(); - return true; - } - - private boolean closeMessageProducer() { - if (messageProducer == null) { - return true; - } - final MessageProducer temp = messageProducer; - messageProducer = null; - try { - temp.close(); - return true; - } catch (final JMSException e) { - StatusLogger.getLogger().debug( - "Caught exception closing JMS MessageProducer: {} ({}); continuing JMS manager shutdown", - e.getLocalizedMessage(), temp, e); - return false; - } - } - - private boolean closeSession() { - if (session == null) { - return true; - } - final Session temp = session; - session = null; - try { - temp.close(); - return true; - } catch (final JMSException e) { - StatusLogger.getLogger().debug( - "Caught exception closing JMS Session: {} ({}); continuing JMS manager shutdown", - e.getLocalizedMessage(), temp, e); - return false; - } - } - - private Connection createConnection(final JndiManager jndiManager) throws NamingException, JMSException { - final ConnectionFactory connectionFactory = jndiManager.lookup(configuration.getConnectionFactoryName()); - if (configuration.getUserName() != null && configuration.getPassword() != null) { - return connectionFactory.createConnection(configuration.getUserName(), - configuration.getPassword() == null ? null : String.valueOf(configuration.getPassword())); - } - return connectionFactory.createConnection(); - - } - - private Destination createDestination(final JndiManager jndiManager) throws NamingException { - return jndiManager.lookup(configuration.getDestinationName()); - } - - private void createMessageAndSend(final LogEvent event, final Layout layout) throws JMSException { - final var eventMessage = event.getMessage(); - final Message message; - if (eventMessage instanceof org.apache.logging.log4j.message.MapMessage<?, ?>) { - message = map((org.apache.logging.log4j.message.MapMessage<?, ?>) eventMessage, session.createMapMessage()); - } else if (layout != null) { - message = session.createTextMessage(layout.toSerializable(event)); - } else { - throw new UnsupportedOperationException("Unable to create a JMS message without a layout defined"); - } - message.setJMSTimestamp(event.getTimeMillis()); - messageProducer.send(message); - } - - /** - * Creates a MessageConsumer on this Destination using the current Session. - * - * @return A MessageConsumer on this Destination. - * @throws JMSException if an error occurs. - */ - public MessageConsumer createMessageConsumer() throws JMSException { - return this.session.createConsumer(this.destination); - } - - /** - * Creates a MessageProducer on this Destination using the current Session. - * - * @param session - * The JMS Session to use to create the MessageProducer - * @param destination - * The JMS Destination for the MessageProducer - * @return A MessageProducer on this Destination. - * @throws JMSException if an error occurs. - */ - public MessageProducer createMessageProducer(final Session session, final Destination destination) - throws JMSException { - return session.createProducer(destination); - } - - private Reconnector createReconnector() { - final Reconnector recon = new Reconnector(this); - recon.setDaemon(true); - recon.setPriority(Thread.MIN_PRIORITY); - return recon; - } - - private Session createSession(final Connection connection) throws JMSException { - return connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - - public JmsManagerConfiguration getJmsManagerConfiguration() { - return configuration; - } - - JndiManager getJndiManager() { - return configuration.getJndiManager(); - } - - <T> T lookup(final String destinationName) throws NamingException { - return this.jndiManager.lookup(destinationName); - } - - private MapMessage map(final org.apache.logging.log4j.message.MapMessage<?, ?> log4jMapMessage, - final MapMessage jmsMapMessage) { - // Map without calling org.apache.logging.log4j.message.MapMessage#getData() which makes a copy of the map. - log4jMapMessage.forEach((key, value) -> { - try { - jmsMapMessage.setObject(key, value); - } catch (final JMSException e) { - throw new IllegalArgumentException(String.format("%s mapping key '%s' to value '%s': %s", - e.getClass(), key, value, e.getLocalizedMessage()), e); - } - }); - return jmsMapMessage; - } - - @Override - protected boolean releaseSub(final long timeout, final TimeUnit timeUnit) { - if (reconnector != null) { - reconnector.shutdown(); - reconnector.interrupt(); - reconnector = null; - } - boolean closed = false; - closed &= closeJndiManager(); - closed &= closeMessageProducer(); - closed &= closeSession(); - closed &= closeConnection(); - return closed && this.jndiManager.stop(timeout, timeUnit); - } - - void send(final LogEvent event, final Layout layout) { - if (messageProducer == null) { - if (reconnector != null && !configuration.isImmediateFail()) { - reconnector.latch(); - if (messageProducer == null) { - throw new AppenderLoggingException( - "Error sending to JMS Manager '" + getName() + "': JMS message producer not available"); - } - } - } - synchronized (this) { - try { - createMessageAndSend(event, layout); - } catch (final JMSException causeEx) { - if (configuration.isRetry() && reconnector == null) { - reconnector = createReconnector(); - try { - closeJndiManager(); - reconnector.reconnect(); - } catch (NamingException | JMSException reconnEx) { - logger().debug("Cannot reestablish JMS connection to {}: {}; starting reconnector thread {}", - configuration, reconnEx.getLocalizedMessage(), reconnector.getName(), reconnEx); - reconnector.start(); - throw new AppenderLoggingException( - String.format("JMS exception sending to %s for %s", getName(), configuration), causeEx); - } - try { - createMessageAndSend(event, layout); - } catch (final JMSException e) { - throw new AppenderLoggingException( - String.format("Error sending to %s after reestablishing JMS connection for %s", getName(), - configuration), - causeEx); - } - } - } - } - } - -} diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/package-info.java deleted file mode 100644 index da03b25969..0000000000 --- a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/package-info.java +++ /dev/null @@ -1,28 +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. - */ - -/** - * Message oriented middleware appenders. - * - * @since 2.1 - */ -@Export -@Version("1.0.0") -package org.apache.logging.log4j.jms.appender; - -import org.osgi.annotation.bundle.Export; -import org.osgi.annotation.versioning.Version; diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java deleted file mode 100644 index afc2f74aec..0000000000 --- a/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java +++ /dev/null @@ -1,190 +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.jms.appender; - -import java.util.Map; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.MapMessage; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.impl.Log4jLogEvent; -import org.apache.logging.log4j.core.impl.Log4jPropertyKey; -import org.apache.logging.log4j.core.test.categories.Appenders; -import org.apache.logging.log4j.core.test.junit.LoggerContextRule; -import org.apache.logging.log4j.jndi.test.junit.JndiRule; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.message.SimpleMessage; -import org.apache.logging.log4j.message.StringMapMessage; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.RuleChain; - -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -@Category(Appenders.Jms.class) -public class JmsAppenderTest { - - private static final String CONNECTION_FACTORY_NAME = "jms/connectionFactory"; - private static final String QUEUE_FACTORY_NAME = "jms/queues"; - private static final String TOPIC_FACTORY_NAME = "jms/topics"; - private static final String DESTINATION_NAME = "jms/destination"; - private static final String DESTINATION_NAME_ML = "jms/destination-ml"; - private static final String QUEUE_NAME = "jms/queue"; - private static final String TOPIC_NAME = "jms/topic"; - private static final String LOG_MESSAGE = "Hello, world!"; - - private final ConnectionFactory connectionFactory = mock(ConnectionFactory.class); - private final Connection connection = mock(Connection.class); - private final Session session = mock(Session.class); - private final Destination destination = mock(Destination.class); - private final Destination destinationMl = mock(Destination.class); - private final MessageProducer messageProducer = mock(MessageProducer.class); - private final MessageProducer messageProducerMl = mock(MessageProducer.class); - private final TextMessage textMessage = mock(TextMessage.class); - private final ObjectMessage objectMessage = mock(ObjectMessage.class); - private final MapMessage mapMessage = mock(MapMessage.class); - - private final JndiRule jndiRule = new JndiRule(createBindings()); - private final LoggerContextRule ctx = new LoggerContextRule("src/test/resources/JmsAppenderTest.xml"); - - @Rule - public RuleChain rules = RuleChain.outerRule(jndiRule).around(ctx); - - @BeforeClass - public static void beforeClass() throws Exception { - System.setProperty(Log4jPropertyKey.JNDI_ENABLE_JMS.getSystemKey(), "true"); - } - - public JmsAppenderTest() throws Exception { - // this needs to set up before LoggerContextRule - given(connectionFactory.createConnection()).willReturn(connection); - given(connectionFactory.createConnection(anyString(), anyString())).willThrow(IllegalArgumentException.class); - given(connection.createSession(eq(false), eq(Session.AUTO_ACKNOWLEDGE))).willReturn(session); - given(session.createProducer(eq(destination))).willReturn(messageProducer); - given(session.createProducer(eq(destinationMl))).willReturn(messageProducerMl); - given(session.createTextMessage(anyString())).willReturn(textMessage); - given(session.createMapMessage()).willReturn(mapMessage); - } - - private Map<String, Object> createBindings() { - return Map.of( - CONNECTION_FACTORY_NAME, connectionFactory, - DESTINATION_NAME, destination, - DESTINATION_NAME_ML, destinationMl, - QUEUE_FACTORY_NAME, connectionFactory, - QUEUE_NAME, destination, - TOPIC_FACTORY_NAME, connectionFactory, - TOPIC_NAME, destination - ); - } - - private Log4jLogEvent createLogEvent() { - return createLogEvent(new SimpleMessage(LOG_MESSAGE)); - } - - private Log4jLogEvent createLogEvent(final Message message) { - // @formatter:off - return Log4jLogEvent.newBuilder() - .setLoggerName(JmsAppenderTest.class.getName()) - .setLoggerFqcn(JmsAppenderTest.class.getName()) - .setLevel(Level.INFO) - .setMessage(message) - .build(); - // @formatter:on - } - - private Log4jLogEvent createMapMessageLogEvent() { - final StringMapMessage mapMessage = new StringMapMessage(); - return createLogEvent(mapMessage.with("testMesage", LOG_MESSAGE)); - } - - @Before - public void setUp() throws Exception { - // we have 4 appenders all connecting to the same ConnectionFactory - then(connection).should(times(4)).start(); - } - - @Test - public void testAppendToQueue() throws Exception { - final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender"); - final LogEvent event = createLogEvent(); - appender.append(event); - then(session).should().createTextMessage(eq(LOG_MESSAGE)); - then(textMessage).should().setJMSTimestamp(anyLong()); - then(messageProducer).should().send(textMessage); - appender.stop(); - then(session).should().close(); - then(connection).should().close(); - } - - @Test - public void testAppendToQueueWithMessageLayout() throws Exception { - final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender-MessageLayout"); - final LogEvent event = createMapMessageLogEvent(); - appender.append(event); - then(session).should().createMapMessage(); - then(mapMessage).should().setJMSTimestamp(anyLong()); - then(messageProducerMl).should().send(mapMessage); - appender.stop(); - then(session).should().close(); - then(connection).should().close(); - } - - @Test - public void testJmsQueueAppenderCompatibility() throws Exception { - final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender"); - final LogEvent expected = createLogEvent(); - appender.append(expected); - then(session).should().createTextMessage(eq(expected.getMessage().getFormat())); - then(textMessage).should().setJMSTimestamp(anyLong()); - then(messageProducer).should().send(textMessage); - appender.stop(); - then(session).should().close(); - then(connection).should().close(); - } - - @Test - public void testJmsTopicAppenderCompatibility() throws Exception { - final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsTopicAppender"); - final LogEvent expected = createLogEvent(); - appender.append(expected); - then(session).should().createTextMessage(eq(expected.getMessage().getFormat())); - then(textMessage).should().setJMSTimestamp(anyLong()); - then(messageProducer).should().send(textMessage); - appender.stop(); - then(session).should().close(); - then(connection).should().close(); - } - -} diff --git a/log4j-jms/src/test/resources/JmsAppenderTest.xml b/log4j-jms/src/test/resources/JmsAppenderTest.xml deleted file mode 100644 index 9fbfb86886..0000000000 --- a/log4j-jms/src/test/resources/JmsAppenderTest.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<Configuration name="JmsAppenderTest" status="OFF"> - <Appenders> - <JMS name="JmsAppender" - factoryBindingName="jms/connectionFactory" - destinationBindingName="jms/destination"> - <PatternLayout pattern="%m"/> - </JMS> - <JMS name="JmsAppender-MessageLayout" - factoryBindingName="jms/connectionFactory" - destinationBindingName="jms/destination-ml"/> - <!-- backwards compatibility tests --> - <JMSQueue name="JmsQueueAppender" - factoryBindingName="jms/queues" - queueBindingName="jms/queue"> - <PatternLayout pattern="%m"/> - </JMSQueue> - <JMSTopic name="JmsTopicAppender" - factoryBindingName="jms/topics" - topicBindingName="jms/topic"> - <PatternLayout pattern="%m"/> - </JMSTopic> - </Appenders> - <Loggers> - <Root level="info"> - <AppenderRef ref="JmsQueueAppender"/> - </Root> - </Loggers> -</Configuration> diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index 4fb9129835..61a4feedfd 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -96,7 +96,6 @@ <!-- ===================================================== Direct dependency version properties (in alphabetical order) ===================================================== --> - <activemq.version>5.18.2</activemq.version> <angus-activation.version>2.0.1</angus-activation.version> <angus-mail.version>2.0.2</angus-mail.version> <assertj.version>3.24.2</assertj.version> @@ -137,7 +136,6 @@ <javax-activation.version>1.2.0</javax-activation.version> <javax-inject.version>1</javax-inject.version> <javax-jaxb.version>2.3.1</javax-jaxb.version> - <javax-jms.version>2.0.1</javax-jms.version> <javax-mail.version>1.6.2</javax-mail.version> <javax-persistence.version>2.2</javax-persistence.version> <javax-servlet.version>4.0.1</javax-servlet.version> @@ -310,13 +308,6 @@ <scope>import</scope> </dependency> - - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-broker</artifactId> - <version>${activemq.version}</version> - </dependency> - <dependency> <groupId>org.eclipse.angus</groupId> <artifactId>angus-activation</artifactId> @@ -715,12 +706,6 @@ <version>${javax-inject.version}</version> </dependency> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <version>${javax-jms.version}</version> - </dependency> - <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> diff --git a/pom.xml b/pom.xml index 107eccc629..4737881f96 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,6 @@ <module>log4j-jdbc</module> <module>log4j-jdbc-dbcp2</module> <module>log4j-jeromq</module> - <module>log4j-jms</module> <module>log4j-jndi</module> <module>log4j-jndi-test</module> <module>log4j-jpa</module> @@ -451,12 +450,6 @@ <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jms</artifactId> - <version>${project.version}</version> - </dependency> - <!-- JNDI --> <dependency> <groupId>org.apache.logging.log4j</groupId> diff --git a/src/site/asciidoc/manual/appenders.adoc b/src/site/asciidoc/manual/appenders.adoc index bc70d6b75d..529bf523a5 100644 --- a/src/site/asciidoc/manual/appenders.adoc +++ b/src/site/asciidoc/manual/appenders.adoc @@ -1253,147 +1253,6 @@ table based on a Log4j `MapMessage` instead of values from `LogEvent`s. </Configuration> ---- -[#JMSAppender] -== JMSAppender - -[[JMSQueueAppender]] [[JMSTopicAppender]] -As of Log4j 2.11.0, JPA support has moved from the existing module -`log4j-core` to the new module `log4j-jms`. - -The JMS Appender sends the formatted log event to a JMS Destination. - -The JMS Appender requires JNDI support so as of release 2.15.1 this appender will not function unless -`log4j2.enableJndi=true` is configured as a system property or environment variable. See the -link:./configuration.html#enableJndi[log4j2.enableJndi] system property. - -Note that in Log4j 2.0, this appender was split into a JMSQueueAppender -and a JMSTopicAppender. Starting in Log4j 2.1, these appenders were -combined into the JMS Appender which makes no distinction between queues -and topics. However, configurations written for 2.0 which use the -`<JMSQueue/>` or `<JMSTopic/>` elements will continue to work with the -new `<JMS/>` configuration element. - -.JMS Appender Parameters -[cols="15%,15%,15%,55%",options="header",] -|======================================================================= -|Parameter Name |Type |Default |Description -|allowdLdapClasses|String|null|A comma separated list of fully qualified class names that may be accessed by LDAP. -The classes must implement Serializable. Only applies when the JMS Appender By default only Java primative classes -are allowed. -|allowdLdapHosts|String|null|A comma separated list of host names or ip addresses that may be accessed by LDAP. -By default only the local host names and ip addresses are allowed. -|allowdJndiProtocols|String|null|A comma separated list of protocol names that JNDI will allow. By default only java, -ldap, and ldaps are the only allowed protocols. -|factoryBindingName |String |_Required_ |The name to locate in the -Context that provides the -https://download.oracle.com/javaee/5/api/javax/jms/ConnectionFactory.html[`ConnectionFactory`]. -This can be any subinterface of `ConnectionFactory` as well. - -|factoryName |String |_Required_ |The fully qualified class name that -should be used to define the Initial Context Factory as defined in -https://download.oracle.com/javase/7/docs/api/javax/naming/Context.html#INITIAL_CONTEXT_FACTORY[`INITIAL_CONTEXT_FACTORY`]. -If a factoryName is specified without a providerURL a warning message -will be logged as this is likely to cause problems. - -|filter |Filter |null |A Filter to determine if the event should be -handled by this Appender. More than one Filter may be used by using a -CompositeFilter. - -|layout |Layout |_Required_ |The Layout to use to format the LogEvent. -_New since 2.9, in previous versions SerializedLayout was default._ - -|name |String |_Required_ |The name of the Appender. - -|password |String |null |The password to use to create the JMS -connection. - -|providerURL |String |_Required_ |The URL of the provider to use as -defined by -https://download.oracle.com/javase/7/docs/api/javax/naming/Context.html#PROVIDER_URL[`PROVIDER_URL`]. - -|destinationBindingName |String |_Required_ |The name to use to locate -the -https://download.oracle.com/javaee/5/api/javax/jms/Destination.html[`Destination`]. -This can be a `Queue` or `Topic`, and as such, the attribute names -`queueBindingName` and `topicBindingName` are aliases to maintain -compatibility with the Log4j 2.0 JMS appenders. - -|securityPrincipalName |String |null |The name of the identity of the -Principal as specified by -https://download.oracle.com/javase/7/docs/api/javax/naming/Context.html#SECURITY_PRINCIPAL[`SECURITY_PRINCIPAL`]. -If a securityPrincipalName is specified without securityCredentials a -warning message will be logged as this is likely to cause problems. - -|securityCredentials |String |null |The security credentials for the -principal as specified by -https://download.oracle.com/javase/7/docs/api/javax/naming/Context.html#SECURITY_CREDENTIALS[`SECURITY_CREDENTIALS`]. - -|ignoreExceptions |boolean |true |When `true`, exceptions caught while -appending events are internally logged and then ignored. When `false` -exceptions are propagated to the caller. You must set this to `false` -when wrapping this Appender in a -link:#FailoverAppender[FailoverAppender]. - -|immediateFail |boolean |false |When set to true, log events will not -wait to try to reconnect and will fail immediately if the JMS resources -are not available. New in 2.9. - -|reconnectIntervalMillis |long |5000 |If set to a value greater than 0, -after an error, the JMSManager will attempt to reconnect to the broker -after waiting the specified number of milliseconds. If the reconnect -fails then an exception will be thrown (which can be caught by the -application if `ignoreExceptions` is set to `false`). New in 2.9. - -|urlPkgPrefixes |String |null |A colon-separated list of package -prefixes for the class name of the factory class that will create a URL -context factory as defined by -https://download.oracle.com/javase/7/docs/api/javax/naming/Context.html#URL_PKG_PREFIXES[`URL_PKG_PREFIXES`]. - -|userName |String |null |The user id used to create the JMS connection. -|======================================================================= - -Here is a sample JMS Appender configuration: - -[source,prettyprint,linenums] ----- -<?xml version="1.0" encoding="UTF-8"?> -<Configuration status="warn" name="MyApp"> - <Appenders> - <JMS name="jmsQueue" destinationBindingName="MyQueue" - factoryBindingName="MyQueueConnectionFactory"> - <JsonLayout properties="true"/> - </JMS> - </Appenders> - <Loggers> - <Root level="error"> - <AppenderRef ref="jmsQueue"/> - </Root> - </Loggers> -</Configuration> ----- - -To map your Log4j `MapMessage`s to JMS `javax.jms.MapMessage`s, set the -layout of the appender to `MessageLayout` with `<MessageLayout />` -(Since 2.9.): - -[source,prettyprint,linenums] ----- -<?xml version="1.0" encoding="UTF-8"?> -<Configuration status="warn" name="MyApp"> - <Appenders> - <JMS name="jmsQueue" destinationBindingName="MyQueue" - factoryBindingName="MyQueueConnectionFactory"> - <MessageLayout /> - </JMS> - </Appenders> - <Loggers> - <Root level="error"> - <AppenderRef ref="jmsQueue"/> - </Root> - </Loggers> -</Configuration> ----- - [#JPAAppender] == JPAAppender diff --git a/src/site/asciidoc/manual/architecture.adoc b/src/site/asciidoc/manual/architecture.adoc index 9105a3a6a8..7f6280451c 100644 --- a/src/site/asciidoc/manual/architecture.adoc +++ b/src/site/asciidoc/manual/architecture.adoc @@ -343,7 +343,7 @@ to print to multiple destinations. In log4j speak, an output destination is called an link:../log4j-core/apidocs/org/apache/logging/log4j/core/Appender.html[`Appender`]. Currently, appenders exist for the console, files, remote socket -servers, Apache Flume, JMS, remote UNIX Syslog daemons, and various +servers, Apache Flume, remote UNIX Syslog daemons, and various database APIs. See the section on link:appenders.html[Appenders] for more details on the various types available. More than one Appender can be attached to a Logger. diff --git a/src/site/asciidoc/manual/messages.adoc b/src/site/asciidoc/manual/messages.adoc index 39b7ae248e..add056bdd1 100644 --- a/src/site/asciidoc/manual/messages.adoc +++ b/src/site/asciidoc/manual/messages.adoc @@ -226,7 +226,7 @@ Otherwise, the Map will be formatted as `"key1=value1 key2=value2 ..."`. Some Appenders make special use of `MapMessage` objects: -* When a link:appenders.html#JMSAppender[JMS Appender] is configured +* When a JMS Appender is configured with a no layout, it converts a Log4j `MapMessage` to a JMS `javax.jms.MapMessage`. * When a link:appenders.html#JDBCAppender[JDBC Appender] is configured diff --git a/src/site/asciidoc/manual/systemproperties.adoc b/src/site/asciidoc/manual/systemproperties.adoc index ba83302025..4bd96ba316 100644 --- a/src/site/asciidoc/manual/systemproperties.adoc +++ b/src/site/asciidoc/manual/systemproperties.adoc @@ -709,7 +709,7 @@ JMX notifications. |NBSP |System/Application |false -|When true, the use of JNDI the JmsAppender is enabled if the log4j-jndi and log4j-jms jars are present on the +|When true, the use of JNDI the JMS Appender is enabled if the log4j-jndi and log4j-jms jars are present on the classpath. |JNDI diff --git a/src/site/asciidoc/runtime-dependencies.adoc b/src/site/asciidoc/runtime-dependencies.adoc index 1488ec103b..65361a50ee 100644 --- a/src/site/asciidoc/runtime-dependencies.adoc +++ b/src/site/asciidoc/runtime-dependencies.adoc @@ -540,9 +540,6 @@ You need to use a version of the Kafka client library matching the Kafka server |SMTP Appender |an implementation of `javax.mail` -|JMS Appender -|a JMS broker like http://activemq.apache.org/[Apache ActiveMQ] - |Windows console color support |http://jansi.fusesource.org/[Jansi] diff --git a/src/site/markdown/log4j-jms.md b/src/site/markdown/log4j-jms.md deleted file mode 100644 index 295c2d5633..0000000000 --- a/src/site/markdown/log4j-jms.md +++ /dev/null @@ -1,33 +0,0 @@ -<!-- vim: set syn=markdown : --> -<!-- - 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. ---> - -# Apache Log4j Java Message Service (JMS) module - -As of Log4j 2.11.0, JMS support has moved from the existing module log4j-core to the new module log4j-jms. - -## Requirements - -This module was introduced in Log4j 2.11.0 and requires a JMS API JAR. - -Some features may require optional -[dependencies](../runtime-dependencies.html). These dependencies are specified in the -documentation for those features. - -Some Log4j features require external dependencies. -See the [Dependency Tree](dependencies.html#Dependency_Tree) -for the exact list of JAR files needed for these features. diff --git a/src/site/markdown/log4j-jmx-gui.md b/src/site/markdown/log4j-jmx-gui.md deleted file mode 100644 index bc0077a6fc..0000000000 --- a/src/site/markdown/log4j-jmx-gui.md +++ /dev/null @@ -1,22 +0,0 @@ -<!-- vim: set syn=markdown : --> -<!-- - 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. ---> - -# Log4j JMX GUI - -[The Apache Log4j JMX GUI](https://github.com/apache/logging-log4j-jmx-gui) is a basic client GUI that can be used to monitor the `StatusLogger` output and to remotely modify the Log4j configuration. -The client GUI can be run as a stand-alone application or as a JConsole plug-in. diff --git a/src/site/markdown/manual/compatibility.md b/src/site/markdown/manual/compatibility.md index 69a1b30138..1b236301d6 100644 --- a/src/site/markdown/manual/compatibility.md +++ b/src/site/markdown/manual/compatibility.md @@ -79,7 +79,6 @@ files must have a file extension of either ".properties" or ".xml". ### Appenders * JDBCAppender (cannot be mapped to Log4j 2's JdbcAppender) -* JMSAppender * SMTPAppender * SocketAppender (Requires the use of the SerializedLayout which is a security risk) * SocketHubAppender (Requires the use of the SerializedLayout which is a securiy risk) diff --git a/src/site/site.xml b/src/site/site.xml index eaa334a9a5..64b8f3381a 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -165,7 +165,6 @@ <item name="File" href="/manual/appenders.html#FileAppender"/> <item name="Flume" href="/manual/appenders.html#FlumeAppender"/> <item name="JDBC" href="/manual/appenders.html#JDBCAppender"/> - <item name="JMS" href="/manual/appenders.html#JMSAppender"/> <item name="JPA" href="/manual/appenders.html#JPAAppender"/> <item name="HTTP" href="/manual/appenders.html#HttpAppender"/> <item name="Kafka" href="/manual/appenders.html#KafkaAppender"/> @@ -301,7 +300,7 @@ <item name="Log4j 2.x - Latest release for Java 8" href="http://logging.apache.org/log4j/2.x/"/> </menu> - <menu name="Components" inherit="top" img="img/glyphicons/cog.png"> + <menu name="Internal Components" inherit="top" img="img/glyphicons/layers.png"> <item name="API" href="log4j-api.html"/> <item name="Implementation" href="log4j-core.html"/> <item name="Commons Logging Bridge" href="log4j-jcl.html"/> @@ -313,9 +312,7 @@ <item name="JDBC Appender" href="log4j-jdbc-dbcp2.html"/> <item name="ZeroMQ Appender" href="log4j-jeromq.html"/> <item name="Apache Flume Appender" href="log4j-flume-ng.html"/> - <item name="JMS Appender" href="log4j-jms.html"/> <item name="Tag Library" href="log4j-taglib.html"/> - <item name="JMX GUI" href="log4j-jmx-gui.html"/> <item name="Web Application Support" href="log4j-web.html"/> <item name="Jakarta Web Application Support" href="log4j-jakarta-web.html"/> <item name="Application Server Integration" href="log4j-appserver.html"/> @@ -331,6 +328,13 @@ <item name="Log4j Transformation Tools" href="log4j-transform"/> </menu> + <menu name="External Components" img="img/glyphicons/link.png"> + <item name="Log4j Jakarta EE" href="/log4j/jakarta"/> + <item name="Log4j JMX GUI" href="/log4j/jmx-gui"/> + <item name="Log4j Tools" href="/log4j/tools"/> + <item name="Log4j Transformation Tools" href="/log4j/transform"/> + </menu> + <menu name="Project Information" img="img/glyphicons/info.png"> <item name="Project Team" href="/team.html" /> <item name="Project License" href="https://www.apache.org/licenses/LICENSE-2.0" />
