You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/06 06:58:34 UTC
[01/29] git commit: Branch trunk for MOM-focused log4j module.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 0e9e33156 -> 810720e0b
Branch trunk for MOM-focused log4j module.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608315 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9b71816e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9b71816e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9b71816e
Branch: refs/heads/master
Commit: 9b71816e6d78a25e052fe5bc75e869ee05e25ba5
Parents: 6d4df9d
Author: mattsicker <ma...@unknown>
Authored: Sun Jul 6 23:53:50 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Sun Jul 6 23:53:50 2014 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[10/29] git commit: Add ActiveMQ as a test dependency.
Posted by ma...@apache.org.
Add ActiveMQ as a test dependency.
- Update dependencies in log4j-mom.
- Add Proton library for AMQP (LOG4J2-701).
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608333 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b5893bc0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b5893bc0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b5893bc0
Branch: refs/heads/master
Commit: b5893bc0412882a083eb975c75c8d5a686326c29
Parents: cd76204
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 04:26:03 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 04:26:03 2014 +0000
----------------------------------------------------------------------
log4j-mom/pom.xml | 32 ++++++++++++++++++++++++++------
pom.xml | 11 +++++++++++
2 files changed, 37 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5893bc0/log4j-mom/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/pom.xml b/log4j-mom/pom.xml
index 6c3f760..c1fbbe3 100644
--- a/log4j-mom/pom.xml
+++ b/log4j-mom/pom.xml
@@ -27,6 +27,12 @@
<artifactId>jboss-jms-api_1.1_spec</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>proton-j</artifactId>
+ </dependency>
+
+ <!-- tests -->
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -37,17 +43,31 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <type>test-jar</type>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
<scope>test</scope>
</dependency>
+ <!-- integration tests -->
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.5</version>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-broker</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5893bc0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6c54144..d045e7b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -160,6 +160,7 @@
<spring.version>3.2.8.RELEASE</spring.version>
<flumeVersion>1.5.0</flumeVersion>
<disruptor.version>3.2.1</disruptor.version>
+ <activemq.version>5.10.0</activemq.version>
<!-- Configuration properties for the OSGi maven-bundle-plugin -->
<project.version.osgi>2.0.0.RC2-SNAPSHOT</project.version.osgi>
<osgi.symbolicName>org.apache.logging.${project.artifactId}</osgi.symbolicName>
@@ -493,6 +494,16 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-broker</artifactId>
+ <version>${activemq.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>proton-j</artifactId>
+ <version>0.7</version>
+ </dependency>
+ <dependency>
<groupId>org.mockejb</groupId>
<artifactId>mockejb</artifactId>
<version>0.6-beta2</version>
[15/29] git commit: Merge branch 'master' into messaging-module
Posted by ma...@apache.org.
Merge branch 'master' into messaging-module
Conflicts:
log4j-core/pom.xml
pom.xml
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e1db6e23
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e1db6e23
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e1db6e23
Branch: refs/heads/master
Commit: e1db6e23ce32956d744ea29ad492134b48806c84
Parents: 6befe58 1167a72
Author: Matt Sicker <bo...@gmail.com>
Authored: Sat Aug 30 17:14:10 2014 -0500
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sat Aug 30 17:14:10 2014 -0500
----------------------------------------------------------------------
.gitignore | 4 +
BUILDING.txt | 4 +-
RELEASE-NOTES.txt | 103 +--
checkstyle-suppressions.xml | 8 +
checkstyle.xml | 1 -
log4j-1.2-api/.gitignore | 4 +
log4j-1.2-api/pom.xml | 6 +-
.../src/main/java/org/apache/log4j/Layout.java | 13 +-
.../apache/log4j/BasicConfigurationFactory.java | 2 +
.../test/java/org/apache/log4j/LoggerTest.java | 2 +
log4j-api/.gitignore | 4 +
log4j-api/pom.xml | 8 +-
.../org/apache/logging/log4j/LogManager.java | 53 +-
.../java/org/apache/logging/log4j/Logger.java | 80 +-
.../org/apache/logging/log4j/ThreadContext.java | 106 +--
.../message/ExtendedThreadInformation.java | 28 +-
.../logging/log4j/message/FormattedMessage.java | 8 +-
.../logging/log4j/message/MapMessage.java | 5 +
.../logging/log4j/message/ObjectMessage.java | 22 +-
.../log4j/message/ParameterizedMessage.java | 52 +-
.../log4j/message/StructuredDataMessage.java | 31 +-
.../logging/log4j/message/package-info.java | 2 +-
.../org/apache/logging/log4j/package-info.java | 2 +-
.../logging/log4j/spi/AbstractLogger.java | 842 +------------------
.../log4j/spi/DefaultThreadContextMap.java | 42 -
.../log4j/spi/DefaultThreadContextStack.java | 152 ++--
.../log4j/spi/MutableThreadContextStack.java | 41 +
.../org/apache/logging/log4j/spi/Provider.java | 92 +-
.../logging/log4j/spi/ThreadContextMap.java | 10 +-
.../logging/log4j/spi/ThreadContextStack.java | 2 +-
.../logging/log4j/status/package-info.java | 2 +-
.../apache/logging/log4j/util/Activator.java | 108 +++
.../apache/logging/log4j/util/LoaderUtil.java | 59 ++
.../logging/log4j/util/PropertiesUtil.java | 68 +-
.../apache/logging/log4j/util/ProviderUtil.java | 60 +-
.../org/apache/logging/log4j/util/Strings.java | 22 +
.../java/org/apache/log4j/util/SerialUtil.java | 65 ++
.../log4j/message/FormattedMessageTest.java | 25 +
.../log4j/message/LocalizedMessageTest.java | 24 +
.../logging/log4j/message/MapMessageTest.java | 18 +
.../log4j/message/MessageFormatMessageTest.java | 25 +
.../apache/logging/log4j/message/Mutable.java | 34 +
.../log4j/message/ObjectMessageTest.java | 51 ++
.../log4j/message/ParameterizedMessageTest.java | 12 +
.../message/StringFormattedMessageTest.java | 25 +
.../message/StructuredDataMessageTest.java | 19 +
.../log4j/message/ThreadDumpMessageTest.java | 16 +
.../spi/DefaultThreadContextStackTest.java | 50 +-
.../spi/MutableThreadContextStackTest.java | 83 +-
log4j-bom/.gitignore | 2 +
log4j-bom/pom.xml | 39 +-
log4j-core/.gitignore | 4 +
log4j-core/LOG4J2-807.log | 24 +
log4j-core/pom.xml | 9 +-
.../logging/log4j/core/AbstractLifeCycle.java | 6 +-
.../org/apache/logging/log4j/core/Appender.java | 31 +-
.../org/apache/logging/log4j/core/Filter.java | 4 +-
.../org/apache/logging/log4j/core/Layout.java | 2 +
.../apache/logging/log4j/core/LifeCycle.java | 11 +-
.../logging/log4j/core/LifeCycleState.java | 33 -
.../org/apache/logging/log4j/core/LogEvent.java | 20 +-
.../logging/log4j/core/LogEventListener.java | 1 +
.../org/apache/logging/log4j/core/Logger.java | 10 +
.../logging/log4j/core/LoggerContext.java | 60 +-
.../log4j/core/appender/AbstractAppender.java | 3 +
.../appender/AbstractOutputStreamAppender.java | 2 +
.../log4j/core/appender/AsyncAppender.java | 2 +
.../log4j/core/appender/ConsoleAppender.java | 6 +-
.../log4j/core/appender/FailoverAppender.java | 4 +-
.../log4j/core/appender/FileAppender.java | 3 +-
.../core/appender/RandomAccessFileAppender.java | 4 +-
.../core/appender/RollingFileAppender.java | 2 +
.../RollingRandomAccessFileAppender.java | 2 +
.../log4j/core/appender/SmtpAppender.java | 1 +
.../log4j/core/appender/SocketAppender.java | 5 +-
.../log4j/core/appender/SyslogAppender.java | 3 +-
.../appender/db/AbstractDatabaseAppender.java | 4 +-
.../appender/db/AbstractDatabaseManager.java | 19 +-
.../core/appender/db/jdbc/JdbcAppender.java | 2 +
.../appender/db/jdbc/JdbcDatabaseManager.java | 29 +-
.../log4j/core/appender/db/jpa/JpaAppender.java | 2 +
.../log4j/core/appender/package-info.java | 2 +-
.../core/appender/rewrite/RewriteAppender.java | 3 +
.../appender/rolling/RollingFileManager.java | 2 +-
.../rolling/action/FileRenameAction.java | 6 +-
.../core/appender/routing/RoutingAppender.java | 3 +-
.../logging/log4j/core/async/AsyncLogger.java | 7 +-
.../log4j/core/async/AsyncLoggerConfig.java | 8 +-
.../core/async/AsyncLoggerConfigHelper.java | 3 +
.../log4j/core/async/AsyncLoggerContext.java | 2 +
.../log4j/core/async/RingBufferLogEvent.java | 5 -
.../core/config/AbstractConfiguration.java | 16 +-
.../log4j/core/config/AppenderControl.java | 2 +
.../logging/log4j/core/config/AppenderRef.java | 2 +-
.../log4j/core/config/ConfigurationFactory.java | 12 +-
.../log4j/core/config/DefaultConfiguration.java | 2 +
.../logging/log4j/core/config/LoggerConfig.java | 37 +-
.../log4j/core/config/NullConfiguration.java | 1 +
.../core/config/json/JsonConfiguration.java | 8 +-
.../log4j/core/config/json/package-info.java | 20 +
.../logging/log4j/core/config/package-info.java | 2 +-
.../log4j/core/config/plugins/Plugin.java | 5 +
.../core/config/plugins/osgi/Activator.java | 94 ---
.../core/config/plugins/osgi/package-info.java | 21 -
.../config/plugins/processor/package-info.java | 2 +-
.../core/config/plugins/util/PluginManager.java | 164 +++-
.../core/config/plugins/util/ResolverUtil.java | 5 +-
.../log4j/core/config/xml/XmlConfiguration.java | 36 +-
.../log4j/core/config/xml/package-info.java | 20 +
.../core/config/yaml/YamlConfiguration.java | 2 +
.../log4j/core/config/yaml/package-info.java | 20 +
.../log4j/core/filter/AbstractFilter.java | 2 +
.../log4j/core/filter/AbstractFilterable.java | 2 +
.../logging/log4j/core/filter/BurstFilter.java | 2 +
.../log4j/core/filter/CompositeFilter.java | 2 +
.../core/filter/DynamicThresholdFilter.java | 3 +
.../logging/log4j/core/filter/MapFilter.java | 3 +
.../logging/log4j/core/filter/MarkerFilter.java | 2 +
.../logging/log4j/core/filter/RegexFilter.java | 76 +-
.../log4j/core/filter/StructuredDataFilter.java | 2 +
.../core/filter/ThreadContextMapFilter.java | 2 +
.../log4j/core/filter/ThresholdFilter.java | 2 +
.../logging/log4j/core/filter/TimeFilter.java | 3 +
.../logging/log4j/core/filter/package-info.java | 2 +-
.../log4j/core/impl/Log4jContextFactory.java | 20 +-
.../logging/log4j/core/impl/Log4jLogEvent.java | 55 +-
.../logging/log4j/core/impl/ThrowableProxy.java | 7 +-
.../logging/log4j/core/impl/package-info.java | 2 +-
.../log4j/core/jackson/package-info.java | 21 +
.../log4j/core/jmx/ContextSelectorAdmin.java | 2 +-
.../log4j/core/jmx/LoggerConfigAdmin.java | 4 +-
.../apache/logging/log4j/core/jmx/Server.java | 6 +-
.../log4j/core/jmx/StatusLoggerAdminMBean.java | 6 +-
.../logging/log4j/core/jmx/package-info.java | 2 +-
.../log4j/core/layout/PatternLayout.java | 4 +-
.../logging/log4j/core/layout/package-info.java | 2 +-
.../log4j/core/lookup/ContextMapLookup.java | 2 +-
.../logging/log4j/core/lookup/DateLookup.java | 6 +-
.../logging/log4j/core/lookup/Interpolator.java | 26 +-
.../lookup/JmxRuntimeInputArgumentsLookup.java | 36 +
.../logging/log4j/core/lookup/JndiLookup.java | 21 +-
.../logging/log4j/core/lookup/MapLookup.java | 116 ++-
.../log4j/core/lookup/ResourceBundleLookup.java | 20 +-
.../logging/log4j/core/lookup/StrLookup.java | 19 +-
.../log4j/core/lookup/StrSubstitutor.java | 63 +-
.../log4j/core/lookup/StructuredDataLookup.java | 6 +-
.../core/lookup/SystemPropertiesLookup.java | 16 +-
.../logging/log4j/core/lookup/package-info.java | 2 +-
.../logging/log4j/core/net/package-info.java | 2 +-
.../core/net/ssl/KeyStoreConfiguration.java | 2 +-
.../core/net/ssl/TrustStoreConfiguration.java | 2 +-
.../log4j/core/net/ssl/package-info.java | 2 +-
.../logging/log4j/core/osgi/Activator.java | 82 ++
.../logging/log4j/core/osgi/package-info.java | 21 +
.../apache/logging/log4j/core/package-info.java | 2 +-
.../core/pattern/DatePatternConverter.java | 27 +-
.../log4j/core/pattern/PatternParser.java | 4 +-
.../core/selector/JndiContextSelector.java | 5 +-
.../log4j/core/selector/package-info.java | 2 +-
.../logging/log4j/core/tools/Generate.java | 548 ++++++++++++
.../logging/log4j/core/tools/package-info.java | 20 +
.../apache/logging/log4j/core/util/Assert.java | 6 +-
.../log4j/core/util/BundleResourceLoader.java | 1 -
.../logging/log4j/core/util/Charsets.java | 32 +-
.../logging/log4j/core/util/ClockFactory.java | 3 +
.../apache/logging/log4j/core/util/Closer.java | 28 -
.../DefaultShutdownRegistrationStrategy.java | 41 +
.../logging/log4j/core/util/JndiCloser.java | 55 ++
.../apache/logging/log4j/core/util/Loader.java | 49 +-
.../log4j/core/util/OptionConverter.java | 38 +-
.../logging/log4j/core/util/SetUtils.java | 9 +-
.../core/util/ShutdownRegistrationStrategy.java | 61 ++
.../logging/log4j/core/util/UuidUtil.java | 2 +-
.../logging/log4j/core/util/package-info.java | 2 +-
log4j-core/src/site/resources/images/logo.jpg | Bin 8184 -> 0 bytes
.../src/site/resources/images/ls-logo.jpg | Bin 32725 -> 0 bytes
log4j-core/src/site/xdoc/index.xml | 7 +-
.../DebugDisabledPerformanceComparison.java | 270 ------
.../apache/logging/log4j/LocationPerfCheck.java | 49 --
.../logging/log4j/Log4jInitPerformance.java | 57 --
.../log4j/core/BasicConfigurationFactory.java | 1 +
.../apache/logging/log4j/core/LoggerTest.java | 13 +
.../log4j/core/TimestampMessageTest.java | 93 ++
.../ConsoleAppenderNoAnsiStyleLayoutMain.java | 2 +
.../core/appender/ConsoleAppenderTest.java | 1 -
.../log4j/core/appender/Jira739Test.java | 55 ++
.../core/appender/ProgressConsoleTest.java | 20 +-
.../db/AbstractDatabaseAppenderTest.java | 3 +
.../db/jdbc/AbstractJdbcAppenderTest.java | 1 -
.../appender/db/jdbc/JdbcH2AppenderTest.java | 1 -
.../appender/routing/RoutingAppenderTest.java | 2 +-
.../async/AsyncLoggerThreadContextTest.java | 76 ++
.../async/AsyncLoggerTimestampMessageTest.java | 101 +++
.../log4j/core/async/AsyncRootReloadTest.java | 44 +
.../core/async/RingBufferLogEventTest.java | 56 --
.../core/async/perftest/PerfTestDriver.java | 3 +-
.../logging/log4j/core/config/XIncludeTest.java | 138 +++
.../plugins/util/PluginManagerPackagesTest.java | 114 +++
.../log4j/core/filter/RegexFilterTest.java | 38 +-
.../log4j/core/impl/ReflectionComparison.java | 113 ---
.../impl/ReflectiveCallerClassUtilityTest.java | 43 +
.../log4j/core/layout/PatternLayoutTest.java | 22 +-
.../log4j/core/lookup/ContextMapLookupTest.java | 51 ++
.../lookup/MainInputArgumentsJmxLookupTest.java | 57 ++
.../lookup/MainInputArgumentsMapLookup.java | 41 +
.../log4j/core/lookup/MapLookupTest.java | 67 ++
.../net/server/AbstractSocketServerTest.java | 4 +-
.../core/pattern/DatePatternConverterTest.java | 133 +++
.../log4j/core/pattern/PatternParserTest.java | 29 +-
.../core/tools/GenerateCustomLoggerTest.java | 136 +++
.../core/tools/GenerateExtendedLoggerTest.java | 156 ++++
.../log4j/core/util/CachedClockTest.java | 36 -
.../log4j/core/util/StandardCharsetsTest.java | 71 ++
.../logging/log4j/test/AvailablePortFinder.java | 2 +-
.../log4j/test/appender/AlwaysFailAppender.java | 2 +
.../log4j/test/appender/FailOnceAppender.java | 2 +
.../log4j/test/appender/InMemoryAppender.java | 2 +
.../log4j/test/appender/ListAppender.java | 4 +-
.../test/appender/UsesLoggingAppender.java | 4 +-
.../resources/AsyncLoggerThreadContextTest.xml | 17 +
.../AsyncLoggerTimestampMessageTest.xml | 17 +
.../src/test/resources/ContextMapLookupTest.xml | 29 +
log4j-core/src/test/resources/LOG4J2-739.xml | 28 +
log4j-core/src/test/resources/LOG4J2-807.xml | 15 +
.../test/resources/bad/log4j-badfilename.xml | 4 +-
.../test/resources/bad/log4j-badfilterparam.xml | 4 +-
.../src/test/resources/bad/log4j-badlayout.xml | 4 +-
.../src/test/resources/bad/log4j-loggers.xml | 4 +-
.../src/test/resources/bad/log4j-nofilter.xml | 8 +-
.../src/test/resources/bad/log4j-status.xml | 4 +-
.../customplugin/FixedStringLayout.java.source | 54 ++
.../test/resources/customplugin/log4j2-741.xml | 29 +
.../src/test/resources/log4j-filetest.xml | 4 +-
.../src/test/resources/log4j-rolling2.xml | 8 +-
log4j-core/src/test/resources/log4j-strict1.xml | 8 +-
log4j-core/src/test/resources/log4j-test2.xml | 17 +-
.../src/test/resources/log4j-threaded.xml | 4 +-
.../src/test/resources/log4j-xinclude.xml | 8 +-
log4j-core/src/test/resources/log4j12-perf.xml | 4 +-
log4j-core/src/test/resources/log4j12-perf2.xml | 31 -
log4j-core/src/test/resources/log4j2-319.xml | 4 +-
log4j-core/src/test/resources/log4j2-744.xml | 31 +
.../log4j2-console-highlight-default.xml | 4 +-
.../log4j2-console-highlight-logback.xml | 4 +-
.../test/resources/log4j2-console-highlight.xml | 4 +-
.../resources/log4j2-console-style-ansi.xml | 4 +-
.../log4j2-console-style-name-ansi.xml | 4 +-
.../resources/log4j2-console-style-no-ansi.xml | 2 +-
.../src/test/resources/log4j2-console.xml | 4 +-
.../src/test/resources/log4j2-perf-filter.xml | 4 +-
log4j-core/src/test/resources/log4j2-perf.xml | 4 +-
log4j-core/src/test/resources/log4j2-perf2.xml | 32 -
log4j-core/src/test/resources/logback-flume.xml | 4 +-
.../src/test/resources/logback-perf-filter.xml | 4 +-
log4j-core/src/test/resources/logback-perf.xml | 4 +-
log4j-core/src/test/resources/logback-perf2.xml | 29 -
log4j-core/src/test/resources/logback-subst.xml | 4 +-
log4j-distribution/pom.xml | 2 +-
log4j-flume-ng/.gitignore | 4 +
log4j-flume-ng/pom.xml | 6 +-
.../log4j/flume/appender/FlumeAppender.java | 3 +-
log4j-flume-ng/src/site/xdoc/index.xml | 243 ------
log4j-flume-ng/src/site/xdoc/index.xml.vm | 244 ++++++
log4j-jcl/.gitignore | 4 +
log4j-jcl/pom.xml | 6 +-
log4j-jcl/src/site/xdoc/index.xml | 6 +-
.../apache/logging/log4j/jcl/LoggerTest.java | 1 -
log4j-jmx-gui/.gitignore | 4 +
log4j-jmx-gui/pom.xml | 6 +-
.../mom/jms/appender/JmsQueueAppender.java | 2 +
.../mom/jms/appender/JmsTopicAppender.java | 4 +-
.../log4j/mom/jms/appender/JmsQueueTest.java | 3 +
.../log4j/mom/jms/appender/JmsTopicTest.java | 3 +
log4j-nosql/.gitignore | 4 +
log4j-nosql/pom.xml | 101 ++-
.../log4j/nosql/appender/NoSqlAppender.java | 1 +
log4j-nosql/src/site/xdoc/index.xml | 81 --
log4j-nosql/src/site/xdoc/index.xml.vm | 85 ++
log4j-perf/.gitignore | 4 +
log4j-perf/pom.xml | 10 +-
.../logging/log4j/perf/jmh/ClocksBenchmark.java | 139 +++
.../jmh/ConfiguratorInitializeBenchmark.java | 72 ++
.../log4j/perf/jmh/DebugDisabledBenchmark.java | 107 +++
.../perf/jmh/FormatterLoggerBenchmark.java | 136 +++
.../log4j/perf/jmh/Log4jLogEventBenchmark.java | 55 +-
.../log4j/perf/jmh/ReflectionBenchmark.java | 106 +++
.../log4j/perf/jmh/TimeFormatBenchmark.java | 253 ++++++
.../log4j/perf/jmh/UuidGeneratorBenchmark.java | 51 ++
.../logging/log4j/perf/jmh/package-info.java | 23 +
log4j-perf/src/main/resources/log4j12-perf2.xml | 31 +
log4j-perf/src/main/resources/log4j2-perf2.xml | 32 +
log4j-perf/src/main/resources/logback-perf2.xml | 29 +
log4j-samples/.gitignore | 2 +
log4j-samples/flume-common/.gitignore | 4 +
log4j-samples/flume-common/pom.xml | 2 +-
.../logging/log4j/samples/util/NamingUtils.java | 6 +-
log4j-samples/flume-embedded/.gitignore | 4 +
log4j-samples/flume-embedded/pom.xml | 2 +-
log4j-samples/flume-remote/.gitignore | 4 +
log4j-samples/flume-remote/pom.xml | 2 +-
log4j-samples/pom.xml | 2 +-
log4j-slf4j-impl/.gitignore | 4 +
log4j-slf4j-impl/pom.xml | 6 +-
.../org/apache/logging/slf4j/Log4jLogger.java | 10 +-
.../org/apache/logging/slf4j/Log4jMarker.java | 6 +-
.../logging/slf4j/Log4jMarkerFactory.java | 66 +-
log4j-slf4j-impl/src/site/xdoc/index.xml | 6 +-
.../apache/logging/slf4j/CustomFlatMarker.java | 76 ++
.../org/apache/logging/slf4j/LoggerTest.java | 53 +-
.../src/test/resources/log4j-test1.xml | 2 +-
log4j-streams/pom.xml | 212 +++++
.../logging/log4j/streams/ByteStreamLogger.java | 150 ++++
.../logging/log4j/streams/CharStreamLogger.java | 110 +++
.../streams/LoggerBufferedInputStream.java | 105 +++
.../log4j/streams/LoggerBufferedReader.java | 92 ++
.../log4j/streams/LoggerInputStream.java | 92 ++
.../log4j/streams/LoggerOutputStream.java | 126 +++
.../log4j/streams/LoggerPrintStream.java | 273 ++++++
.../log4j/streams/LoggerPrintWriter.java | 247 ++++++
.../logging/log4j/streams/LoggerReader.java | 96 +++
.../logging/log4j/streams/LoggerStreams.java | 166 ++++
.../logging/log4j/streams/LoggerWriter.java | 122 +++
.../log4j/streams/helpers/ByteStreamLogger.java | 150 ++++
.../log4j/streams/helpers/CharStreamLogger.java | 110 +++
...LoggerBufferedInputStreamCallerInfoTest.java | 66 ++
.../streams/LoggerBufferedInputStreamTest.java | 29 +
.../LoggerBufferedReaderCallerInfoTest.java | 84 ++
.../log4j/streams/LoggerBufferedReaderTest.java | 41 +
.../LoggerInputStreamCallerInfoTest.java | 54 ++
.../log4j/streams/LoggerInputStreamTest.java | 127 +++
.../LoggerOutputStreamCallerInfoTest.java | 50 ++
.../log4j/streams/LoggerOutputStreamTest.java | 125 +++
.../LoggerPrintStreamCallerInfoTest.java | 145 ++++
.../log4j/streams/LoggerPrintStreamTest.java | 116 +++
.../LoggerPrintWriterCallerInfoTest.java | 145 ++++
.../log4j/streams/LoggerPrintWriterTest.java | 118 +++
.../streams/LoggerReaderCallerInfoTest.java | 57 ++
.../logging/log4j/streams/LoggerReaderTest.java | 141 ++++
.../streams/LoggerStreamsCallerInfoTesting.java | 51 ++
.../logging/log4j/streams/LoggerWriterTest.java | 124 +++
.../logging/log4j/streams/StreamTesting.java | 61 ++
.../resources/log4j2-streams-calling-info.xml | 30 +
.../test/resources/log4j2-streams-unit-test.xml | 30 +
log4j-taglib/.gitignore | 4 +
log4j-taglib/pom.xml | 4 +-
log4j-to-slf4j/.gitignore | 4 +
log4j-to-slf4j/pom.xml | 7 +-
log4j-web/.gitignore | 4 +
log4j-web/pom.xml | 101 ++-
.../log4j/web/Log4jWebInitializerImpl.java | 35 +-
.../logging/log4j/web/Log4jWebSupport.java | 6 +-
.../log4j/web/WebLoggerContextUtils.java | 112 +++
.../log4j/web/appender/ServletAppender.java | 5 +-
.../logging/log4j/web/TestAsyncServlet.java | 60 ++
pom.xml | 64 +-
src/changes/announcement.vm | 170 +++-
src/changes/changes.xml | 173 +++-
src/site/apt/download.apt.vm | 5 +-
src/site/pdf.xml | 5 +-
src/site/resources/images/logo.jpg | Bin 24805 -> 14818 bytes
src/site/site.vm | 2 +-
src/site/site.xml | 9 +-
src/site/xdoc/build.xml.vm | 14 +-
src/site/xdoc/faq.xml | 10 +-
src/site/xdoc/index.xml | 6 +-
src/site/xdoc/javadoc.xml | 8 +
src/site/xdoc/manual/api.xml | 22 +-
src/site/xdoc/manual/appenders.xml | 2 -
src/site/xdoc/manual/architecture.xml | 76 +-
src/site/xdoc/manual/async.xml | 20 +
src/site/xdoc/manual/configuration.xml.vm | 17 +-
src/site/xdoc/manual/customloglevels.xml.vm | 233 +++++
src/site/xdoc/manual/extending.xml | 40 +-
src/site/xdoc/manual/index.xml | 25 +-
src/site/xdoc/manual/jmx.xml | 172 ----
src/site/xdoc/manual/jmx.xml.vm | 172 ++++
src/site/xdoc/manual/layouts.xml.vm | 56 +-
src/site/xdoc/manual/logsep.xml | 2 +-
src/site/xdoc/manual/lookups.xml | 9 +-
src/site/xdoc/manual/messages.xml | 4 +-
src/site/xdoc/manual/migration.xml | 4 +-
src/site/xdoc/manual/plugins.xml | 90 +-
src/site/xdoc/manual/webapp.xml | 144 ++--
383 files changed, 11840 insertions(+), 3355 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/log4j-core/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --cc log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
index aa4fd95,0000000..4a544e4
mode 100644,000000..100644
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
@@@ -1,111 -1,0 +1,113 @@@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsQueueManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Queue.
+ */
+@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
+public final class JmsQueueAppender extends AbstractAppender {
+
++ private static final long serialVersionUID = 1L;
++
+ private final JmsQueueManager manager;
+
+ private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsQueueManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ *
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsQueueAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The user ID to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsQueueAppender.
+ */
+ @PluginFactory
+ public static JmsQueueAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("queueBindingName") final String queueBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --cc log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
index 6b1e16f,0000000..1b000ce
mode 100644,000000..100644
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
@@@ -1,112 -1,0 +1,114 @@@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsTopicManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Topic.
+ */
+@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
+public final class JmsTopicAppender extends AbstractAppender {
+
++ private static final long serialVersionUID = 1L;
++
+ private final JmsTopicManager manager;
+
+ private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsTopicManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ * <p/>
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsTopicAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsTopicAppender.
+ */
+ @PluginFactory
+ public static JmsTopicAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("topicBindingName") final String topicBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filters") final Filter filter,
++ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
----------------------------------------------------------------------
diff --cc log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
index 7a61efa,0000000..a36e148
mode 100644,000000..100644
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
@@@ -1,144 -1,0 +1,147 @@@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueTest {
+
+ private static final String FACTORY_NAME = "TestQueueConnectionFactory";
+ private static final String QUEUE_NAME = "TestQueue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsQueueTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ QUEUE_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
++
++ private static final long serialVersionUID = 1L;
++
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
----------------------------------------------------------------------
diff --cc log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
index 6781b75,0000000..890f929
mode 100644,000000..100644
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
@@@ -1,144 -1,0 +1,147 @@@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsTopicTest {
+
+ private static final String FACTORY_NAME = "TestTopicConnectionFactory";
+ private static final String TOPIC_NAME = "TestTopic";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsTopicTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
+ context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ TOPIC_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console =
+ ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
++
++ private static final long serialVersionUID = 1L;
++
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e1db6e23/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index d045e7b,29b05af..2d0b1e5
--- a/pom.xml
+++ b/pom.xml
@@@ -153,22 -154,15 +154,22 @@@
<slf4j.version>1.7.7</slf4j.version>
<logback.version>1.0.13</logback.version>
<log4jParentDir>${basedir}</log4jParentDir>
- <Log4jReleaseVersion>2.0-rc2</Log4jReleaseVersion>
- <Log4jReleaseCount>thirteenth</Log4jReleaseCount>
+ <Log4jReleaseVersion>2.0.2</Log4jReleaseVersion>
+ <Log4jReleaseCount>sixteenth</Log4jReleaseCount>
<jackson1.version>1.9.13</jackson1.version>
- <jackson2.version>2.4.1</jackson2.version>
+ <jackson2.version>2.4.2</jackson2.version>
<spring.version>3.2.8.RELEASE</spring.version>
- <flumeVersion>1.5.0.1</flumeVersion>
- <disruptor.version>3.3.0</disruptor.version>
- <pmd.plugin.version>3.2</pmd.plugin.version>
- <findbugs.plugin.version>2.5.5</findbugs.plugin.version>
+ <flumeVersion>1.5.0</flumeVersion>
+ <disruptor.version>3.2.1</disruptor.version>
+ <activemq.version>5.10.0</activemq.version>
+ <!-- Configuration properties for the OSGi maven-bundle-plugin -->
+ <project.version.osgi>2.0.0.RC2-SNAPSHOT</project.version.osgi>
+ <osgi.symbolicName>org.apache.logging.${project.artifactId}</osgi.symbolicName>
+ <osgi.export>org.apache.logging.log4j.*;version=${project.version};-noimport:=true</osgi.export>
+ <osgi.import>*</osgi.import>
+ <osgi.dynamicImport />
+ <osgi.private />
+ <pmd.plugin.version>3.1</pmd.plugin.version>
<changes.plugin.version>2.9</changes.plugin.version>
<javadoc.plugin.version>2.9.1</javadoc.plugin.version>
<surefire.plugin.version>2.17</surefire.plugin.version>
@@@ -1000,7 -994,7 +1011,8 @@@
<module>log4j-nosql</module>
<module>log4j-web</module>
<module>log4j-perf</module>
+ <module>log4j-mom</module>
+ <module>log4j-streams</module>
</modules>
<profiles>
<profile>
[20/29] git commit: Fix usage of Closer to JndiCloser.
Posted by ma...@apache.org.
Fix usage of Closer to JndiCloser.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c396b0fa
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c396b0fa
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c396b0fa
Branch: refs/heads/master
Commit: c396b0fa3d8879537e440df8bbd9767efe547ff8
Parents: 89304e8
Author: Matt Sicker <ma...@apache.org>
Authored: Sat Aug 30 17:42:11 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sat Aug 30 17:42:11 2014 -0500
----------------------------------------------------------------------
.../org/apache/logging/log4j/mom/jms/manager/JndiManager.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c396b0fa/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
index f56e28f..873b7f4 100644
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
@@ -24,7 +24,7 @@ import javax.naming.NamingException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.appender.AbstractManager;
import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.core.util.JndiCloser;
import org.apache.logging.log4j.status.StatusLogger;
/**
@@ -94,7 +94,7 @@ public class JndiManager extends AbstractManager {
@Override
protected void releaseSub() {
- Closer.closeSilently(this.context);
+ JndiCloser.closeSilently(this.context);
}
/**
[29/29] git commit: Merge branch 'messaging-module'
Posted by ma...@apache.org.
Merge branch 'messaging-module'
Conflicts:
log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueFailoverTest.java
log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicFailoverTest.java
pom.xml
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/810720e0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/810720e0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/810720e0
Branch: refs/heads/master
Commit: 810720e0b151e0537042ac92fa9091958fd6c9f6
Parents: 0e9e331 f4721c2
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:58:12 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:58:12 2014 -0500
----------------------------------------------------------------------
log4j-core/pom.xml | 7 -
.../core/appender/jms/JmsQueueAppender.java | 113 ---------
.../core/appender/jms/JmsTopicAppender.java | 114 ---------
.../log4j/core/appender/jms/package-info.java | 20 --
.../core/config/plugins/PluginAliases.java | 4 +-
.../log4j/core/net/jms/AbstractJmsManager.java | 155 ------------
.../log4j/core/net/jms/AbstractJmsReceiver.java | 83 -------
.../log4j/core/net/jms/JmsQueueManager.java | 237 -------------------
.../log4j/core/net/jms/JmsQueueReceiver.java | 107 ---------
.../log4j/core/net/jms/JmsTopicManager.java | 237 -------------------
.../log4j/core/net/jms/JmsTopicReceiver.java | 105 --------
.../log4j/core/net/jms/package-info.java | 25 --
.../core/net/jms/JmsQueueAppenderTest.java | 83 -------
.../core/net/jms/JmsQueueFailoverTest.java | 119 ----------
.../log4j/core/net/jms/JmsQueueTest.java | 145 ------------
.../core/net/jms/JmsTopicFailoverTest.java | 118 ---------
.../log4j/core/net/jms/JmsTopicTest.java | 146 ------------
.../test/resources/log4j-jmsqueue-failover.xml | 52 ----
.../src/test/resources/log4j-jmsqueue.xml | 30 ---
.../test/resources/log4j-jmstopic-failover.xml | 52 ----
log4j-jms/pom.xml | 69 ++++++
.../logging/log4j/jms/appender/JmsAppender.java | 198 ++++++++++++++++
.../log4j/jms/appender/package-info.java | 20 ++
.../logging/log4j/jms/manager/JmsManager.java | 169 +++++++++++++
.../logging/log4j/jms/manager/JndiManager.java | 125 ++++++++++
.../log4j/jms/receiver/AbstractJmsReceiver.java | 82 +++++++
.../log4j/jms/receiver/JmsQueueReceiver.java | 106 +++++++++
.../log4j/jms/receiver/JmsTopicReceiver.java | 104 ++++++++
.../log4j/jms/receiver/package-info.java | 25 ++
.../log4j/jms/appender/JmsAppenderIT.java | 126 ++++++++++
.../log4j/jms/appender/JmsAppenderTest.java | 138 +++++++++++
.../src/test/resources/JmsAppenderTest.xml | 43 ++++
pom.xml | 7 +
33 files changed, 1214 insertions(+), 1950 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/810720e0/log4j-core/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/810720e0/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index d379dc0,591aeb5..a36f802
--- a/pom.xml
+++ b/pom.xml
@@@ -183,6 -186,6 +183,7 @@@
<projectDir />
<commons.logging.version>1.2</commons.logging.version>
<osgi.api.version>4.3.1</osgi.api.version>
++ <activemq.version>5.10.0</activemq.version>
</properties>
<pluginRepositories>
<pluginRepository>
@@@ -1006,7 -1006,8 +1012,8 @@@
<module>log4j-nosql</module>
<module>log4j-web</module>
<module>log4j-perf</module>
+ <module>log4j-iostreams</module>
+ <module>log4j-jms</module>
- <module>log4j-streams</module>
</modules>
<profiles>
<profile>
[11/29] git commit: Add JNDI manager class for use with JMS.
Posted by ma...@apache.org.
Add JNDI manager class for use with JMS.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608335 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/30ef6923
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/30ef6923
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/30ef6923
Branch: refs/heads/master
Commit: 30ef69234b84fe202d8f5caac31d83eac780d846
Parents: b5893bc
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 04:38:07 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 04:38:07 2014 +0000
----------------------------------------------------------------------
.../log4j/mom/jms/manager/JndiManager.java | 105 +++++++++++++++++++
1 file changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/30ef6923/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
new file mode 100644
index 0000000..9399540
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
@@ -0,0 +1,105 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JNDI context manager. Mainly useful for finding JMS objects and configuring the InitialContext.
+ */
+public class JndiManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
+
+ private final Context context;
+
+ private JndiManager(String name, Context context) {
+ super(name);
+ this.context = context;
+ }
+
+ public static JndiManager getJndiManager(final String initialContextFactoryName,
+ final String providerURL,
+ final String urlPkgPrefixes,
+ final String securityPrincipal,
+ final String securityCredentials,
+ final Properties additionalProperties) {
+ final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
+ if (initialContextFactoryName == null) {
+ return getManager(name, FACTORY, null);
+ }
+ final Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ properties.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
+ "provider URL. This is likely to cause problems.", initialContextFactoryName);
+ }
+ if (urlPkgPrefixes != null) {
+ properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipal != null) {
+ properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
+ if (securityCredentials != null) {
+ properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
+ securityPrincipal);
+ }
+ }
+ if (additionalProperties != null) {
+ properties.putAll(additionalProperties);
+ }
+ return getManager(name, FACTORY, properties);
+ }
+
+ @Override
+ protected void releaseSub() {
+ Closer.closeSilently(this.context);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(final String name) throws NamingException {
+ return (T) this.context.lookup(name);
+ }
+
+ private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
+
+ @Override
+ public JndiManager createManager(String name, Properties data) {
+ try {
+ return new JndiManager(name, new InitialContext(data));
+ } catch (final NamingException e) {
+ LOGGER.error("Error creating JNDI InitialContext.", e);
+ return null;
+ }
+ }
+ }
+}
[03/29] git commit: Split out JMS appender and receiver into new
log4j module.
Posted by ma...@apache.org.
Split out JMS appender and receiver into new log4j module.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608317 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1274408e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1274408e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1274408e
Branch: refs/heads/master
Commit: 1274408e2aa77557e8061c7e74979a40b7f245c9
Parents: 9b71816
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 00:13:53 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 00:13:53 2014 +0000
----------------------------------------------------------------------
.../core/appender/jms/JmsQueueAppender.java | 111 ---------
.../core/appender/jms/JmsTopicAppender.java | 112 ---------
.../log4j/core/appender/jms/package-info.java | 20 --
.../log4j/core/net/jms/AbstractJmsManager.java | 155 ------------
.../log4j/core/net/jms/AbstractJmsReceiver.java | 83 -------
.../log4j/core/net/jms/JmsQueueManager.java | 237 -------------------
.../log4j/core/net/jms/JmsQueueReceiver.java | 107 ---------
.../log4j/core/net/jms/JmsTopicManager.java | 237 -------------------
.../log4j/core/net/jms/JmsTopicReceiver.java | 105 --------
.../log4j/core/net/jms/package-info.java | 25 --
.../core/net/jms/JmsQueueAppenderTest.java | 83 -------
.../core/net/jms/JmsQueueFailoverTest.java | 122 ----------
.../log4j/core/net/jms/JmsQueueTest.java | 142 -----------
.../core/net/jms/JmsTopicFailoverTest.java | 121 ----------
.../log4j/core/net/jms/JmsTopicTest.java | 143 -----------
log4j-mom/pom.xml | 53 +++++
.../mom/jms/appender/JmsQueueAppender.java | 111 +++++++++
.../mom/jms/appender/JmsTopicAppender.java | 112 +++++++++
.../log4j/mom/jms/appender/package-info.java | 20 ++
.../mom/jms/receiver/AbstractJmsManager.java | 155 ++++++++++++
.../mom/jms/receiver/AbstractJmsReceiver.java | 83 +++++++
.../log4j/mom/jms/receiver/JmsQueueManager.java | 237 +++++++++++++++++++
.../mom/jms/receiver/JmsQueueReceiver.java | 107 +++++++++
.../log4j/mom/jms/receiver/JmsTopicManager.java | 237 +++++++++++++++++++
.../mom/jms/receiver/JmsTopicReceiver.java | 105 ++++++++
.../log4j/mom/jms/receiver/package-info.java | 25 ++
.../mom/jms/appender/JmsQueueAppenderTest.java | 85 +++++++
.../mom/jms/appender/JmsQueueFailoverTest.java | 122 ++++++++++
.../log4j/mom/jms/appender/JmsQueueTest.java | 144 +++++++++++
.../mom/jms/appender/JmsTopicFailoverTest.java | 121 ++++++++++
.../log4j/mom/jms/appender/JmsTopicTest.java | 144 +++++++++++
pom.xml | 1 +
32 files changed, 1862 insertions(+), 1803 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsQueueAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsQueueAppender.java
deleted file mode 100644
index 9b19631..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsQueueAppender.java
+++ /dev/null
@@ -1,111 +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.core.appender.jms;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.core.net.jms.JmsQueueManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Queue.
- */
-@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
-public final class JmsQueueAppender extends AbstractAppender {
-
- private final JmsQueueManager manager;
-
- private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsQueueManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- *
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsQueueAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The user ID to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsQueueAppender.
- */
- @PluginFactory
- public static JmsQueueAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("queueBindingName") final String queueBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filter") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsTopicAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsTopicAppender.java
deleted file mode 100644
index 8793a9d..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/JmsTopicAppender.java
+++ /dev/null
@@ -1,112 +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.core.appender.jms;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.core.net.jms.JmsTopicManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Topic.
- */
-@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
-public final class JmsTopicAppender extends AbstractAppender {
-
- private final JmsTopicManager manager;
-
- private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsTopicManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- * <p/>
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsTopicAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsTopicAppender.
- */
- @PluginFactory
- public static JmsTopicAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("topicBindingName") final String topicBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filters") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
-
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/package-info.java
deleted file mode 100644
index 029e2e9..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/jms/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-/**
- * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
- */
-package org.apache.logging.log4j.core.appender.jms;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsManager.java
deleted file mode 100644
index cc7d3f9..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsManager.java
+++ /dev/null
@@ -1,155 +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.core.net.jms;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.AbstractManager;
-
-/**
- * Base Class for Managers of JMS connections.
- */
-public abstract class AbstractJmsManager extends AbstractManager {
-
- /**
- * The Constructor.
- * @param name The name of the Appender.
- */
- public AbstractJmsManager(final String name) {
- super(name);
- }
-
- /**
- * Create the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return the InitialContext.
- * @throws NamingException if a naming error occurs.
- */
- protected static Context createContext(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials)
- throws NamingException {
-
- final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
- securityCredentials);
- return new InitialContext(props);
- }
-
- /**
- * Looks up the name in the context.
- * @param ctx The Context.
- * @param name The name to locate.
- * @return The object to be located.
- * @throws NamingException If an error occurs locating the name.
- */
- protected static Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- LOGGER.warn("Could not find name [{}].", name);
- throw e;
- }
- }
-
- /**
- * Sets up the properties to pass to the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return The Properties.
- */
- protected static Properties getEnvironment(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials) {
- final Properties props = new Properties();
- if (factoryName != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, factoryName);
- if (providerURL != null) {
- props.put(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
- "This is likely to cause problems");
- }
- if (urlPkgPrefixes != null) {
- props.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipalName != null) {
- props.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- props.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
- "This is likely to cause problems.");
- }
- }
- return props;
- }
- return null;
- }
-
- /**
- * Send the message.
- * @param object The Object to sent.
- * @throws Exception if an error occurs.
- */
- public abstract void send(Serializable object) throws Exception;
-
- /**
- * Send the Object.
- * @param object The Object to send.
- * @param session The Session.
- * @param producer The MessageProducer.
- * @throws Exception if an error occurs.
- */
- public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
- throws Exception {
- try {
- Message msg;
- if (object instanceof String) {
- msg = session.createTextMessage();
- ((TextMessage) msg).setText((String) object);
- } else {
- msg = session.createObjectMessage();
- ((ObjectMessage) msg).setObject(object);
- }
- producer.send(msg);
- } catch (final JMSException ex) {
- LOGGER.error("Could not publish message via JMS {}", getName());
- throw ex;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsReceiver.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsReceiver.java
deleted file mode 100644
index 5723070..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/AbstractJmsReceiver.java
+++ /dev/null
@@ -1,83 +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.core.net.jms;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.ObjectMessage;
-import javax.naming.Context;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LogEventListener;
-
-/**
- * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
- */
-public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
-
- /**
- * Logger to capture diagnostics.
- */
- protected Logger logger = LogManager.getLogger(this.getClass().getName());
-
- /**
- * Listener that receives the event.
- * @param message The received message.
- */
- @Override
- public void onMessage(final javax.jms.Message message) {
- try {
- if (message instanceof ObjectMessage) {
- final ObjectMessage objectMessage = (ObjectMessage) message;
- final Serializable object = objectMessage.getObject();
- if (object instanceof LogEvent) {
- log((LogEvent) object);
- } else {
- logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
- }
- } else {
- logger.warn("Received message is of type " + message.getJMSType()
- + ", was expecting ObjectMessage.");
- }
- } catch (final JMSException jmse) {
- logger.error("Exception thrown while processing incoming message.",
- jmse);
- }
- }
-
- /**
- * Looks up an object from the Context.
- * @param ctx The Context.
- * @param name The name of the object to locate.
- * @return The object.
- * @throws NamingException if an error occurs.
- */
- protected Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- logger.error("Could not find name [" + name + "].");
- throw e;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueManager.java
deleted file mode 100644
index 13c08f3..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueManager.java
+++ /dev/null
@@ -1,237 +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.core.net.jms;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for a JMS Queue.
- */
-public class JmsQueueManager extends AbstractJmsManager {
-
- private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
-
- private QueueInfo info;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
- private final Context context;
-
- /**
- * The Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param queueBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final QueueInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JmsQueueManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The userid to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @return The JmsQueueManager.
- */
- public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String queueBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsQueueManager");
- return null;
- }
- if (queueBindingName == null) {
- LOGGER.error("No topic name provided for JmsQueueManager");
- return null;
- }
-
- final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
- }
-
- @Override
- public synchronized void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.sender);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String queueBindingName, final String userName,
- final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static QueueInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
- QueueConnection conn;
- if (userName != null) {
- conn = factory.createQueueConnection(userName, password);
- } else {
- conn = factory.createQueueConnection();
- }
- final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) lookup(context, queueBindingName);
- final QueueSender sender = sess.createSender(queue);
- conn.start();
- return new QueueInfo(conn, sess, sender);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Queue connection information */
- private static class QueueInfo {
- private final QueueConnection conn;
- private final QueueSession session;
- private final QueueSender sender;
-
- public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
- this.conn = conn;
- this.session = session;
- this.sender = sender;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
-
- @Override
- public JmsQueueManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
- data.password, true);
- return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueReceiver.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueReceiver.java
deleted file mode 100644
index eb927ff..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsQueueReceiver.java
+++ /dev/null
@@ -1,107 +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.core.net.jms;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Log Events over a JMS Queue. This implementation expects that all messages will
- * contain a serialized LogEvent.
- */
-public class JmsQueueReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param qcfBindingName The QueueConnectionFactory binding name.
- * @param queueBindingName The Queue binding name.
- * @param username The userid to connect to the queue.
- * @param password The password to connect to the queue.
- */
- public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
- final String password) {
-
- try {
- final Context ctx = new InitialContext();
- QueueConnectionFactory queueConnectionFactory;
- queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
- final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
- queueConnection.start();
- final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) ctx.lookup(queueBindingName);
- final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
- queueReceiver.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String qcfBindingName = args[0];
- final String queueBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
- + " QueueConnectionFactoryBindingName QueueBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicManager.java
deleted file mode 100644
index f06ec06..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicManager.java
+++ /dev/null
@@ -1,237 +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.core.net.jms;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for JMS Topic connections.
- */
-public class JmsTopicManager extends AbstractJmsManager {
-
- private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
-
- private TopicInfo info;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
- private final Context context;
- /**
- * Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param topicBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
- final String topicBindingName, final String userName, final String password,
- final TopicInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JSMTopicManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @return A JmsTopicManager.
- */
- public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String topicBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsTopicManager");
- return null;
- }
- if (topicBindingName == null) {
- LOGGER.error("No topic name provided for JmsTopicManager");
- return null;
- }
-
- final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
- }
-
-
- @Override
- public void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.publisher);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String topicBindingName,
- final String userName, final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static TopicInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
- TopicConnection conn;
- if (userName != null) {
- conn = factory.createTopicConnection(userName, password);
- } else {
- conn = factory.createTopicConnection();
- }
- final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) lookup(context, queueBindingName);
- final TopicPublisher publisher = sess.createPublisher(topic);
- conn.start();
- return new TopicInfo(conn, sess, publisher);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Topic connection information */
- private static class TopicInfo {
- private final TopicConnection conn;
- private final TopicSession session;
- private final TopicPublisher publisher;
-
- public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
- this.conn = conn;
- this.session = session;
- this.publisher = publisher;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
-
- @Override
- public JmsTopicManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
- data.password, true);
- return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicReceiver.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicReceiver.java
deleted file mode 100644
index f1422e9..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/JmsTopicReceiver.java
+++ /dev/null
@@ -1,105 +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.core.net.jms;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicSession;
-import javax.jms.TopicSubscriber;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Topic messages that contain LogEvents. This implementation expects that all messages
- * are serialized log events.
- */
-public class JmsTopicReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param tcfBindingName The TopicConnectionFactory binding name.
- * @param topicBindingName The Topic binding name.
- * @param username The userid to connect to the topic.
- * @param password The password to connect to the topic.
- */
- public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
- final String password) {
- try {
- final Context ctx = new InitialContext();
- TopicConnectionFactory topicConnectionFactory;
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
- final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
- topicConnection.start();
- final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) ctx.lookup(topicBindingName);
- final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
- topicSubscriber.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String tcfBindingName = args[0];
- final String topicBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
- + " TopicConnectionFactoryBindingName TopicBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/package-info.java
deleted file mode 100644
index 98e9e03..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/jms/package-info.java
+++ /dev/null
@@ -1,25 +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.
- */
-/**
- * Supporting network code for JMS appenders.
- * <p/>
- * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
- * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
- * the running process. Of course, use of these classes as standalone executables are entirely optional and can
- * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
- */
-package org.apache.logging.log4j.core.net.jms;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueAppenderTest.java
deleted file mode 100644
index 13f6d92..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueAppenderTest.java
+++ /dev/null
@@ -1,83 +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.core.net.jms;
-
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueAppenderTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue.xml";
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @Test
- public void testConfiguration() throws Exception {
- final LoggerContext ctx = (LoggerContext) LogManager.getContext();
- final Configuration config = ctx.getConfiguration();
- final Map<String, Appender> appenders = config.getAppenders();
- assertTrue(appenders.containsKey("JMSQueue"));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueFailoverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueFailoverTest.java
deleted file mode 100644
index 456c049..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueFailoverTest.java
+++ /dev/null
@@ -1,122 +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.core.net.jms;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueFailoverTest {
-
- private static final String FACTORY_NAME = "QueueConnectionFactory";
- private static final String QUEUE_NAME = "Log4j2Queue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueTest.java
deleted file mode 100644
index d4854c6..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsQueueTest.java
+++ /dev/null
@@ -1,142 +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.core.net.jms;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.appender.jms.JmsQueueAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- QUEUE_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicFailoverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicFailoverTest.java
deleted file mode 100644
index f0dc11a..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicFailoverTest.java
+++ /dev/null
@@ -1,121 +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.core.net.jms;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicFailoverTest {
-
- private static final String FACTORY_NAME = "TopicConnectionFactory";
- private static final String TOPIC_NAME = "Log4j2Topic";
-
- private static Context context;
-
- private static final String CONFIG = "log4j-jmstopic-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- final AbstractJmsReceiver receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicTest.java
deleted file mode 100644
index df4bf02..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/jms/JmsTopicTest.java
+++ /dev/null
@@ -1,143 +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.core.net.jms;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.appender.jms.JmsTopicAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicTest {
-
- private static final String FACTORY_NAME = "TestTopicConnectionFactory";
- private static final String TOPIC_NAME = "TestTopic";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsTopicTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- TOPIC_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console =
- ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
[06/29] git commit: Remove JMS API from log4j-core dependencies.
Posted by ma...@apache.org.
Remove JMS API from log4j-core dependencies.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608324 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d77f1bf7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d77f1bf7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d77f1bf7
Branch: refs/heads/master
Commit: d77f1bf7ea690403342a53395e20ce0a3b30c660
Parents: 0b127e9
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 01:20:20 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 01:20:20 2014 +0000
----------------------------------------------------------------------
log4j-core/pom.xml | 6 ------
1 file changed, 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d77f1bf7/log4j-core/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index 96358bf..c46a4ee 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -86,12 +86,6 @@
<artifactId>jansi</artifactId>
<optional>true</optional>
</dependency>
- <!-- Used for JMS appenders (needs an implementation of course) -->
- <dependency>
- <groupId>org.jboss.spec.javax.jms</groupId>
- <artifactId>jboss-jms-api_1.1_spec</artifactId>
- <scope>provided</scope>
- </dependency>
<!-- Required for SMTPAppender -->
<dependency>
<groupId>com.sun.mail</groupId>
[05/29] git commit: Delete empty directories.
Posted by ma...@apache.org.
Delete empty directories.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608322 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0b127e97
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0b127e97
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0b127e97
Branch: refs/heads/master
Commit: 0b127e97c0b3869bc54d0f31670f20a05efd7c14
Parents: d519427
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 00:28:35 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 00:28:35 2014 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[23/29] git commit: Delete old JMS appender classes.
Posted by ma...@apache.org.
Delete old JMS appender classes.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4827cdbb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4827cdbb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4827cdbb
Branch: refs/heads/master
Commit: 4827cdbb38391d5a840dc3edf3050e882afdc4f4
Parents: 1b66d8d
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:44:44 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:44:44 2014 -0500
----------------------------------------------------------------------
.../mom/jms/appender/JmsQueueAppender.java | 113 ---------
.../mom/jms/appender/JmsTopicAppender.java | 114 ---------
.../mom/jms/manager/AbstractJmsManager.java | 156 ------------
.../log4j/mom/jms/manager/JmsQueueManager.java | 237 -------------------
.../log4j/mom/jms/manager/JmsTopicManager.java | 237 -------------------
5 files changed, 857 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4827cdbb/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
deleted file mode 100644
index 4a544e4..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
+++ /dev/null
@@ -1,113 +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.mom.jms.appender;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsQueueManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Queue.
- */
-@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
-public final class JmsQueueAppender extends AbstractAppender {
-
- private static final long serialVersionUID = 1L;
-
- private final JmsQueueManager manager;
-
- private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsQueueManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- *
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsQueueAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The user ID to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsQueueAppender.
- */
- @PluginFactory
- public static JmsQueueAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("queueBindingName") final String queueBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filter") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4827cdbb/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
deleted file mode 100644
index 1b000ce..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
+++ /dev/null
@@ -1,114 +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.mom.jms.appender;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsTopicManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Topic.
- */
-@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
-public final class JmsTopicAppender extends AbstractAppender {
-
- private static final long serialVersionUID = 1L;
-
- private final JmsTopicManager manager;
-
- private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsTopicManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- * <p/>
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsTopicAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsTopicAppender.
- */
- @PluginFactory
- public static JmsTopicAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("topicBindingName") final String topicBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filter") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
-
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4827cdbb/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
deleted file mode 100644
index e53b175..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
+++ /dev/null
@@ -1,156 +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.mom.jms.manager;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.AbstractManager;
-
-/**
- * Base Class for Managers of JMS connections.
- */
-public abstract class AbstractJmsManager extends AbstractManager {
-
- /**
- * The Constructor.
- * @param name The name of the Appender.
- */
- public AbstractJmsManager(final String name) {
- super(name);
- }
-
- /**
- * Create the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return the InitialContext.
- * @throws NamingException if a naming error occurs.
- */
- protected static Context createContext(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials)
- throws NamingException {
-
- final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
- securityCredentials);
- return new InitialContext(props);
- }
-
- /**
- * Looks up the name in the context.
- * @param ctx The Context.
- * @param name The name to locate.
- * @return The object to be located.
- * @throws NamingException If an error occurs locating the name.
- */
- protected static Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- LOGGER.warn("Could not find name [{}].", name);
- throw e;
- }
- }
-
- /**
- * Sets up the properties to pass to the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return The Properties.
- * @see javax.naming.Context
- */
- protected static Properties getEnvironment(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials) {
- final Properties props = new Properties();
- if (factoryName != null) {
- props.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);
- if (providerURL != null) {
- props.setProperty(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
- "This is likely to cause problems");
- }
- if (urlPkgPrefixes != null) {
- props.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipalName != null) {
- props.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- props.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
- "This is likely to cause problems.");
- }
- }
- return props;
- }
- return null;
- }
-
- /**
- * Send the message.
- * @param object The Object to sent.
- * @throws Exception if an error occurs.
- */
- public abstract void send(Serializable object) throws Exception;
-
- /**
- * Send the Object.
- * @param object The Object to send.
- * @param session The Session.
- * @param producer The MessageProducer.
- * @throws Exception if an error occurs.
- */
- public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
- throws Exception {
- try {
- Message msg;
- if (object instanceof String) {
- msg = session.createTextMessage();
- ((TextMessage) msg).setText((String) object);
- } else {
- msg = session.createObjectMessage();
- ((ObjectMessage) msg).setObject(object);
- }
- producer.send(msg);
- } catch (final JMSException ex) {
- LOGGER.error("Could not publish message via JMS {}", getName());
- throw ex;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4827cdbb/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
deleted file mode 100644
index fd00c03..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.manager;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for a JMS Queue.
- */
-public class JmsQueueManager extends AbstractJmsManager {
-
- private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
-
- private QueueInfo info;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
- private final Context context;
-
- /**
- * The Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param queueBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final QueueInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JmsQueueManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The userid to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @return The JmsQueueManager.
- */
- public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String queueBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsQueueManager");
- return null;
- }
- if (queueBindingName == null) {
- LOGGER.error("No topic name provided for JmsQueueManager");
- return null;
- }
-
- final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
- }
-
- @Override
- public synchronized void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.sender);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String queueBindingName, final String userName,
- final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static QueueInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
- QueueConnection conn;
- if (userName != null) {
- conn = factory.createQueueConnection(userName, password);
- } else {
- conn = factory.createQueueConnection();
- }
- final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) lookup(context, queueBindingName);
- final QueueSender sender = sess.createSender(queue);
- conn.start();
- return new QueueInfo(conn, sess, sender);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Queue connection information */
- private static class QueueInfo {
- private final QueueConnection conn;
- private final QueueSession session;
- private final QueueSender sender;
-
- public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
- this.conn = conn;
- this.session = session;
- this.sender = sender;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
-
- @Override
- public JmsQueueManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
- data.password, true);
- return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4827cdbb/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
deleted file mode 100644
index 9f45b72..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.manager;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for JMS Topic connections.
- */
-public class JmsTopicManager extends AbstractJmsManager {
-
- private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
-
- private TopicInfo info;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
- private final Context context;
- /**
- * Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param topicBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
- final String topicBindingName, final String userName, final String password,
- final TopicInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JSMTopicManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @return A JmsTopicManager.
- */
- public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String topicBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsTopicManager");
- return null;
- }
- if (topicBindingName == null) {
- LOGGER.error("No topic name provided for JmsTopicManager");
- return null;
- }
-
- final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
- }
-
-
- @Override
- public void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.publisher);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String topicBindingName,
- final String userName, final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static TopicInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
- TopicConnection conn;
- if (userName != null) {
- conn = factory.createTopicConnection(userName, password);
- } else {
- conn = factory.createTopicConnection();
- }
- final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) lookup(context, queueBindingName);
- final TopicPublisher publisher = sess.createPublisher(topic);
- conn.start();
- return new TopicInfo(conn, sess, publisher);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Topic connection information */
- private static class TopicInfo {
- private final TopicConnection conn;
- private final TopicSession session;
- private final TopicPublisher publisher;
-
- public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
- this.conn = conn;
- this.session = session;
- this.publisher = publisher;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
-
- @Override
- public JmsTopicManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
- data.password, true);
- return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
[09/29] git commit: Move JMS log4j configuration files to appropriate
module.
Posted by ma...@apache.org.
Move JMS log4j configuration files to appropriate module.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608332 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cd762042
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cd762042
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cd762042
Branch: refs/heads/master
Commit: cd7620428795814642795bc57713da778b1f5457
Parents: a117d38
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 03:39:36 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 03:39:36 2014 +0000
----------------------------------------------------------------------
.../test/resources/log4j-jmsqueue-failover.xml | 52 --------------------
.../src/test/resources/log4j-jmsqueue.xml | 30 -----------
.../test/resources/log4j-jmstopic-failover.xml | 52 --------------------
.../test/resources/log4j-jmsqueue-failover.xml | 52 ++++++++++++++++++++
log4j-mom/src/test/resources/log4j-jmsqueue.xml | 30 +++++++++++
.../test/resources/log4j-jmstopic-failover.xml | 52 ++++++++++++++++++++
6 files changed, 134 insertions(+), 134 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
deleted file mode 100644
index 8b86750..0000000
--- a/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Queue"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-core/src/test/resources/log4j-jmsqueue.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-jmsqueue.xml b/log4j-core/src/test/resources/log4j-jmsqueue.xml
deleted file mode 100644
index 44ea169..0000000
--- a/log4j-core/src/test/resources/log4j-jmsqueue.xml
+++ /dev/null
@@ -1,30 +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="ConfigTest" status="OFF" monitorInterval="5">
- <Appenders>
- <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
- <PatternLayout pattern="%m%n"/>
- </JMSQueue>
- </Appenders>
- <Loggers>
- <Root level="error">
- <AppenderRef ref="JMSQueue"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-jmstopic-failover.xml b/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
deleted file mode 100644
index 8588f69..0000000
--- a/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Topic"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
new file mode 100644
index 0000000..8b86750
--- /dev/null
+++ b/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
@@ -0,0 +1,52 @@
+<?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 status="OFF" name="FailoverTest">
+ <Appenders>
+ <List name="List"/>
+ <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
+ ignoreExceptions="false"/>
+ <Rewrite name="Rewrite" ignoreExceptions="false">
+ <PropertiesRewritePolicy>
+ <Property name="appender">List</Property>
+ </PropertiesRewritePolicy>
+ <AppenderRef ref="Log4j2Queue"/>
+ </Rewrite>
+ <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
+ <Failovers>
+ <AppenderRef ref="List"/>
+ </Failovers>
+ </Failover>
+ </Appenders>
+
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="Failover">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="Failover"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ <AppenderRef ref="List">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="List"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-mom/src/test/resources/log4j-jmsqueue.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmsqueue.xml b/log4j-mom/src/test/resources/log4j-jmsqueue.xml
new file mode 100644
index 0000000..44ea169
--- /dev/null
+++ b/log4j-mom/src/test/resources/log4j-jmsqueue.xml
@@ -0,0 +1,30 @@
+<?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="ConfigTest" status="OFF" monitorInterval="5">
+ <Appenders>
+ <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
+ <PatternLayout pattern="%m%n"/>
+ </JMSQueue>
+ </Appenders>
+ <Loggers>
+ <Root level="error">
+ <AppenderRef ref="JMSQueue"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cd762042/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml b/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
new file mode 100644
index 0000000..8588f69
--- /dev/null
+++ b/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
@@ -0,0 +1,52 @@
+<?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 status="OFF" name="FailoverTest">
+ <Appenders>
+ <List name="List"/>
+ <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
+ ignoreExceptions="false"/>
+ <Rewrite name="Rewrite" ignoreExceptions="false">
+ <PropertiesRewritePolicy>
+ <Property name="appender">List</Property>
+ </PropertiesRewritePolicy>
+ <AppenderRef ref="Log4j2Topic"/>
+ </Rewrite>
+ <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
+ <Failovers>
+ <AppenderRef ref="List"/>
+ </Failovers>
+ </Failover>
+ </Appenders>
+
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="Failover">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="Failover"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ <AppenderRef ref="List">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="List"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
[12/29] git commit: Add javadoc for JndiManager.
Posted by ma...@apache.org.
Add javadoc for JndiManager.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608337 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/08e3f128
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/08e3f128
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/08e3f128
Branch: refs/heads/master
Commit: 08e3f128366996586cfa7706c5f8060b1ef955fd
Parents: 30ef692
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 04:43:04 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 04:43:04 2014 +0000
----------------------------------------------------------------------
.../log4j/mom/jms/manager/JndiManager.java | 22 +++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/08e3f128/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
index 9399540..f56e28f 100644
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
@@ -17,7 +17,6 @@
package org.apache.logging.log4j.mom.jms.manager;
import java.util.Properties;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -44,6 +43,19 @@ public class JndiManager extends AbstractManager {
this.context = context;
}
+ /**
+ * Gets a JndiManager with the provided configuration information.
+ *
+ * @param initialContextFactoryName 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 JndiManager for the provided parameters.
+ */
public static JndiManager getJndiManager(final String initialContextFactoryName,
final String providerURL,
final String urlPkgPrefixes,
@@ -85,6 +97,14 @@ public class JndiManager extends AbstractManager {
Closer.closeSilently(this.context);
}
+ /**
+ * Looks up a named object through this JNDI context.
+ *
+ * @param name name of the object to look up.
+ * @param <T> the type of the object.
+ * @return the named object if it could be located.
+ * @throws NamingException
+ */
@SuppressWarnings("unchecked")
public <T> T lookup(final String name) throws NamingException {
return (T) this.context.lookup(name);
[26/29] Remove mom package from hierarchy.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..55268cc
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java
@@ -0,0 +1,122 @@
+package org.apache.logging.log4j.jms.appender;
+
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+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.util.JndiCloser;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.*;
+
+public class JmsAppenderTest {
+
+ private static final String CONNECTION_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 QUEUE_NAME = "jms/queue";
+ private static final String TOPIC_NAME = "jms/topic";
+ private static final String LOG_MESSAGE = "Hello, world!";
+
+ private static Context context;
+
+ private static MockQueue destination;
+ private static MockQueue queue;
+ private static MockTopic topic;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(TOPIC_FACTORY_NAME, new TopicConnectionFactoryImpl());
+ destination = new MockQueue(DESTINATION_NAME);
+ context.rebind(DESTINATION_NAME, destination);
+ queue = new MockQueue(QUEUE_NAME);
+ context.rebind(QUEUE_NAME, queue);
+ topic = new MockTopic(TOPIC_NAME);
+ context.rebind(TOPIC_NAME, topic);
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ JndiCloser.close(context);
+ }
+
+ @Rule
+ public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
+
+ @Test
+ public void testAppendToQueue() throws Exception {
+ assertEquals(0, destination.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender");
+ final LogEvent event = createLogEvent();
+ appender.append(event);
+ assertEquals(1, destination.size());
+ final Message message = destination.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(TextMessage.class));
+ final TextMessage textMessage = (TextMessage) message;
+ assertEquals(LOG_MESSAGE, textMessage.getText());
+ }
+
+ @Test
+ public void testJmsQueueAppenderCompatibility() throws Exception {
+ assertEquals(0, queue.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender");
+ final LogEvent expected = createLogEvent();
+ appender.append(expected);
+ assertEquals(1, queue.size());
+ final Message message = queue.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(ObjectMessage.class));
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Object o = objectMessage.getObject();
+ assertThat(o, instanceOf(LogEvent.class));
+ final LogEvent actual = (LogEvent) o;
+ assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
+ }
+
+ @Test
+ public void testJmsTopicAppenderCompatibility() throws Exception {
+ assertEquals(0, topic.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsTopicAppender");
+ final LogEvent expected = createLogEvent();
+ appender.append(expected);
+ assertEquals(1, topic.size());
+ final Message message = topic.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(ObjectMessage.class));
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Object o = objectMessage.getObject();
+ assertThat(o, instanceOf(LogEvent.class));
+ final LogEvent actual = (LogEvent) o;
+ assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
+ }
+
+ private static Log4jLogEvent createLogEvent() {
+ return Log4jLogEvent.newBuilder()
+ .setLoggerName(JmsAppenderTest.class.getName())
+ .setLoggerFqcn(JmsAppenderTest.class.getName())
+ .setLevel(Level.INFO)
+ .setMessage(new SimpleMessage(LOG_MESSAGE))
+ .build();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
deleted file mode 100644
index 9ed98fa..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
+++ /dev/null
@@ -1,126 +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.mom.jms.appender;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.ObjectMessage;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-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.layout.SerializedLayout;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.mom.jms.manager.JmsManager;
-import org.apache.logging.log4j.mom.jms.manager.JndiManager;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Integration test for JmsAppender using an embedded ActiveMQ broker.
- */
-public class JmsAppenderIT {
-
- private static JmsManager jmsManager;
-
- private JmsAppender appender;
-
- @BeforeClass
- public static void setUpClass() {
- final Properties additional = new Properties();
- additional.setProperty("queue.TestQueue", "TestQueue");
- JndiManager jndiManager = JndiManager.getJndiManager(ActiveMQInitialContextFactory.class.getName(),
- "vm://localhost?broker.persistent=false", null, null, null, additional);
- jmsManager = JmsManager.getJmsManager("JmsManager", jndiManager, "ConnectionFactory", "TestQueue", null, null);
- }
-
- @AfterClass
- public static void tearDownClass() {
- jmsManager.release();
- }
-
- @Before
- public void setUp() throws Exception {
- appender = new JmsAppender("JmsAppender", null, SerializedLayout.createLayout(), true, jmsManager);
- appender.start();
- }
-
- @Test
- public void testLogToQueue() throws Exception {
- final int messageCount = 100;
- final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
- final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount);
- messageConsumer.setMessageListener(consumer);
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- for (int i = 0; i < messageCount; i++) {
- final LogEvent event = Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.ERROR,
- new SimpleMessage(messageText), null, null, null, null, Thread.currentThread().getName(), null,
- System.currentTimeMillis());
- appender.append(event);
- }
- consumer.awaitAndAssertAllMessagesConsumed();
- }
-
- private static class JmsQueueConsumer implements MessageListener {
-
- private final int messageCount;
- private final CountDownLatch countDownLatch;
- private final Collection<LogEvent> events;
-
- private JmsQueueConsumer(final int messageCount) {
- this.messageCount = messageCount;
- this.countDownLatch = new CountDownLatch(messageCount);
- this.events = new ArrayList<LogEvent>(messageCount);
- }
-
- @Override
- public void onMessage(Message message) {
- try {
- consume((ObjectMessage) message);
- } catch (JMSException e) {
- e.printStackTrace();
- }
- }
-
- private void consume(ObjectMessage message) throws JMSException {
- try {
- final LogEvent event = (LogEvent) message.getObject();
- events.add(event);
- } finally {
- countDownLatch.countDown();
- }
- }
-
- public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
- countDownLatch.await(5, TimeUnit.SECONDS);
- assertEquals(messageCount, events.size());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
deleted file mode 100644
index 743a4eb..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.apache.logging.log4j.mom.jms.appender;
-
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-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.util.JndiCloser;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.*;
-
-public class JmsAppenderTest {
-
- private static final String CONNECTION_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 QUEUE_NAME = "jms/queue";
- private static final String TOPIC_NAME = "jms/topic";
- private static final String LOG_MESSAGE = "Hello, world!";
-
- private static Context context;
-
- private static MockQueue destination;
- private static MockQueue queue;
- private static MockTopic topic;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(TOPIC_FACTORY_NAME, new TopicConnectionFactoryImpl());
- destination = new MockQueue(DESTINATION_NAME);
- context.rebind(DESTINATION_NAME, destination);
- queue = new MockQueue(QUEUE_NAME);
- context.rebind(QUEUE_NAME, queue);
- topic = new MockTopic(TOPIC_NAME);
- context.rebind(TOPIC_NAME, topic);
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- JndiCloser.close(context);
- }
-
- @Rule
- public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
-
- @Test
- public void testAppendToQueue() throws Exception {
- assertEquals(0, destination.size());
- final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender");
- final LogEvent event = createLogEvent();
- appender.append(event);
- assertEquals(1, destination.size());
- final Message message = destination.getMessageAt(0);
- assertNotNull(message);
- assertThat(message, instanceOf(TextMessage.class));
- final TextMessage textMessage = (TextMessage) message;
- assertEquals(LOG_MESSAGE, textMessage.getText());
- }
-
- @Test
- public void testJmsQueueAppenderCompatibility() throws Exception {
- assertEquals(0, queue.size());
- final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender");
- final LogEvent expected = createLogEvent();
- appender.append(expected);
- assertEquals(1, queue.size());
- final Message message = queue.getMessageAt(0);
- assertNotNull(message);
- assertThat(message, instanceOf(ObjectMessage.class));
- final ObjectMessage objectMessage = (ObjectMessage) message;
- final Object o = objectMessage.getObject();
- assertThat(o, instanceOf(LogEvent.class));
- final LogEvent actual = (LogEvent) o;
- assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
- }
-
- @Test
- public void testJmsTopicAppenderCompatibility() throws Exception {
- assertEquals(0, topic.size());
- final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsTopicAppender");
- final LogEvent expected = createLogEvent();
- appender.append(expected);
- assertEquals(1, topic.size());
- final Message message = topic.getMessageAt(0);
- assertNotNull(message);
- assertThat(message, instanceOf(ObjectMessage.class));
- final ObjectMessage objectMessage = (ObjectMessage) message;
- final Object o = objectMessage.getObject();
- assertThat(o, instanceOf(LogEvent.class));
- final LogEvent actual = (LogEvent) o;
- assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
- }
-
- private static Log4jLogEvent createLogEvent() {
- return Log4jLogEvent.newBuilder()
- .setLoggerName(JmsAppenderTest.class.getName())
- .setLoggerFqcn(JmsAppenderTest.class.getName())
- .setLevel(Level.INFO)
- .setMessage(new SimpleMessage(LOG_MESSAGE))
- .build();
- }
-
-}
\ No newline at end of file
[08/29] git commit: Move Jms*Manager classes to manager package.
Posted by ma...@apache.org.
Move Jms*Manager classes to manager package.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608330 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a117d38a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a117d38a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a117d38a
Branch: refs/heads/master
Commit: a117d38a13b978a0be13d303d8b5a72730b9167e
Parents: 91d879a
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 03:26:46 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 03:26:46 2014 +0000
----------------------------------------------------------------------
.../mom/jms/appender/JmsQueueAppender.java | 2 +-
.../mom/jms/appender/JmsTopicAppender.java | 2 +-
.../mom/jms/manager/AbstractJmsManager.java | 156 ++++++++++++
.../log4j/mom/jms/manager/JmsQueueManager.java | 237 +++++++++++++++++++
.../log4j/mom/jms/manager/JmsTopicManager.java | 237 +++++++++++++++++++
.../mom/jms/receiver/AbstractJmsManager.java | 155 ------------
.../log4j/mom/jms/receiver/JmsQueueManager.java | 237 -------------------
.../log4j/mom/jms/receiver/JmsTopicManager.java | 237 -------------------
8 files changed, 632 insertions(+), 631 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
index 284e1f6..aa4fd95 100644
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
@@ -28,7 +28,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueManager;
+import org.apache.logging.log4j.mom.jms.manager.JmsQueueManager;
import org.apache.logging.log4j.core.util.Booleans;
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
index 9985746..6b1e16f 100644
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
@@ -28,7 +28,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicManager;
+import org.apache.logging.log4j.mom.jms.manager.JmsTopicManager;
import org.apache.logging.log4j.core.util.Booleans;
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
new file mode 100644
index 0000000..e53b175
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
@@ -0,0 +1,156 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.AbstractManager;
+
+/**
+ * Base Class for Managers of JMS connections.
+ */
+public abstract class AbstractJmsManager extends AbstractManager {
+
+ /**
+ * The Constructor.
+ * @param name The name of the Appender.
+ */
+ public AbstractJmsManager(final String name) {
+ super(name);
+ }
+
+ /**
+ * Create the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return the InitialContext.
+ * @throws NamingException if a naming error occurs.
+ */
+ protected static Context createContext(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials)
+ throws NamingException {
+
+ final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
+ securityCredentials);
+ return new InitialContext(props);
+ }
+
+ /**
+ * Looks up the name in the context.
+ * @param ctx The Context.
+ * @param name The name to locate.
+ * @return The object to be located.
+ * @throws NamingException If an error occurs locating the name.
+ */
+ protected static Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ LOGGER.warn("Could not find name [{}].", name);
+ throw e;
+ }
+ }
+
+ /**
+ * Sets up the properties to pass to the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return The Properties.
+ * @see javax.naming.Context
+ */
+ protected static Properties getEnvironment(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials) {
+ final Properties props = new Properties();
+ if (factoryName != null) {
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);
+ if (providerURL != null) {
+ props.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
+ "This is likely to cause problems");
+ }
+ if (urlPkgPrefixes != null) {
+ props.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipalName != null) {
+ props.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ props.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
+ "This is likely to cause problems.");
+ }
+ }
+ return props;
+ }
+ return null;
+ }
+
+ /**
+ * Send the message.
+ * @param object The Object to sent.
+ * @throws Exception if an error occurs.
+ */
+ public abstract void send(Serializable object) throws Exception;
+
+ /**
+ * Send the Object.
+ * @param object The Object to send.
+ * @param session The Session.
+ * @param producer The MessageProducer.
+ * @throws Exception if an error occurs.
+ */
+ public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
+ throws Exception {
+ try {
+ Message msg;
+ if (object instanceof String) {
+ msg = session.createTextMessage();
+ ((TextMessage) msg).setText((String) object);
+ } else {
+ msg = session.createObjectMessage();
+ ((ObjectMessage) msg).setObject(object);
+ }
+ producer.send(msg);
+ } catch (final JMSException ex) {
+ LOGGER.error("Could not publish message via JMS {}", getName());
+ throw ex;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
new file mode 100644
index 0000000..fd00c03
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for a JMS Queue.
+ */
+public class JmsQueueManager extends AbstractJmsManager {
+
+ private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
+
+ private QueueInfo info;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+
+ /**
+ * The Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param queueBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final QueueInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JmsQueueManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The userid to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @return The JmsQueueManager.
+ */
+ public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String queueBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsQueueManager");
+ return null;
+ }
+ if (queueBindingName == null) {
+ LOGGER.error("No topic name provided for JmsQueueManager");
+ return null;
+ }
+
+ final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
+ }
+
+ @Override
+ public synchronized void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.sender);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String queueBindingName, final String userName,
+ final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static QueueInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
+ QueueConnection conn;
+ if (userName != null) {
+ conn = factory.createQueueConnection(userName, password);
+ } else {
+ conn = factory.createQueueConnection();
+ }
+ final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) lookup(context, queueBindingName);
+ final QueueSender sender = sess.createSender(queue);
+ conn.start();
+ return new QueueInfo(conn, sess, sender);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Queue connection information */
+ private static class QueueInfo {
+ private final QueueConnection conn;
+ private final QueueSession session;
+ private final QueueSender sender;
+
+ public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
+ this.conn = conn;
+ this.session = session;
+ this.sender = sender;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
+
+ @Override
+ public JmsQueueManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
+ data.password, true);
+ return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
new file mode 100644
index 0000000..9f45b72
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for JMS Topic connections.
+ */
+public class JmsTopicManager extends AbstractJmsManager {
+
+ private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
+
+ private TopicInfo info;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+ /**
+ * Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param topicBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
+ final String topicBindingName, final String userName, final String password,
+ final TopicInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JSMTopicManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @return A JmsTopicManager.
+ */
+ public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String topicBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsTopicManager");
+ return null;
+ }
+ if (topicBindingName == null) {
+ LOGGER.error("No topic name provided for JmsTopicManager");
+ return null;
+ }
+
+ final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
+ }
+
+
+ @Override
+ public void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.publisher);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String topicBindingName,
+ final String userName, final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static TopicInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
+ TopicConnection conn;
+ if (userName != null) {
+ conn = factory.createTopicConnection(userName, password);
+ } else {
+ conn = factory.createTopicConnection();
+ }
+ final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) lookup(context, queueBindingName);
+ final TopicPublisher publisher = sess.createPublisher(topic);
+ conn.start();
+ return new TopicInfo(conn, sess, publisher);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Topic connection information */
+ private static class TopicInfo {
+ private final TopicConnection conn;
+ private final TopicSession session;
+ private final TopicPublisher publisher;
+
+ public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
+ this.conn = conn;
+ this.session = session;
+ this.publisher = publisher;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
+
+ @Override
+ public JmsTopicManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
+ data.password, true);
+ return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
deleted file mode 100644
index d3ae2a3..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
+++ /dev/null
@@ -1,155 +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.mom.jms.receiver;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.AbstractManager;
-
-/**
- * Base Class for Managers of JMS connections.
- */
-public abstract class AbstractJmsManager extends AbstractManager {
-
- /**
- * The Constructor.
- * @param name The name of the Appender.
- */
- public AbstractJmsManager(final String name) {
- super(name);
- }
-
- /**
- * Create the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return the InitialContext.
- * @throws NamingException if a naming error occurs.
- */
- protected static Context createContext(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials)
- throws NamingException {
-
- final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
- securityCredentials);
- return new InitialContext(props);
- }
-
- /**
- * Looks up the name in the context.
- * @param ctx The Context.
- * @param name The name to locate.
- * @return The object to be located.
- * @throws NamingException If an error occurs locating the name.
- */
- protected static Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- LOGGER.warn("Could not find name [{}].", name);
- throw e;
- }
- }
-
- /**
- * Sets up the properties to pass to the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return The Properties.
- */
- protected static Properties getEnvironment(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials) {
- final Properties props = new Properties();
- if (factoryName != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, factoryName);
- if (providerURL != null) {
- props.put(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
- "This is likely to cause problems");
- }
- if (urlPkgPrefixes != null) {
- props.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipalName != null) {
- props.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- props.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
- "This is likely to cause problems.");
- }
- }
- return props;
- }
- return null;
- }
-
- /**
- * Send the message.
- * @param object The Object to sent.
- * @throws Exception if an error occurs.
- */
- public abstract void send(Serializable object) throws Exception;
-
- /**
- * Send the Object.
- * @param object The Object to send.
- * @param session The Session.
- * @param producer The MessageProducer.
- * @throws Exception if an error occurs.
- */
- public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
- throws Exception {
- try {
- Message msg;
- if (object instanceof String) {
- msg = session.createTextMessage();
- ((TextMessage) msg).setText((String) object);
- } else {
- msg = session.createObjectMessage();
- ((ObjectMessage) msg).setObject(object);
- }
- producer.send(msg);
- } catch (final JMSException ex) {
- LOGGER.error("Could not publish message via JMS {}", getName());
- throw ex;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
deleted file mode 100644
index 6825282..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.receiver;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for a JMS Queue.
- */
-public class JmsQueueManager extends AbstractJmsManager {
-
- private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
-
- private QueueInfo info;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
- private final Context context;
-
- /**
- * The Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param queueBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final QueueInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JmsQueueManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The userid to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @return The JmsQueueManager.
- */
- public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String queueBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsQueueManager");
- return null;
- }
- if (queueBindingName == null) {
- LOGGER.error("No topic name provided for JmsQueueManager");
- return null;
- }
-
- final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
- }
-
- @Override
- public synchronized void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.sender);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String queueBindingName, final String userName,
- final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static QueueInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
- QueueConnection conn;
- if (userName != null) {
- conn = factory.createQueueConnection(userName, password);
- } else {
- conn = factory.createQueueConnection();
- }
- final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) lookup(context, queueBindingName);
- final QueueSender sender = sess.createSender(queue);
- conn.start();
- return new QueueInfo(conn, sess, sender);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Queue connection information */
- private static class QueueInfo {
- private final QueueConnection conn;
- private final QueueSession session;
- private final QueueSender sender;
-
- public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
- this.conn = conn;
- this.session = session;
- this.sender = sender;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
-
- @Override
- public JmsQueueManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
- data.password, true);
- return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a117d38a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
deleted file mode 100644
index 08d7128..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.receiver;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for JMS Topic connections.
- */
-public class JmsTopicManager extends AbstractJmsManager {
-
- private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
-
- private TopicInfo info;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
- private final Context context;
- /**
- * Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param topicBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
- final String topicBindingName, final String userName, final String password,
- final TopicInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JSMTopicManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @return A JmsTopicManager.
- */
- public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String topicBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsTopicManager");
- return null;
- }
- if (topicBindingName == null) {
- LOGGER.error("No topic name provided for JmsTopicManager");
- return null;
- }
-
- final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
- }
-
-
- @Override
- public void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.publisher);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String topicBindingName,
- final String userName, final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static TopicInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
- TopicConnection conn;
- if (userName != null) {
- conn = factory.createTopicConnection(userName, password);
- } else {
- conn = factory.createTopicConnection();
- }
- final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) lookup(context, queueBindingName);
- final TopicPublisher publisher = sess.createPublisher(topic);
- conn.start();
- return new TopicInfo(conn, sess, publisher);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Topic connection information */
- private static class TopicInfo {
- private final TopicConnection conn;
- private final TopicSession session;
- private final TopicPublisher publisher;
-
- public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
- this.conn = conn;
- this.session = session;
- this.publisher = publisher;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
-
- @Override
- public JmsTopicManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
- data.password, true);
- return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
[04/29] git commit: Add svn:ignore properties.
Posted by ma...@apache.org.
Add svn:ignore properties.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608321 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d5194273
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d5194273
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d5194273
Branch: refs/heads/master
Commit: d51942733536a20a4543163ee8e718956b2d6405
Parents: 1274408
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 00:27:40 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 00:27:40 2014 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[13/29] git commit: Add more generic implementation of JMS plugins.
Posted by ma...@apache.org.
Add more generic implementation of JMS plugins.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608338 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/35428a95
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/35428a95
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/35428a95
Branch: refs/heads/master
Commit: 35428a952f39c570de8cd5077ef949664aeb5710
Parents: 08e3f12
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 04:53:12 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 04:53:12 2014 +0000
----------------------------------------------------------------------
.../log4j/mom/jms/appender/JmsAppender.java | 195 +++++++++++++++++++
.../log4j/mom/jms/manager/JmsManager.java | 169 ++++++++++++++++
.../log4j/mom/jms/appender/JmsAppenderIT.java | 126 ++++++++++++
.../log4j/mom/jms/appender/JmsAppenderTest.java | 79 ++++++++
.../src/test/resources/JmsAppenderTest.xml | 14 ++
5 files changed, 583 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35428a95/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
new file mode 100644
index 0000000..c98e2a1
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
@@ -0,0 +1,195 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsManager;
+import org.apache.logging.log4j.mom.jms.manager.JndiManager;
+
+/**
+ * Generic JMS appender plugin for both queues and topics.
+ */
+@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
+// TODO: use @PluginAliases to make the separated plugins work through this one
+public class JmsAppender extends AbstractAppender {
+
+ private final JmsManager manager;
+ private final MessageProducer producer;
+
+ protected JmsAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final boolean ignoreExceptions, final JmsManager manager)
+ throws JMSException {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ this.producer = this.manager.createMessageProducer();
+ }
+
+ @Override
+ public void append(LogEvent event) {
+ try {
+ final Message message = this.manager.createMessage(getLayout().toSerializable(event));
+ message.setJMSTimestamp(event.getTimeMillis());
+ this.producer.send(message);
+ } catch (JMSException e) {
+ throw new AppenderLoggingException(e);
+ }
+ }
+
+ @PluginBuilderFactory
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public static class Builder implements org.apache.logging.log4j.core.util.Builder<JmsAppender> {
+
+ @PluginBuilderAttribute
+ private String name;
+
+ @PluginBuilderAttribute
+ private String factoryName;
+
+ @PluginBuilderAttribute
+ private String providerUrl;
+
+ @PluginBuilderAttribute
+ private String urlPkgPrefixes;
+
+ @PluginBuilderAttribute
+ private String securityPrincipalName;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String securityCredentials;
+
+ @PluginBuilderAttribute
+ private String factoryBindingName;
+
+ @PluginBuilderAttribute
+ private String destinationBindingName;
+
+ @PluginBuilderAttribute
+ private String username;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String password;
+
+ @PluginElement("Layout")
+ private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
+
+ @PluginElement("Filter")
+ private Filter filter;
+
+ @PluginBuilderAttribute
+ private boolean ignoreExceptions = true;
+
+ private Builder() {
+ }
+
+ public Builder setName(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setFactoryName(final String factoryName) {
+ this.factoryName = factoryName;
+ return this;
+ }
+
+ public Builder setProviderUrl(final String providerUrl) {
+ this.providerUrl = providerUrl;
+ return this;
+ }
+
+ public Builder setUrlPkgPrefixes(final String urlPkgPrefixes) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ return this;
+ }
+
+ public Builder setSecurityPrincipalName(final String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ return this;
+ }
+
+ public Builder setSecurityCredentials(final String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ return this;
+ }
+
+ public Builder setFactoryBindingName(final String factoryBindingName) {
+ this.factoryBindingName = factoryBindingName;
+ return this;
+ }
+
+ public Builder setDestinationBindingName(final String destinationBindingName) {
+ this.destinationBindingName = destinationBindingName;
+ return this;
+ }
+
+ public Builder setUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ public Builder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public Builder setLayout(final Layout<? extends Serializable> layout) {
+ this.layout = layout;
+ return this;
+ }
+
+ public Builder setFilter(final Filter filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public Builder setIgnoreExceptions(final boolean ignoreExceptions) {
+ this.ignoreExceptions = ignoreExceptions;
+ return this;
+ }
+
+ @Override
+ public JmsAppender build() {
+ final JndiManager jndiManager = JndiManager.getJndiManager(factoryName, providerUrl, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, null);
+ final JmsManager jmsManager = JmsManager.getJmsManager(name, jndiManager, factoryBindingName,
+ destinationBindingName, username, password);
+ try {
+ return new JmsAppender(name, filter, layout, ignoreExceptions, jmsManager);
+ } catch (final JMSException e) {
+ LOGGER.error("Error creating JmsAppender [{}].", name, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35428a95/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
new file mode 100644
index 0000000..d3ce550
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
@@ -0,0 +1,169 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+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.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects
+ * involving a configured ConnectionFactory and Destination.
+ */
+public class JmsManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JmsManagerFactory FACTORY = new JmsManagerFactory();
+
+ private final JndiManager jndiManager;
+ private final Connection connection;
+ private final Session session;
+ private final Destination destination;
+
+ private JmsManager(final String name, final JndiManager jndiManager, final String connectionFactoryName,
+ final String destinationName, final String username, final String password)
+ throws NamingException, JMSException {
+ super(name);
+ this.jndiManager = jndiManager;
+ final ConnectionFactory connectionFactory = this.jndiManager.lookup(connectionFactoryName);
+ if (username != null && password != null) {
+ this.connection = connectionFactory.createConnection(username, password);
+ } else {
+ this.connection = connectionFactory.createConnection();
+ }
+ this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ this.destination = this.jndiManager.lookup(destinationName);
+ this.connection.start();
+ }
+
+ /**
+ * Gets a JmsManager using the specified configuration parameters.
+ *
+ * @param name The name to use for this JmsManager.
+ * @param jndiManager The JndiManager to look up JMS information through.
+ * @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.
+ * @return The JmsManager as configured.
+ */
+ public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
+ final String connectionFactoryName, final String destinationName,
+ final String username, final String password) {
+ final JmsConfiguration configuration = new JmsConfiguration(jndiManager, connectionFactoryName, destinationName,
+ username, password);
+ return FACTORY.createManager(name, configuration);
+ }
+
+ /**
+ * Creates a MessageConsumer on this Destination using the current Session.
+ *
+ * @return A MessageConsumer on this Destination.
+ * @throws JMSException
+ */
+ public MessageConsumer createMessageConsumer() throws JMSException {
+ return this.session.createConsumer(this.destination);
+ }
+
+ /**
+ * Creates a MessageProducer on this Destination using the current Session.
+ *
+ * @return A MessageProducer on this Destination.
+ * @throws JMSException
+ */
+ public MessageProducer createMessageProducer() throws JMSException {
+ return this.session.createProducer(this.destination);
+ }
+
+ /**
+ * Creates a TextMessage or ObjectMessage from a Serializable object. For instance, when using a text-based
+ * {@link org.apache.logging.log4j.core.Layout} such as {@link org.apache.logging.log4j.core.layout.PatternLayout},
+ * the {@link org.apache.logging.log4j.core.LogEvent} message will be serialized to a String. When using a
+ * layout such as {@link org.apache.logging.log4j.core.layout.SerializedLayout}, the LogEvent message will be
+ * serialized as a Java object.
+ *
+ * @param object The LogEvent or String message to wrap.
+ * @return A new JMS message containing the provided object.
+ * @throws JMSException
+ */
+ public Message createMessage(final Serializable object) throws JMSException {
+ if (object instanceof String) {
+ return this.session.createTextMessage((String) object);
+ } else {
+ return this.session.createObjectMessage(object);
+ }
+ }
+
+ @Override
+ protected void releaseSub() {
+ try {
+ this.session.close();
+ } catch (final JMSException ignored) {
+ }
+ try {
+ this.connection.close();
+ } catch (final JMSException ignored) {
+ }
+ this.jndiManager.release();
+ }
+
+ private static class JmsConfiguration {
+ private final JndiManager jndiManager;
+ private final String connectionFactoryName;
+ private final String destinationName;
+ private final String username;
+ private final String password;
+
+ private JmsConfiguration(JndiManager jndiManager, String connectionFactoryName, String destinationName,
+ String username, String password) {
+ this.jndiManager = jndiManager;
+ this.connectionFactoryName = connectionFactoryName;
+ this.destinationName = destinationName;
+ this.username = username;
+ this.password = password;
+ }
+ }
+
+ private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsConfiguration> {
+
+ @Override
+ public JmsManager createManager(String name, JmsConfiguration data) {
+ try {
+ return new JmsManager(name, data.jndiManager, data.connectionFactoryName, data.destinationName,
+ data.username, data.password);
+ } catch (final Exception e) {
+ LOGGER.error("Error creating JmsManager using ConnectionFactory [{}] and Destination [{}].",
+ data.connectionFactoryName, data.destinationName, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35428a95/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
new file mode 100644
index 0000000..9ed98fa
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
@@ -0,0 +1,126 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+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.layout.SerializedLayout;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.mom.jms.manager.JmsManager;
+import org.apache.logging.log4j.mom.jms.manager.JndiManager;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Integration test for JmsAppender using an embedded ActiveMQ broker.
+ */
+public class JmsAppenderIT {
+
+ private static JmsManager jmsManager;
+
+ private JmsAppender appender;
+
+ @BeforeClass
+ public static void setUpClass() {
+ final Properties additional = new Properties();
+ additional.setProperty("queue.TestQueue", "TestQueue");
+ JndiManager jndiManager = JndiManager.getJndiManager(ActiveMQInitialContextFactory.class.getName(),
+ "vm://localhost?broker.persistent=false", null, null, null, additional);
+ jmsManager = JmsManager.getJmsManager("JmsManager", jndiManager, "ConnectionFactory", "TestQueue", null, null);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ jmsManager.release();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ appender = new JmsAppender("JmsAppender", null, SerializedLayout.createLayout(), true, jmsManager);
+ appender.start();
+ }
+
+ @Test
+ public void testLogToQueue() throws Exception {
+ final int messageCount = 100;
+ final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
+ final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount);
+ messageConsumer.setMessageListener(consumer);
+ final String messageText = "Hello, World!";
+ final String loggerName = this.getClass().getName();
+ for (int i = 0; i < messageCount; i++) {
+ final LogEvent event = Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.ERROR,
+ new SimpleMessage(messageText), null, null, null, null, Thread.currentThread().getName(), null,
+ System.currentTimeMillis());
+ appender.append(event);
+ }
+ consumer.awaitAndAssertAllMessagesConsumed();
+ }
+
+ private static class JmsQueueConsumer implements MessageListener {
+
+ private final int messageCount;
+ private final CountDownLatch countDownLatch;
+ private final Collection<LogEvent> events;
+
+ private JmsQueueConsumer(final int messageCount) {
+ this.messageCount = messageCount;
+ this.countDownLatch = new CountDownLatch(messageCount);
+ this.events = new ArrayList<LogEvent>(messageCount);
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ try {
+ consume((ObjectMessage) message);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void consume(ObjectMessage message) throws JMSException {
+ try {
+ final LogEvent event = (LogEvent) message.getObject();
+ events.add(event);
+ } finally {
+ countDownLatch.countDown();
+ }
+ }
+
+ public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
+ countDownLatch.await(5, TimeUnit.SECONDS);
+ assertEquals(messageCount, events.size());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35428a95/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
new file mode 100644
index 0000000..8e54681
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
@@ -0,0 +1,79 @@
+package org.apache.logging.log4j.mom.jms.appender;
+
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+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.util.Closer;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.*;
+
+public class JmsAppenderTest {
+
+ private static final String CONNECTION_FACTORY_NAME = "jms/activemq";
+ private static final String DESTINATION_NAME = "jms/destination";
+ private static final String LOG_MESSAGE = "Hello, world!";
+
+ private static Context context;
+
+ private JmsAppender appender;
+ private static MockQueue queue;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
+ queue = new MockQueue(DESTINATION_NAME);
+ context.rebind(DESTINATION_NAME, queue);
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ Closer.closeSilently(context);
+ }
+
+ @Rule
+ public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
+
+ @Before
+ public void setUp() throws Exception {
+ appender = (JmsAppender) ctx.getAppender("JmsQueueAppender");
+ assertEquals(0, queue.size());
+ }
+
+ @Test
+ public void testAppendToQueue() throws Exception {
+ final String loggerName = this.getClass().getName();
+ final long now = System.currentTimeMillis();
+ final LogEvent event = createLogEvent(loggerName, now);
+ appender.append(event);
+ assertEquals(1, queue.size());
+ final Message message = queue.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(TextMessage.class));
+ final TextMessage textMessage = (TextMessage) message;
+ assertEquals(LOG_MESSAGE, textMessage.getText());
+ }
+
+ private static Log4jLogEvent createLogEvent(String loggerName, long now) {
+ return Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.INFO,
+ new SimpleMessage(LOG_MESSAGE), null, null, null, null, Thread.currentThread().getName(), null, now);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35428a95/log4j-mom/src/test/resources/JmsAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/JmsAppenderTest.xml b/log4j-mom/src/test/resources/JmsAppenderTest.xml
new file mode 100644
index 0000000..4997747
--- /dev/null
+++ b/log4j-mom/src/test/resources/JmsAppenderTest.xml
@@ -0,0 +1,14 @@
+<Configuration name="JmsAppenderTest" status="OFF">
+ <Appenders>
+ <JMS name="JmsQueueAppender"
+ factoryBindingName="jms/activemq"
+ destinationBindingName="jms/destination">
+ <PatternLayout pattern="%m"/>
+ </JMS>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="JmsQueueAppender"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
[02/29] Split out JMS appender and receiver into new log4j module.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/pom.xml b/log4j-mom/pom.xml
new file mode 100644
index 0000000..6c3f760
--- /dev/null
+++ b/log4j-mom/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <artifactId>log4j</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>log4j-mom</artifactId>
+ <name>Log4j 2 MOM Plugins</name>
+ <description>Message Oriented Middleware plugins for Log4j 2</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.spec.javax.jms</groupId>
+ <artifactId>jboss-jms-api_1.1_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockejb</groupId>
+ <artifactId>mockejb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
new file mode 100644
index 0000000..284e1f6
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
@@ -0,0 +1,111 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Queue.
+ */
+@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
+public final class JmsQueueAppender extends AbstractAppender {
+
+ private final JmsQueueManager manager;
+
+ private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsQueueManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ *
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsQueueAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The user ID to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsQueueAppender.
+ */
+ @PluginFactory
+ public static JmsQueueAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("queueBindingName") final String queueBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
new file mode 100644
index 0000000..9985746
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
@@ -0,0 +1,112 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Topic.
+ */
+@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
+public final class JmsTopicAppender extends AbstractAppender {
+
+ private final JmsTopicManager manager;
+
+ private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsTopicManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ * <p/>
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsTopicAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsTopicAppender.
+ */
+ @PluginFactory
+ public static JmsTopicAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("topicBindingName") final String topicBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filters") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
new file mode 100644
index 0000000..0c7a4ff
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
+ */
+package org.apache.logging.log4j.mom.jms.appender;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
new file mode 100644
index 0000000..d3ae2a3
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsManager.java
@@ -0,0 +1,155 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.AbstractManager;
+
+/**
+ * Base Class for Managers of JMS connections.
+ */
+public abstract class AbstractJmsManager extends AbstractManager {
+
+ /**
+ * The Constructor.
+ * @param name The name of the Appender.
+ */
+ public AbstractJmsManager(final String name) {
+ super(name);
+ }
+
+ /**
+ * Create the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return the InitialContext.
+ * @throws NamingException if a naming error occurs.
+ */
+ protected static Context createContext(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials)
+ throws NamingException {
+
+ final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
+ securityCredentials);
+ return new InitialContext(props);
+ }
+
+ /**
+ * Looks up the name in the context.
+ * @param ctx The Context.
+ * @param name The name to locate.
+ * @return The object to be located.
+ * @throws NamingException If an error occurs locating the name.
+ */
+ protected static Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ LOGGER.warn("Could not find name [{}].", name);
+ throw e;
+ }
+ }
+
+ /**
+ * Sets up the properties to pass to the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return The Properties.
+ */
+ protected static Properties getEnvironment(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials) {
+ final Properties props = new Properties();
+ if (factoryName != null) {
+ props.put(Context.INITIAL_CONTEXT_FACTORY, factoryName);
+ if (providerURL != null) {
+ props.put(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
+ "This is likely to cause problems");
+ }
+ if (urlPkgPrefixes != null) {
+ props.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipalName != null) {
+ props.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ props.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
+ "This is likely to cause problems.");
+ }
+ }
+ return props;
+ }
+ return null;
+ }
+
+ /**
+ * Send the message.
+ * @param object The Object to sent.
+ * @throws Exception if an error occurs.
+ */
+ public abstract void send(Serializable object) throws Exception;
+
+ /**
+ * Send the Object.
+ * @param object The Object to send.
+ * @param session The Session.
+ * @param producer The MessageProducer.
+ * @throws Exception if an error occurs.
+ */
+ public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
+ throws Exception {
+ try {
+ Message msg;
+ if (object instanceof String) {
+ msg = session.createTextMessage();
+ ((TextMessage) msg).setText((String) object);
+ } else {
+ msg = session.createObjectMessage();
+ ((ObjectMessage) msg).setObject(object);
+ }
+ producer.send(msg);
+ } catch (final JMSException ex) {
+ LOGGER.error("Could not publish message via JMS {}", getName());
+ throw ex;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
new file mode 100644
index 0000000..bf86c65
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
@@ -0,0 +1,83 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LogEventListener;
+
+/**
+ * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
+ */
+public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
+
+ /**
+ * Logger to capture diagnostics.
+ */
+ protected Logger logger = LogManager.getLogger(this.getClass().getName());
+
+ /**
+ * Listener that receives the event.
+ * @param message The received message.
+ */
+ @Override
+ public void onMessage(final javax.jms.Message message) {
+ try {
+ if (message instanceof ObjectMessage) {
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Serializable object = objectMessage.getObject();
+ if (object instanceof LogEvent) {
+ log((LogEvent) object);
+ } else {
+ logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
+ }
+ } else {
+ logger.warn("Received message is of type " + message.getJMSType()
+ + ", was expecting ObjectMessage.");
+ }
+ } catch (final JMSException jmse) {
+ logger.error("Exception thrown while processing incoming message.",
+ jmse);
+ }
+ }
+
+ /**
+ * Looks up an object from the Context.
+ * @param ctx The Context.
+ * @param name The name of the object to locate.
+ * @return The object.
+ * @throws NamingException if an error occurs.
+ */
+ protected Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ logger.error("Could not find name [" + name + "].");
+ throw e;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
new file mode 100644
index 0000000..6825282
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for a JMS Queue.
+ */
+public class JmsQueueManager extends AbstractJmsManager {
+
+ private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
+
+ private QueueInfo info;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+
+ /**
+ * The Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param queueBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final QueueInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JmsQueueManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The userid to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @return The JmsQueueManager.
+ */
+ public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String queueBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsQueueManager");
+ return null;
+ }
+ if (queueBindingName == null) {
+ LOGGER.error("No topic name provided for JmsQueueManager");
+ return null;
+ }
+
+ final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
+ }
+
+ @Override
+ public synchronized void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.sender);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String queueBindingName, final String userName,
+ final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static QueueInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
+ QueueConnection conn;
+ if (userName != null) {
+ conn = factory.createQueueConnection(userName, password);
+ } else {
+ conn = factory.createQueueConnection();
+ }
+ final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) lookup(context, queueBindingName);
+ final QueueSender sender = sess.createSender(queue);
+ conn.start();
+ return new QueueInfo(conn, sess, sender);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Queue connection information */
+ private static class QueueInfo {
+ private final QueueConnection conn;
+ private final QueueSession session;
+ private final QueueSender sender;
+
+ public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
+ this.conn = conn;
+ this.session = session;
+ this.sender = sender;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
+
+ @Override
+ public JmsQueueManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
+ data.password, true);
+ return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
new file mode 100644
index 0000000..b231489
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
@@ -0,0 +1,107 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Log Events over a JMS Queue. This implementation expects that all messages will
+ * contain a serialized LogEvent.
+ */
+public class JmsQueueReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param qcfBindingName The QueueConnectionFactory binding name.
+ * @param queueBindingName The Queue binding name.
+ * @param username The userid to connect to the queue.
+ * @param password The password to connect to the queue.
+ */
+ public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
+ final String password) {
+
+ try {
+ final Context ctx = new InitialContext();
+ QueueConnectionFactory queueConnectionFactory;
+ queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
+ final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
+ queueConnection.start();
+ final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) ctx.lookup(queueBindingName);
+ final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
+ queueReceiver.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String qcfBindingName = args[0];
+ final String queueBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
+ + " QueueConnectionFactoryBindingName QueueBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
new file mode 100644
index 0000000..08d7128
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for JMS Topic connections.
+ */
+public class JmsTopicManager extends AbstractJmsManager {
+
+ private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
+
+ private TopicInfo info;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+ /**
+ * Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param topicBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
+ final String topicBindingName, final String userName, final String password,
+ final TopicInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JSMTopicManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @return A JmsTopicManager.
+ */
+ public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String topicBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsTopicManager");
+ return null;
+ }
+ if (topicBindingName == null) {
+ LOGGER.error("No topic name provided for JmsTopicManager");
+ return null;
+ }
+
+ final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
+ }
+
+
+ @Override
+ public void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.publisher);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String topicBindingName,
+ final String userName, final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static TopicInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
+ TopicConnection conn;
+ if (userName != null) {
+ conn = factory.createTopicConnection(userName, password);
+ } else {
+ conn = factory.createTopicConnection();
+ }
+ final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) lookup(context, queueBindingName);
+ final TopicPublisher publisher = sess.createPublisher(topic);
+ conn.start();
+ return new TopicInfo(conn, sess, publisher);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Topic connection information */
+ private static class TopicInfo {
+ private final TopicConnection conn;
+ private final TopicSession session;
+ private final TopicPublisher publisher;
+
+ public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
+ this.conn = conn;
+ this.session = session;
+ this.publisher = publisher;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
+
+ @Override
+ public JmsTopicManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
+ data.password, true);
+ return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
new file mode 100644
index 0000000..0149ee5
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
@@ -0,0 +1,105 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Topic messages that contain LogEvents. This implementation expects that all messages
+ * are serialized log events.
+ */
+public class JmsTopicReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param tcfBindingName The TopicConnectionFactory binding name.
+ * @param topicBindingName The Topic binding name.
+ * @param username The userid to connect to the topic.
+ * @param password The password to connect to the topic.
+ */
+ public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
+ final String password) {
+ try {
+ final Context ctx = new InitialContext();
+ TopicConnectionFactory topicConnectionFactory;
+ topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
+ final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
+ topicConnection.start();
+ final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) ctx.lookup(topicBindingName);
+ final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
+ topicSubscriber.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String tcfBindingName = args[0];
+ final String topicBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
+ + " TopicConnectionFactoryBindingName TopicBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
new file mode 100644
index 0000000..1f233e8
--- /dev/null
+++ b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/**
+ * Supporting network code for JMS appenders.
+ * <p/>
+ * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
+ * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
+ * the running process. Of course, use of these classes as standalone executables are entirely optional and can
+ * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
+ */
+package org.apache.logging.log4j.mom.jms.receiver;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
new file mode 100644
index 0000000..f05a9fc
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueAppenderTest {
+
+ private static final String FACTORY_NAME = "TestQueueConnectionFactory";
+ private static final String QUEUE_NAME = "TestQueue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ private static final String CONFIG = "log4j-jmsqueue.xml";
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsQueueTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @Test
+ public void testConfiguration() throws Exception {
+ final LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ final Configuration config = ctx.getConfiguration();
+ final Map<String, Appender> appenders = config.getAppenders();
+ assertTrue(appenders.containsKey("JMSQueue"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
new file mode 100644
index 0000000..25c3068
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueFailoverTest {
+
+ private static final String FACTORY_NAME = "QueueConnectionFactory";
+ private static final String QUEUE_NAME = "Log4j2Queue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ private static final String CONFIG = "log4j-jmsqueue-failover.xml";
+
+ private static Configuration config;
+ private static ListAppender listAppender;
+ private static LoggerContext ctx;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ setupQueue();
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ ctx = (LoggerContext) LogManager.getContext(false);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ @Before
+ public void before() {
+ config = ctx.getConfiguration();
+ listAppender = (ListAppender) config.getAppender("List");
+ assertNotNull("No Appender", listAppender);
+ listAppender.clear();
+ ThreadContext.clearMap();
+ }
+
+ private static void setupQueue() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @Test
+ public void testFailover() throws Exception {
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+
+ @Test
+ public void testReconnect() throws Exception {
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
new file mode 100644
index 0000000..7a61efa
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueTest {
+
+ private static final String FACTORY_NAME = "TestQueueConnectionFactory";
+ private static final String QUEUE_NAME = "TestQueue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsQueueTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ QUEUE_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
new file mode 100644
index 0000000..a8de6de
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsTopicFailoverTest {
+
+ private static final String FACTORY_NAME = "TopicConnectionFactory";
+ private static final String TOPIC_NAME = "Log4j2Topic";
+
+ private static Context context;
+
+ private static final String CONFIG = "log4j-jmstopic-failover.xml";
+
+ private static Configuration config;
+ private static ListAppender listAppender;
+ private static LoggerContext ctx;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ setupQueue();
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ ctx = (LoggerContext) LogManager.getContext(false);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ @Before
+ public void before() {
+ config = ctx.getConfiguration();
+ listAppender = (ListAppender) config.getAppender("List");
+ assertNotNull("No Appender", listAppender);
+ listAppender.clear();
+ ThreadContext.clearMap();
+ }
+
+ private static void setupQueue() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
+ //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @Test
+ public void testFailover() throws Exception {
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+
+ @Test
+ public void testReconnect() throws Exception {
+ context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
+ final AbstractJmsReceiver receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
new file mode 100644
index 0000000..6781b75
--- /dev/null
+++ b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsTopicTest {
+
+ private static final String FACTORY_NAME = "TestTopicConnectionFactory";
+ private static final String TOPIC_NAME = "TestTopic";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsTopicTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
+ context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ TOPIC_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console =
+ ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1274408e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 96ca302..6c54144 100644
--- a/pom.xml
+++ b/pom.xml
@@ -989,6 +989,7 @@
<module>log4j-nosql</module>
<module>log4j-web</module>
<module>log4j-perf</module>
+ <module>log4j-mom</module>
</modules>
<profiles>
<profile>
[14/29] git commit: Add license header to config file.
Posted by ma...@apache.org.
Add license header to config file.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608339 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6befe58c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6befe58c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6befe58c
Branch: refs/heads/master
Commit: 6befe58cadcd61fce54dc9128bb2c1f390d5c095
Parents: 35428a9
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 05:02:06 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 05:02:06 2014 +0000
----------------------------------------------------------------------
log4j-mom/src/test/resources/JmsAppenderTest.xml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6befe58c/log4j-mom/src/test/resources/JmsAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/JmsAppenderTest.xml b/log4j-mom/src/test/resources/JmsAppenderTest.xml
index 4997747..ceccbaa 100644
--- a/log4j-mom/src/test/resources/JmsAppenderTest.xml
+++ b/log4j-mom/src/test/resources/JmsAppenderTest.xml
@@ -1,3 +1,21 @@
+<?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="JmsQueueAppender"
[22/29] git commit: Delete old JMS tests.
Posted by ma...@apache.org.
Delete old JMS tests.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1b66d8d7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1b66d8d7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1b66d8d7
Branch: refs/heads/master
Commit: 1b66d8d7f85566c7133686e106c26b1cd884cf33
Parents: 1d99b19
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:42:07 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:42:07 2014 -0500
----------------------------------------------------------------------
.../mom/jms/appender/JmsQueueAppenderTest.java | 85 -----------
.../mom/jms/appender/JmsQueueFailoverTest.java | 122 ---------------
.../log4j/mom/jms/appender/JmsQueueTest.java | 147 -------------------
.../mom/jms/appender/JmsTopicFailoverTest.java | 121 ---------------
.../log4j/mom/jms/appender/JmsTopicTest.java | 147 -------------------
.../test/resources/log4j-jmsqueue-failover.xml | 52 -------
log4j-jms/src/test/resources/log4j-jmsqueue.xml | 30 ----
.../test/resources/log4j-jmstopic-failover.xml | 52 -------
8 files changed, 756 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
deleted file mode 100644
index f05a9fc..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
+++ /dev/null
@@ -1,85 +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.mom.jms.appender;
-
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueAppenderTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue.xml";
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @Test
- public void testConfiguration() throws Exception {
- final LoggerContext ctx = (LoggerContext) LogManager.getContext();
- final Configuration config = ctx.getConfiguration();
- final Map<String, Appender> appenders = config.getAppenders();
- assertTrue(appenders.containsKey("JMSQueue"));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
deleted file mode 100644
index 25c3068..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
+++ /dev/null
@@ -1,122 +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.mom.jms.appender;
-
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueFailoverTest {
-
- private static final String FACTORY_NAME = "QueueConnectionFactory";
- private static final String QUEUE_NAME = "Log4j2Queue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
deleted file mode 100644
index a36e148..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
+++ /dev/null
@@ -1,147 +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.mom.jms.appender;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- QUEUE_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
-
- private static final long serialVersionUID = 1L;
-
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
deleted file mode 100644
index a8de6de..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
+++ /dev/null
@@ -1,121 +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.mom.jms.appender;
-
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicFailoverTest {
-
- private static final String FACTORY_NAME = "TopicConnectionFactory";
- private static final String TOPIC_NAME = "Log4j2Topic";
-
- private static Context context;
-
- private static final String CONFIG = "log4j-jmstopic-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- final AbstractJmsReceiver receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
deleted file mode 100644
index 890f929..0000000
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
+++ /dev/null
@@ -1,147 +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.mom.jms.appender;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicTest {
-
- private static final String FACTORY_NAME = "TestTopicConnectionFactory";
- private static final String TOPIC_NAME = "TestTopic";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsTopicTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- TOPIC_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console =
- ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
-
- private static final long serialVersionUID = 1L;
-
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
deleted file mode 100644
index 8b86750..0000000
--- a/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Queue"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/resources/log4j-jmsqueue.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmsqueue.xml b/log4j-jms/src/test/resources/log4j-jmsqueue.xml
deleted file mode 100644
index 44ea169..0000000
--- a/log4j-jms/src/test/resources/log4j-jmsqueue.xml
+++ /dev/null
@@ -1,30 +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="ConfigTest" status="OFF" monitorInterval="5">
- <Appenders>
- <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
- <PatternLayout pattern="%m%n"/>
- </JMSQueue>
- </Appenders>
- <Loggers>
- <Root level="error">
- <AppenderRef ref="JMSQueue"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b66d8d7/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml b/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
deleted file mode 100644
index 8588f69..0000000
--- a/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Topic"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
[16/29] Rename log4j-mom to log4j-jms.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml b/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
deleted file mode 100644
index 8588f69..0000000
--- a/log4j-mom/src/test/resources/log4j-jmstopic-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Topic"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2d0b1e5..591aeb5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -499,11 +499,6 @@
<version>${activemq.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.qpid</groupId>
- <artifactId>proton-j</artifactId>
- <version>0.7</version>
- </dependency>
- <dependency>
<groupId>org.mockejb</groupId>
<artifactId>mockejb</artifactId>
<version>0.6-beta2</version>
@@ -1011,7 +1006,7 @@
<module>log4j-nosql</module>
<module>log4j-web</module>
<module>log4j-perf</module>
- <module>log4j-mom</module>
+ <module>log4j-jms</module>
<module>log4j-streams</module>
</modules>
<profiles>
[21/29] git commit: Allow @PluginAliases on a field.
Posted by ma...@apache.org.
Allow @PluginAliases on a field.
- This is already technically supported by PluginBuilder for @PluginBuilderAttribute.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1d99b197
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1d99b197
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1d99b197
Branch: refs/heads/master
Commit: 1d99b19711af0052e68144c035e9d85b1ac6e82f
Parents: c396b0f
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 22:31:11 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 22:31:11 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/core/config/plugins/PluginAliases.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1d99b197/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
index 9607bb4..7be3dea 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
@@ -23,11 +23,11 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Identifies a list of aliases for a {@link Plugin} or {@link PluginAttribute}.
+ * Identifies a list of aliases for a {@link Plugin}, {@link PluginAttribute}, or {@link PluginBuilderAttribute}.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.PARAMETER, ElementType.TYPE})
+@Target({ElementType.PARAMETER, ElementType.TYPE, ElementType.FIELD})
public @interface PluginAliases {
String[] value();
[24/29] git commit: Add plugin aliases to JMS appender.
Posted by ma...@apache.org.
Add plugin aliases to JMS appender.
- Now this plugin will work with old config formats!
- Implements LOG4J2-815.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a1ea15b4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a1ea15b4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a1ea15b4
Branch: refs/heads/master
Commit: a1ea15b44283f09a2122c034abb2da61f6457966
Parents: 4827cdb
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:46:24 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:46:24 2014 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/mom/jms/appender/JmsAppender.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a1ea15b4/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
index c98e2a1..f99e890 100644
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
@@ -27,6 +27,7 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
@@ -35,10 +36,11 @@ import org.apache.logging.log4j.mom.jms.manager.JmsManager;
import org.apache.logging.log4j.mom.jms.manager.JndiManager;
/**
- * Generic JMS appender plugin for both queues and topics.
+ * 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.
*/
@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
-// TODO: use @PluginAliases to make the separated plugins work through this one
+@PluginAliases({"JMSQueue", "JMSTopic"})
public class JmsAppender extends AbstractAppender {
private final JmsManager manager;
@@ -53,7 +55,7 @@ public class JmsAppender extends AbstractAppender {
}
@Override
- public void append(LogEvent event) {
+ public void append(final LogEvent event) {
try {
final Message message = this.manager.createMessage(getLayout().toSerializable(event));
message.setJMSTimestamp(event.getTimeMillis());
@@ -92,6 +94,7 @@ public class JmsAppender extends AbstractAppender {
private String factoryBindingName;
@PluginBuilderAttribute
+ @PluginAliases({"queueBindingName", "topicBindingName"})
private String destinationBindingName;
@PluginBuilderAttribute
[07/29] git commit: Merge test fix from trunk.
Posted by ma...@apache.org.
Merge test fix from trunk.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/branches/messaging-module@1608325 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/91d879ac
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/91d879ac
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/91d879ac
Branch: refs/heads/master
Commit: 91d879ac7ae1d0120518d1a71c6fab593988002b
Parents: d77f1bf
Author: mattsicker <ma...@unknown>
Authored: Mon Jul 7 01:20:39 2014 +0000
Committer: mattsicker <ma...@unknown>
Committed: Mon Jul 7 01:20:39 2014 +0000
----------------------------------------------------------------------
.../log4j/core/async/AsyncLoggerContextSelectorTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/91d879ac/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
index 2a78351..dc60aab 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
@@ -51,11 +51,11 @@ public class AsyncLoggerContextSelectorTest {
}
@Test
- public void testContextNameIsAsyncLoggerContext() {
+ public void testContextNameIsAsyncLoggerContextWithClassHashCode() {
final AsyncLoggerContextSelector selector = new AsyncLoggerContextSelector();
final LoggerContext context = selector.getContext(null, null, false);
-
- assertEquals("AsyncLoggerContext", context.getName());
+ final String expectedContextName = "AsyncLoggerContext@" + AsyncLoggerContext.class.hashCode();
+ assertEquals(expectedContextName, context.getName());
}
}
[18/29] Rename log4j-mom to log4j-jms.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
new file mode 100644
index 0000000..9ed98fa
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
@@ -0,0 +1,126 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+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.layout.SerializedLayout;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.mom.jms.manager.JmsManager;
+import org.apache.logging.log4j.mom.jms.manager.JndiManager;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Integration test for JmsAppender using an embedded ActiveMQ broker.
+ */
+public class JmsAppenderIT {
+
+ private static JmsManager jmsManager;
+
+ private JmsAppender appender;
+
+ @BeforeClass
+ public static void setUpClass() {
+ final Properties additional = new Properties();
+ additional.setProperty("queue.TestQueue", "TestQueue");
+ JndiManager jndiManager = JndiManager.getJndiManager(ActiveMQInitialContextFactory.class.getName(),
+ "vm://localhost?broker.persistent=false", null, null, null, additional);
+ jmsManager = JmsManager.getJmsManager("JmsManager", jndiManager, "ConnectionFactory", "TestQueue", null, null);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ jmsManager.release();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ appender = new JmsAppender("JmsAppender", null, SerializedLayout.createLayout(), true, jmsManager);
+ appender.start();
+ }
+
+ @Test
+ public void testLogToQueue() throws Exception {
+ final int messageCount = 100;
+ final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
+ final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount);
+ messageConsumer.setMessageListener(consumer);
+ final String messageText = "Hello, World!";
+ final String loggerName = this.getClass().getName();
+ for (int i = 0; i < messageCount; i++) {
+ final LogEvent event = Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.ERROR,
+ new SimpleMessage(messageText), null, null, null, null, Thread.currentThread().getName(), null,
+ System.currentTimeMillis());
+ appender.append(event);
+ }
+ consumer.awaitAndAssertAllMessagesConsumed();
+ }
+
+ private static class JmsQueueConsumer implements MessageListener {
+
+ private final int messageCount;
+ private final CountDownLatch countDownLatch;
+ private final Collection<LogEvent> events;
+
+ private JmsQueueConsumer(final int messageCount) {
+ this.messageCount = messageCount;
+ this.countDownLatch = new CountDownLatch(messageCount);
+ this.events = new ArrayList<LogEvent>(messageCount);
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ try {
+ consume((ObjectMessage) message);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void consume(ObjectMessage message) throws JMSException {
+ try {
+ final LogEvent event = (LogEvent) message.getObject();
+ events.add(event);
+ } finally {
+ countDownLatch.countDown();
+ }
+ }
+
+ public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
+ countDownLatch.await(5, TimeUnit.SECONDS);
+ assertEquals(messageCount, events.size());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
new file mode 100644
index 0000000..8e54681
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
@@ -0,0 +1,79 @@
+package org.apache.logging.log4j.mom.jms.appender;
+
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+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.util.Closer;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.*;
+
+public class JmsAppenderTest {
+
+ private static final String CONNECTION_FACTORY_NAME = "jms/activemq";
+ private static final String DESTINATION_NAME = "jms/destination";
+ private static final String LOG_MESSAGE = "Hello, world!";
+
+ private static Context context;
+
+ private JmsAppender appender;
+ private static MockQueue queue;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
+ queue = new MockQueue(DESTINATION_NAME);
+ context.rebind(DESTINATION_NAME, queue);
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ Closer.closeSilently(context);
+ }
+
+ @Rule
+ public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
+
+ @Before
+ public void setUp() throws Exception {
+ appender = (JmsAppender) ctx.getAppender("JmsQueueAppender");
+ assertEquals(0, queue.size());
+ }
+
+ @Test
+ public void testAppendToQueue() throws Exception {
+ final String loggerName = this.getClass().getName();
+ final long now = System.currentTimeMillis();
+ final LogEvent event = createLogEvent(loggerName, now);
+ appender.append(event);
+ assertEquals(1, queue.size());
+ final Message message = queue.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(TextMessage.class));
+ final TextMessage textMessage = (TextMessage) message;
+ assertEquals(LOG_MESSAGE, textMessage.getText());
+ }
+
+ private static Log4jLogEvent createLogEvent(String loggerName, long now) {
+ return Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.INFO,
+ new SimpleMessage(LOG_MESSAGE), null, null, null, null, Thread.currentThread().getName(), null, now);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
new file mode 100644
index 0000000..f05a9fc
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueAppenderTest {
+
+ private static final String FACTORY_NAME = "TestQueueConnectionFactory";
+ private static final String QUEUE_NAME = "TestQueue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ private static final String CONFIG = "log4j-jmsqueue.xml";
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsQueueTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @Test
+ public void testConfiguration() throws Exception {
+ final LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ final Configuration config = ctx.getConfiguration();
+ final Map<String, Appender> appenders = config.getAppenders();
+ assertTrue(appenders.containsKey("JMSQueue"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
new file mode 100644
index 0000000..25c3068
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueFailoverTest {
+
+ private static final String FACTORY_NAME = "QueueConnectionFactory";
+ private static final String QUEUE_NAME = "Log4j2Queue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ private static final String CONFIG = "log4j-jmsqueue-failover.xml";
+
+ private static Configuration config;
+ private static ListAppender listAppender;
+ private static LoggerContext ctx;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ setupQueue();
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ ctx = (LoggerContext) LogManager.getContext(false);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ @Before
+ public void before() {
+ config = ctx.getConfiguration();
+ listAppender = (ListAppender) config.getAppender("List");
+ assertNotNull("No Appender", listAppender);
+ listAppender.clear();
+ ThreadContext.clearMap();
+ }
+
+ private static void setupQueue() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @Test
+ public void testFailover() throws Exception {
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+
+ @Test
+ public void testReconnect() throws Exception {
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
new file mode 100644
index 0000000..a36e148
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsQueueTest {
+
+ private static final String FACTORY_NAME = "TestQueueConnectionFactory";
+ private static final String QUEUE_NAME = "TestQueue";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsQueueTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
+ context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ QUEUE_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
+
+ private static final long serialVersionUID = 1L;
+
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
new file mode 100644
index 0000000..a8de6de
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsTopicFailoverTest {
+
+ private static final String FACTORY_NAME = "TopicConnectionFactory";
+ private static final String TOPIC_NAME = "Log4j2Topic";
+
+ private static Context context;
+
+ private static final String CONFIG = "log4j-jmstopic-failover.xml";
+
+ private static Configuration config;
+ private static ListAppender listAppender;
+ private static LoggerContext ctx;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ setupQueue();
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ ctx = (LoggerContext) LogManager.getContext(false);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ @Before
+ public void before() {
+ config = ctx.getConfiguration();
+ listAppender = (ListAppender) config.getAppender("List");
+ assertNotNull("No Appender", listAppender);
+ listAppender.clear();
+ ThreadContext.clearMap();
+ }
+
+ private static void setupQueue() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
+ //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
+ }
+
+ @Test
+ public void testFailover() throws Exception {
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+
+ @Test
+ public void testReconnect() throws Exception {
+ context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
+ final AbstractJmsReceiver receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
+ ThreadContext.put("appender", "Failover");
+ final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
+ logger.debug("Test Message");
+ final List<LogEvent> events = listAppender.getEvents();
+ assertNotNull("No events returned", events);
+ assertTrue("No events returned", events.size() > 0);
+ assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
new file mode 100644
index 0000000..890f929
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
+import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
+import org.apache.logging.log4j.status.StatusConsoleListener;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JmsTopicTest {
+
+ private static final String FACTORY_NAME = "TestTopicConnectionFactory";
+ private static final String TOPIC_NAME = "TestTopic";
+
+ private static Context context;
+ private static AbstractJmsReceiver receiver;
+
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("JmsTopicTest");
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ // MockContextFactory becomes the primary JNDI provider
+ final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
+ StatusLogger.getLogger().registerListener(listener);
+ MockContextFactory.setAsInitial();
+ context = new InitialContext();
+ context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
+ context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
+ ((LoggerContext) LogManager.getContext()).reconfigure();
+ receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ StatusLogger.getLogger().reset();
+ }
+
+ @After
+ public void teardown() {
+ final Map<String,Appender> map = root.getAppenders();
+ for (final Map.Entry<String, Appender> entry : map.entrySet()) {
+ final Appender app = entry.getValue();
+ root.removeAppender(app);
+ app.stop();
+ }
+ }
+
+ @Test
+ public void testServer() throws Exception {
+ final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
+ final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
+ final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
+ final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
+ TOPIC_NAME, null, null, null, clientFilters, "true");
+ appender.start();
+ final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
+ final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
+ listApp.start();
+ final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
+ final ConsoleAppender console =
+ ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
+ console.start();
+ final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
+ serverLogger.addAppender(console);
+ serverLogger.setAdditive(false);
+
+
+ // set appender on root and set level to debug
+ root.addAppender(listApp);
+ root.addAppender(appender);
+ root.setAdditive(false);
+ root.setLevel(Level.DEBUG);
+ root.debug("This is a test message");
+ Thread.sleep(100);
+ final List<LogEvent> events = listApp.getEvents();
+ assertNotNull("No event retrieved", events);
+ assertTrue("No events retrieved", events.size() > 0);
+ assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
+ }
+
+ private class MessageFilter extends AbstractFilter {
+
+ private static final long serialVersionUID = 1L;
+
+ public MessageFilter(final Result onMatch, final Result onMismatch) {
+ super(onMatch, onMismatch);
+ }
+
+ @Override
+ public Result filter(final LogEvent event) {
+ final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (final StackTraceElement element : stackTrace) {
+ if (element.getMethodName().equals("onMessage")) {
+ return onMatch;
+ } else if (element.getMethodName().equals("testServer")) {
+ return onMismatch;
+ }
+ }
+ return onMismatch;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/resources/JmsAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/JmsAppenderTest.xml b/log4j-jms/src/test/resources/JmsAppenderTest.xml
new file mode 100644
index 0000000..ceccbaa
--- /dev/null
+++ b/log4j-jms/src/test/resources/JmsAppenderTest.xml
@@ -0,0 +1,32 @@
+<?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="JmsQueueAppender"
+ factoryBindingName="jms/activemq"
+ destinationBindingName="jms/destination">
+ <PatternLayout pattern="%m"/>
+ </JMS>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="JmsQueueAppender"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
new file mode 100644
index 0000000..8b86750
--- /dev/null
+++ b/log4j-jms/src/test/resources/log4j-jmsqueue-failover.xml
@@ -0,0 +1,52 @@
+<?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 status="OFF" name="FailoverTest">
+ <Appenders>
+ <List name="List"/>
+ <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
+ ignoreExceptions="false"/>
+ <Rewrite name="Rewrite" ignoreExceptions="false">
+ <PropertiesRewritePolicy>
+ <Property name="appender">List</Property>
+ </PropertiesRewritePolicy>
+ <AppenderRef ref="Log4j2Queue"/>
+ </Rewrite>
+ <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
+ <Failovers>
+ <AppenderRef ref="List"/>
+ </Failovers>
+ </Failover>
+ </Appenders>
+
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="Failover">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="Failover"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ <AppenderRef ref="List">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="List"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/resources/log4j-jmsqueue.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmsqueue.xml b/log4j-jms/src/test/resources/log4j-jmsqueue.xml
new file mode 100644
index 0000000..44ea169
--- /dev/null
+++ b/log4j-jms/src/test/resources/log4j-jmsqueue.xml
@@ -0,0 +1,30 @@
+<?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="ConfigTest" status="OFF" monitorInterval="5">
+ <Appenders>
+ <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
+ <PatternLayout pattern="%m%n"/>
+ </JMSQueue>
+ </Appenders>
+ <Loggers>
+ <Root level="error">
+ <AppenderRef ref="JMSQueue"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml b/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
new file mode 100644
index 0000000..8588f69
--- /dev/null
+++ b/log4j-jms/src/test/resources/log4j-jmstopic-failover.xml
@@ -0,0 +1,52 @@
+<?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 status="OFF" name="FailoverTest">
+ <Appenders>
+ <List name="List"/>
+ <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
+ ignoreExceptions="false"/>
+ <Rewrite name="Rewrite" ignoreExceptions="false">
+ <PropertiesRewritePolicy>
+ <Property name="appender">List</Property>
+ </PropertiesRewritePolicy>
+ <AppenderRef ref="Log4j2Topic"/>
+ </Rewrite>
+ <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
+ <Failovers>
+ <AppenderRef ref="List"/>
+ </Failovers>
+ </Failover>
+ </Appenders>
+
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="Failover">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="Failover"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ <AppenderRef ref="List">
+ <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
+ <KeyValuePair key="appender" value="List"/>
+ </ThreadContextMapFilter>
+ </AppenderRef>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/pom.xml b/log4j-mom/pom.xml
deleted file mode 100644
index c1fbbe3..0000000
--- a/log4j-mom/pom.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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">
- <parent>
- <artifactId>log4j</artifactId>
- <groupId>org.apache.logging.log4j</groupId>
- <version>2.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>log4j-mom</artifactId>
- <name>Log4j 2 MOM Plugins</name>
- <description>Message Oriented Middleware plugins for Log4j 2</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.spec.javax.jms</groupId>
- <artifactId>jboss-jms-api_1.1_spec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.qpid</groupId>
- <artifactId>proton-j</artifactId>
- </dependency>
-
- <!-- tests -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockejb</groupId>
- <artifactId>mockejb</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- integration tests -->
- <dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-broker</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
deleted file mode 100644
index c98e2a1..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
+++ /dev/null
@@ -1,195 +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.mom.jms.appender;
-
-import java.io.Serializable;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsManager;
-import org.apache.logging.log4j.mom.jms.manager.JndiManager;
-
-/**
- * Generic JMS appender plugin for both queues and topics.
- */
-@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
-// TODO: use @PluginAliases to make the separated plugins work through this one
-public class JmsAppender extends AbstractAppender {
-
- private final JmsManager manager;
- private final MessageProducer producer;
-
- protected JmsAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final boolean ignoreExceptions, final JmsManager manager)
- throws JMSException {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- this.producer = this.manager.createMessageProducer();
- }
-
- @Override
- public void append(LogEvent event) {
- try {
- final Message message = this.manager.createMessage(getLayout().toSerializable(event));
- message.setJMSTimestamp(event.getTimeMillis());
- this.producer.send(message);
- } catch (JMSException e) {
- throw new AppenderLoggingException(e);
- }
- }
-
- @PluginBuilderFactory
- public static Builder newBuilder() {
- return new Builder();
- }
-
- public static class Builder implements org.apache.logging.log4j.core.util.Builder<JmsAppender> {
-
- @PluginBuilderAttribute
- private String name;
-
- @PluginBuilderAttribute
- private String factoryName;
-
- @PluginBuilderAttribute
- private String providerUrl;
-
- @PluginBuilderAttribute
- private String urlPkgPrefixes;
-
- @PluginBuilderAttribute
- private String securityPrincipalName;
-
- @PluginBuilderAttribute(sensitive = true)
- private String securityCredentials;
-
- @PluginBuilderAttribute
- private String factoryBindingName;
-
- @PluginBuilderAttribute
- private String destinationBindingName;
-
- @PluginBuilderAttribute
- private String username;
-
- @PluginBuilderAttribute(sensitive = true)
- private String password;
-
- @PluginElement("Layout")
- private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
-
- @PluginElement("Filter")
- private Filter filter;
-
- @PluginBuilderAttribute
- private boolean ignoreExceptions = true;
-
- private Builder() {
- }
-
- public Builder setName(final String name) {
- this.name = name;
- return this;
- }
-
- public Builder setFactoryName(final String factoryName) {
- this.factoryName = factoryName;
- return this;
- }
-
- public Builder setProviderUrl(final String providerUrl) {
- this.providerUrl = providerUrl;
- return this;
- }
-
- public Builder setUrlPkgPrefixes(final String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- return this;
- }
-
- public Builder setSecurityPrincipalName(final String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- return this;
- }
-
- public Builder setSecurityCredentials(final String securityCredentials) {
- this.securityCredentials = securityCredentials;
- return this;
- }
-
- public Builder setFactoryBindingName(final String factoryBindingName) {
- this.factoryBindingName = factoryBindingName;
- return this;
- }
-
- public Builder setDestinationBindingName(final String destinationBindingName) {
- this.destinationBindingName = destinationBindingName;
- return this;
- }
-
- public Builder setUsername(final String username) {
- this.username = username;
- return this;
- }
-
- public Builder setPassword(final String password) {
- this.password = password;
- return this;
- }
-
- public Builder setLayout(final Layout<? extends Serializable> layout) {
- this.layout = layout;
- return this;
- }
-
- public Builder setFilter(final Filter filter) {
- this.filter = filter;
- return this;
- }
-
- public Builder setIgnoreExceptions(final boolean ignoreExceptions) {
- this.ignoreExceptions = ignoreExceptions;
- return this;
- }
-
- @Override
- public JmsAppender build() {
- final JndiManager jndiManager = JndiManager.getJndiManager(factoryName, providerUrl, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, null);
- final JmsManager jmsManager = JmsManager.getJmsManager(name, jndiManager, factoryBindingName,
- destinationBindingName, username, password);
- try {
- return new JmsAppender(name, filter, layout, ignoreExceptions, jmsManager);
- } catch (final JMSException e) {
- LOGGER.error("Error creating JmsAppender [{}].", name, e);
- return null;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
deleted file mode 100644
index 4a544e4..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
+++ /dev/null
@@ -1,113 +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.mom.jms.appender;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsQueueManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Queue.
- */
-@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
-public final class JmsQueueAppender extends AbstractAppender {
-
- private static final long serialVersionUID = 1L;
-
- private final JmsQueueManager manager;
-
- private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsQueueManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- *
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsQueueAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The user ID to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsQueueAppender.
- */
- @PluginFactory
- public static JmsQueueAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("queueBindingName") final String queueBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filter") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
deleted file mode 100644
index 1b000ce..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
+++ /dev/null
@@ -1,114 +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.mom.jms.appender;
-
-import java.io.Serializable;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsTopicManager;
-import org.apache.logging.log4j.core.util.Booleans;
-
-/**
- * Appender to write to a JMS Topic.
- */
-@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
-public final class JmsTopicAppender extends AbstractAppender {
-
- private static final long serialVersionUID = 1L;
-
- private final JmsTopicManager manager;
-
- private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final JmsTopicManager manager, final boolean ignoreExceptions) {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- }
-
- /**
- * Actual writing occurs here.
- * <p/>
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
- try {
- manager.send(getLayout().toSerializable(event));
- } catch (final Exception ex) {
- throw new AppenderLoggingException(ex);
- }
- }
-
- /**
- * Create a JmsTopicAppender.
- * @param name The name of the Appender.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @param layout The layout to use (defaults to SerializedLayout).
- * @param filter The Filter or null.
- * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
- * they are propagated to the caller.
- * @return The JmsTopicAppender.
- */
- @PluginFactory
- public static JmsTopicAppender createAppender(
- @PluginAttribute("name") final String name,
- @PluginAttribute("factoryName") final String factoryName,
- @PluginAttribute("providerURL") final String providerURL,
- @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
- @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
- @PluginAttribute("securityCredentials") final String securityCredentials,
- @PluginAttribute("factoryBindingName") final String factoryBindingName,
- @PluginAttribute("topicBindingName") final String topicBindingName,
- @PluginAttribute("userName") final String userName,
- @PluginAttribute("password") final String password,
- @PluginElement("Layout") Layout<? extends Serializable> layout,
- @PluginElement("Filter") final Filter filter,
- @PluginAttribute("ignoreExceptions") final String ignore) {
-
- if (name == null) {
- LOGGER.error("No name provided for JmsQueueAppender");
- return null;
- }
- final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
- final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
- if (manager == null) {
- return null;
- }
- if (layout == null) {
- layout = SerializedLayout.createLayout();
- }
- return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
deleted file mode 100644
index 0c7a4ff..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-/**
- * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
- */
-package org.apache.logging.log4j.mom.jms.appender;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
deleted file mode 100644
index e53b175..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
+++ /dev/null
@@ -1,156 +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.mom.jms.manager;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.AbstractManager;
-
-/**
- * Base Class for Managers of JMS connections.
- */
-public abstract class AbstractJmsManager extends AbstractManager {
-
- /**
- * The Constructor.
- * @param name The name of the Appender.
- */
- public AbstractJmsManager(final String name) {
- super(name);
- }
-
- /**
- * Create the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return the InitialContext.
- * @throws NamingException if a naming error occurs.
- */
- protected static Context createContext(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials)
- throws NamingException {
-
- final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
- securityCredentials);
- return new InitialContext(props);
- }
-
- /**
- * Looks up the name in the context.
- * @param ctx The Context.
- * @param name The name to locate.
- * @return The object to be located.
- * @throws NamingException If an error occurs locating the name.
- */
- protected static Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- LOGGER.warn("Could not find name [{}].", name);
- throw e;
- }
- }
-
- /**
- * Sets up the properties to pass to the InitialContext.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @return The Properties.
- * @see javax.naming.Context
- */
- protected static Properties getEnvironment(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials) {
- final Properties props = new Properties();
- if (factoryName != null) {
- props.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);
- if (providerURL != null) {
- props.setProperty(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
- "This is likely to cause problems");
- }
- if (urlPkgPrefixes != null) {
- props.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipalName != null) {
- props.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- props.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
- "This is likely to cause problems.");
- }
- }
- return props;
- }
- return null;
- }
-
- /**
- * Send the message.
- * @param object The Object to sent.
- * @throws Exception if an error occurs.
- */
- public abstract void send(Serializable object) throws Exception;
-
- /**
- * Send the Object.
- * @param object The Object to send.
- * @param session The Session.
- * @param producer The MessageProducer.
- * @throws Exception if an error occurs.
- */
- public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
- throws Exception {
- try {
- Message msg;
- if (object instanceof String) {
- msg = session.createTextMessage();
- ((TextMessage) msg).setText((String) object);
- } else {
- msg = session.createObjectMessage();
- ((ObjectMessage) msg).setObject(object);
- }
- producer.send(msg);
- } catch (final JMSException ex) {
- LOGGER.error("Could not publish message via JMS {}", getName());
- throw ex;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
deleted file mode 100644
index d3ce550..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
+++ /dev/null
@@ -1,169 +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.mom.jms.manager;
-
-import java.io.Serializable;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-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.Logger;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects
- * involving a configured ConnectionFactory and Destination.
- */
-public class JmsManager extends AbstractManager {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private static final JmsManagerFactory FACTORY = new JmsManagerFactory();
-
- private final JndiManager jndiManager;
- private final Connection connection;
- private final Session session;
- private final Destination destination;
-
- private JmsManager(final String name, final JndiManager jndiManager, final String connectionFactoryName,
- final String destinationName, final String username, final String password)
- throws NamingException, JMSException {
- super(name);
- this.jndiManager = jndiManager;
- final ConnectionFactory connectionFactory = this.jndiManager.lookup(connectionFactoryName);
- if (username != null && password != null) {
- this.connection = connectionFactory.createConnection(username, password);
- } else {
- this.connection = connectionFactory.createConnection();
- }
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- this.destination = this.jndiManager.lookup(destinationName);
- this.connection.start();
- }
-
- /**
- * Gets a JmsManager using the specified configuration parameters.
- *
- * @param name The name to use for this JmsManager.
- * @param jndiManager The JndiManager to look up JMS information through.
- * @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.
- * @return The JmsManager as configured.
- */
- public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
- final String connectionFactoryName, final String destinationName,
- final String username, final String password) {
- final JmsConfiguration configuration = new JmsConfiguration(jndiManager, connectionFactoryName, destinationName,
- username, password);
- return FACTORY.createManager(name, configuration);
- }
-
- /**
- * Creates a MessageConsumer on this Destination using the current Session.
- *
- * @return A MessageConsumer on this Destination.
- * @throws JMSException
- */
- public MessageConsumer createMessageConsumer() throws JMSException {
- return this.session.createConsumer(this.destination);
- }
-
- /**
- * Creates a MessageProducer on this Destination using the current Session.
- *
- * @return A MessageProducer on this Destination.
- * @throws JMSException
- */
- public MessageProducer createMessageProducer() throws JMSException {
- return this.session.createProducer(this.destination);
- }
-
- /**
- * Creates a TextMessage or ObjectMessage from a Serializable object. For instance, when using a text-based
- * {@link org.apache.logging.log4j.core.Layout} such as {@link org.apache.logging.log4j.core.layout.PatternLayout},
- * the {@link org.apache.logging.log4j.core.LogEvent} message will be serialized to a String. When using a
- * layout such as {@link org.apache.logging.log4j.core.layout.SerializedLayout}, the LogEvent message will be
- * serialized as a Java object.
- *
- * @param object The LogEvent or String message to wrap.
- * @return A new JMS message containing the provided object.
- * @throws JMSException
- */
- public Message createMessage(final Serializable object) throws JMSException {
- if (object instanceof String) {
- return this.session.createTextMessage((String) object);
- } else {
- return this.session.createObjectMessage(object);
- }
- }
-
- @Override
- protected void releaseSub() {
- try {
- this.session.close();
- } catch (final JMSException ignored) {
- }
- try {
- this.connection.close();
- } catch (final JMSException ignored) {
- }
- this.jndiManager.release();
- }
-
- private static class JmsConfiguration {
- private final JndiManager jndiManager;
- private final String connectionFactoryName;
- private final String destinationName;
- private final String username;
- private final String password;
-
- private JmsConfiguration(JndiManager jndiManager, String connectionFactoryName, String destinationName,
- String username, String password) {
- this.jndiManager = jndiManager;
- this.connectionFactoryName = connectionFactoryName;
- this.destinationName = destinationName;
- this.username = username;
- this.password = password;
- }
- }
-
- private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsConfiguration> {
-
- @Override
- public JmsManager createManager(String name, JmsConfiguration data) {
- try {
- return new JmsManager(name, data.jndiManager, data.connectionFactoryName, data.destinationName,
- data.username, data.password);
- } catch (final Exception e) {
- LOGGER.error("Error creating JmsManager using ConnectionFactory [{}] and Destination [{}].",
- data.connectionFactoryName, data.destinationName, e);
- return null;
- }
- }
- }
-
-}
[25/29] git commit: Add backwards compatibility tests for JMS
appender.
Posted by ma...@apache.org.
Add backwards compatibility tests for JMS appender.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7aec0b5a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7aec0b5a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7aec0b5a
Branch: refs/heads/master
Commit: 7aec0b5ab93533d73ae2ecd8f6d348152f619008
Parents: a1ea15b
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:46:37 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:46:37 2014 -0500
----------------------------------------------------------------------
.../log4j/mom/jms/appender/JmsAppenderTest.java | 85 +++++++++++++++-----
.../src/test/resources/JmsAppenderTest.xml | 15 +++-
2 files changed, 77 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7aec0b5a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
index 8e54681..743a4eb 100644
--- a/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
@@ -1,6 +1,7 @@
package org.apache.logging.log4j.mom.jms.appender;
import javax.jms.Message;
+import javax.jms.ObjectMessage;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -8,16 +9,17 @@ import javax.naming.InitialContext;
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.util.Closer;
+import org.apache.logging.log4j.core.util.JndiCloser;
import org.apache.logging.log4j.junit.InitialLoggerContext;
import org.apache.logging.log4j.message.SimpleMessage;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
import org.mockejb.jndi.MockContextFactory;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -25,55 +27,96 @@ import static org.junit.Assert.*;
public class JmsAppenderTest {
- private static final String CONNECTION_FACTORY_NAME = "jms/activemq";
+ private static final String CONNECTION_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 QUEUE_NAME = "jms/queue";
+ private static final String TOPIC_NAME = "jms/topic";
private static final String LOG_MESSAGE = "Hello, world!";
private static Context context;
- private JmsAppender appender;
+ private static MockQueue destination;
private static MockQueue queue;
+ private static MockTopic topic;
@BeforeClass
public static void setUpClass() throws Exception {
MockContextFactory.setAsInitial();
context = new InitialContext();
context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
- queue = new MockQueue(DESTINATION_NAME);
- context.rebind(DESTINATION_NAME, queue);
+ context.rebind(TOPIC_FACTORY_NAME, new TopicConnectionFactoryImpl());
+ destination = new MockQueue(DESTINATION_NAME);
+ context.rebind(DESTINATION_NAME, destination);
+ queue = new MockQueue(QUEUE_NAME);
+ context.rebind(QUEUE_NAME, queue);
+ topic = new MockTopic(TOPIC_NAME);
+ context.rebind(TOPIC_NAME, topic);
}
@AfterClass
public static void tearDownClass() throws Exception {
- Closer.closeSilently(context);
+ JndiCloser.close(context);
}
@Rule
public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
- @Before
- public void setUp() throws Exception {
- appender = (JmsAppender) ctx.getAppender("JmsQueueAppender");
- assertEquals(0, queue.size());
- }
-
@Test
public void testAppendToQueue() throws Exception {
- final String loggerName = this.getClass().getName();
- final long now = System.currentTimeMillis();
- final LogEvent event = createLogEvent(loggerName, now);
+ assertEquals(0, destination.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender");
+ final LogEvent event = createLogEvent();
appender.append(event);
- assertEquals(1, queue.size());
- final Message message = queue.getMessageAt(0);
+ assertEquals(1, destination.size());
+ final Message message = destination.getMessageAt(0);
assertNotNull(message);
assertThat(message, instanceOf(TextMessage.class));
final TextMessage textMessage = (TextMessage) message;
assertEquals(LOG_MESSAGE, textMessage.getText());
}
- private static Log4jLogEvent createLogEvent(String loggerName, long now) {
- return Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.INFO,
- new SimpleMessage(LOG_MESSAGE), null, null, null, null, Thread.currentThread().getName(), null, now);
+ @Test
+ public void testJmsQueueAppenderCompatibility() throws Exception {
+ assertEquals(0, queue.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender");
+ final LogEvent expected = createLogEvent();
+ appender.append(expected);
+ assertEquals(1, queue.size());
+ final Message message = queue.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(ObjectMessage.class));
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Object o = objectMessage.getObject();
+ assertThat(o, instanceOf(LogEvent.class));
+ final LogEvent actual = (LogEvent) o;
+ assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
+ }
+
+ @Test
+ public void testJmsTopicAppenderCompatibility() throws Exception {
+ assertEquals(0, topic.size());
+ final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsTopicAppender");
+ final LogEvent expected = createLogEvent();
+ appender.append(expected);
+ assertEquals(1, topic.size());
+ final Message message = topic.getMessageAt(0);
+ assertNotNull(message);
+ assertThat(message, instanceOf(ObjectMessage.class));
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Object o = objectMessage.getObject();
+ assertThat(o, instanceOf(LogEvent.class));
+ final LogEvent actual = (LogEvent) o;
+ assertEquals(expected.getMessage().getFormattedMessage(), actual.getMessage().getFormattedMessage());
+ }
+
+ private static Log4jLogEvent createLogEvent() {
+ return Log4jLogEvent.newBuilder()
+ .setLoggerName(JmsAppenderTest.class.getName())
+ .setLoggerFqcn(JmsAppenderTest.class.getName())
+ .setLevel(Level.INFO)
+ .setMessage(new SimpleMessage(LOG_MESSAGE))
+ .build();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7aec0b5a/log4j-jms/src/test/resources/JmsAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/resources/JmsAppenderTest.xml b/log4j-jms/src/test/resources/JmsAppenderTest.xml
index ceccbaa..56b3f25 100644
--- a/log4j-jms/src/test/resources/JmsAppenderTest.xml
+++ b/log4j-jms/src/test/resources/JmsAppenderTest.xml
@@ -18,11 +18,22 @@
-->
<Configuration name="JmsAppenderTest" status="OFF">
<Appenders>
- <JMS name="JmsQueueAppender"
- factoryBindingName="jms/activemq"
+ <JMS name="JmsAppender"
+ factoryBindingName="jms/queues"
destinationBindingName="jms/destination">
<PatternLayout pattern="%m"/>
</JMS>
+ <!-- backwards compatibility tests -->
+ <JMSQueue name="JmsQueueAppender"
+ factoryBindingName="jms/queues"
+ queueBindingName="jms/queue">
+ <SerializedLayout/>
+ </JMSQueue>
+ <JMSTopic name="JmsTopicAppender"
+ factoryBindingName="jms/topics"
+ topicBindingName="jms/topic">
+ <SerializedLayout/>
+ </JMSTopic>
</Appenders>
<Loggers>
<Root level="info">
[27/29] git commit: Remove mom package from hierarchy.
Posted by ma...@apache.org.
Remove mom package from hierarchy.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7ddb07bd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7ddb07bd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7ddb07bd
Branch: refs/heads/master
Commit: 7ddb07bd0494d2c045bb98ba922d1b2e2cf56f9f
Parents: 7aec0b5
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:53:53 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:53:53 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/jms/appender/JmsAppender.java | 198 +++++++++++++++++++
.../log4j/jms/appender/package-info.java | 20 ++
.../logging/log4j/jms/manager/JmsManager.java | 169 ++++++++++++++++
.../logging/log4j/jms/manager/JndiManager.java | 125 ++++++++++++
.../log4j/jms/receiver/AbstractJmsReceiver.java | 82 ++++++++
.../log4j/jms/receiver/JmsQueueReceiver.java | 106 ++++++++++
.../log4j/jms/receiver/JmsTopicReceiver.java | 104 ++++++++++
.../log4j/jms/receiver/package-info.java | 25 +++
.../log4j/mom/jms/appender/JmsAppender.java | 198 -------------------
.../log4j/mom/jms/appender/package-info.java | 20 --
.../log4j/mom/jms/manager/JmsManager.java | 169 ----------------
.../log4j/mom/jms/manager/JndiManager.java | 125 ------------
.../mom/jms/receiver/AbstractJmsReceiver.java | 83 --------
.../mom/jms/receiver/JmsQueueReceiver.java | 107 ----------
.../mom/jms/receiver/JmsTopicReceiver.java | 105 ----------
.../log4j/mom/jms/receiver/package-info.java | 25 ---
.../log4j/jms/appender/JmsAppenderIT.java | 126 ++++++++++++
.../log4j/jms/appender/JmsAppenderTest.java | 122 ++++++++++++
.../log4j/mom/jms/appender/JmsAppenderIT.java | 126 ------------
.../log4j/mom/jms/appender/JmsAppenderTest.java | 122 ------------
20 files changed, 1077 insertions(+), 1080 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsAppender.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..d90f203
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/JmsAppender.java
@@ -0,0 +1,198 @@
+/*
+ * 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.io.Serializable;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.jms.manager.JmsManager;
+import org.apache.logging.log4j.jms.manager.JndiManager;
+
+/**
+ * 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.
+ */
+@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
+@PluginAliases({"JMSQueue", "JMSTopic"})
+public class JmsAppender extends AbstractAppender {
+
+ private final JmsManager manager;
+ private final MessageProducer producer;
+
+ protected JmsAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final boolean ignoreExceptions, final JmsManager manager)
+ throws JMSException {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ this.producer = this.manager.createMessageProducer();
+ }
+
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ final Message message = this.manager.createMessage(getLayout().toSerializable(event));
+ message.setJMSTimestamp(event.getTimeMillis());
+ this.producer.send(message);
+ } catch (JMSException e) {
+ throw new AppenderLoggingException(e);
+ }
+ }
+
+ @PluginBuilderFactory
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public static class Builder implements org.apache.logging.log4j.core.util.Builder<JmsAppender> {
+
+ @PluginBuilderAttribute
+ private String name;
+
+ @PluginBuilderAttribute
+ private String factoryName;
+
+ @PluginBuilderAttribute
+ private String providerUrl;
+
+ @PluginBuilderAttribute
+ private String urlPkgPrefixes;
+
+ @PluginBuilderAttribute
+ private String securityPrincipalName;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String securityCredentials;
+
+ @PluginBuilderAttribute
+ private String factoryBindingName;
+
+ @PluginBuilderAttribute
+ @PluginAliases({"queueBindingName", "topicBindingName"})
+ private String destinationBindingName;
+
+ @PluginBuilderAttribute
+ private String username;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String password;
+
+ @PluginElement("Layout")
+ private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
+
+ @PluginElement("Filter")
+ private Filter filter;
+
+ @PluginBuilderAttribute
+ private boolean ignoreExceptions = true;
+
+ private Builder() {
+ }
+
+ public Builder setName(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setFactoryName(final String factoryName) {
+ this.factoryName = factoryName;
+ return this;
+ }
+
+ public Builder setProviderUrl(final String providerUrl) {
+ this.providerUrl = providerUrl;
+ return this;
+ }
+
+ public Builder setUrlPkgPrefixes(final String urlPkgPrefixes) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ return this;
+ }
+
+ public Builder setSecurityPrincipalName(final String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ return this;
+ }
+
+ public Builder setSecurityCredentials(final String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ return this;
+ }
+
+ public Builder setFactoryBindingName(final String factoryBindingName) {
+ this.factoryBindingName = factoryBindingName;
+ return this;
+ }
+
+ public Builder setDestinationBindingName(final String destinationBindingName) {
+ this.destinationBindingName = destinationBindingName;
+ return this;
+ }
+
+ public Builder setUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ public Builder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public Builder setLayout(final Layout<? extends Serializable> layout) {
+ this.layout = layout;
+ return this;
+ }
+
+ public Builder setFilter(final Filter filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public Builder setIgnoreExceptions(final boolean ignoreExceptions) {
+ this.ignoreExceptions = ignoreExceptions;
+ return this;
+ }
+
+ @Override
+ public JmsAppender build() {
+ final JndiManager jndiManager = JndiManager.getJndiManager(factoryName, providerUrl, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, null);
+ final JmsManager jmsManager = JmsManager.getJmsManager(name, jndiManager, factoryBindingName,
+ destinationBindingName, username, password);
+ try {
+ return new JmsAppender(name, filter, layout, ignoreExceptions, jmsManager);
+ } catch (final JMSException e) {
+ LOGGER.error("Error creating JmsAppender [{}].", name, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/package-info.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..26aec37
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/appender/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
+ */
+package org.apache.logging.log4j.jms.appender;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JmsManager.java
new file mode 100644
index 0000000..f6921d2
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JmsManager.java
@@ -0,0 +1,169 @@
+/*
+ * 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.manager;
+
+import java.io.Serializable;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+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.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects
+ * involving a configured ConnectionFactory and Destination.
+ */
+public class JmsManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JmsManagerFactory FACTORY = new JmsManagerFactory();
+
+ private final JndiManager jndiManager;
+ private final Connection connection;
+ private final Session session;
+ private final Destination destination;
+
+ private JmsManager(final String name, final JndiManager jndiManager, final String connectionFactoryName,
+ final String destinationName, final String username, final String password)
+ throws NamingException, JMSException {
+ super(name);
+ this.jndiManager = jndiManager;
+ final ConnectionFactory connectionFactory = this.jndiManager.lookup(connectionFactoryName);
+ if (username != null && password != null) {
+ this.connection = connectionFactory.createConnection(username, password);
+ } else {
+ this.connection = connectionFactory.createConnection();
+ }
+ this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ this.destination = this.jndiManager.lookup(destinationName);
+ this.connection.start();
+ }
+
+ /**
+ * Gets a JmsManager using the specified configuration parameters.
+ *
+ * @param name The name to use for this JmsManager.
+ * @param jndiManager The JndiManager to look up JMS information through.
+ * @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.
+ * @return The JmsManager as configured.
+ */
+ public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
+ final String connectionFactoryName, final String destinationName,
+ final String username, final String password) {
+ final JmsConfiguration configuration = new JmsConfiguration(jndiManager, connectionFactoryName, destinationName,
+ username, password);
+ return FACTORY.createManager(name, configuration);
+ }
+
+ /**
+ * Creates a MessageConsumer on this Destination using the current Session.
+ *
+ * @return A MessageConsumer on this Destination.
+ * @throws JMSException
+ */
+ public MessageConsumer createMessageConsumer() throws JMSException {
+ return this.session.createConsumer(this.destination);
+ }
+
+ /**
+ * Creates a MessageProducer on this Destination using the current Session.
+ *
+ * @return A MessageProducer on this Destination.
+ * @throws JMSException
+ */
+ public MessageProducer createMessageProducer() throws JMSException {
+ return this.session.createProducer(this.destination);
+ }
+
+ /**
+ * Creates a TextMessage or ObjectMessage from a Serializable object. For instance, when using a text-based
+ * {@link org.apache.logging.log4j.core.Layout} such as {@link org.apache.logging.log4j.core.layout.PatternLayout},
+ * the {@link org.apache.logging.log4j.core.LogEvent} message will be serialized to a String. When using a
+ * layout such as {@link org.apache.logging.log4j.core.layout.SerializedLayout}, the LogEvent message will be
+ * serialized as a Java object.
+ *
+ * @param object The LogEvent or String message to wrap.
+ * @return A new JMS message containing the provided object.
+ * @throws JMSException
+ */
+ public Message createMessage(final Serializable object) throws JMSException {
+ if (object instanceof String) {
+ return this.session.createTextMessage((String) object);
+ } else {
+ return this.session.createObjectMessage(object);
+ }
+ }
+
+ @Override
+ protected void releaseSub() {
+ try {
+ this.session.close();
+ } catch (final JMSException ignored) {
+ }
+ try {
+ this.connection.close();
+ } catch (final JMSException ignored) {
+ }
+ this.jndiManager.release();
+ }
+
+ private static class JmsConfiguration {
+ private final JndiManager jndiManager;
+ private final String connectionFactoryName;
+ private final String destinationName;
+ private final String username;
+ private final String password;
+
+ private JmsConfiguration(JndiManager jndiManager, String connectionFactoryName, String destinationName,
+ String username, String password) {
+ this.jndiManager = jndiManager;
+ this.connectionFactoryName = connectionFactoryName;
+ this.destinationName = destinationName;
+ this.username = username;
+ this.password = password;
+ }
+ }
+
+ private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsConfiguration> {
+
+ @Override
+ public JmsManager createManager(String name, JmsConfiguration data) {
+ try {
+ return new JmsManager(name, data.jndiManager, data.connectionFactoryName, data.destinationName,
+ data.username, data.password);
+ } catch (final Exception e) {
+ LOGGER.error("Error creating JmsManager using ConnectionFactory [{}] and Destination [{}].",
+ data.connectionFactoryName, data.destinationName, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JndiManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JndiManager.java
new file mode 100644
index 0000000..c680948
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/manager/JndiManager.java
@@ -0,0 +1,125 @@
+/*
+ * 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.manager;
+
+import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.util.JndiCloser;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JNDI context manager. Mainly useful for finding JMS objects and configuring the InitialContext.
+ */
+public class JndiManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
+
+ private final Context context;
+
+ private JndiManager(String name, Context context) {
+ super(name);
+ this.context = context;
+ }
+
+ /**
+ * Gets a JndiManager with the provided configuration information.
+ *
+ * @param initialContextFactoryName 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 JndiManager for the provided parameters.
+ */
+ public static JndiManager getJndiManager(final String initialContextFactoryName,
+ final String providerURL,
+ final String urlPkgPrefixes,
+ final String securityPrincipal,
+ final String securityCredentials,
+ final Properties additionalProperties) {
+ final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
+ if (initialContextFactoryName == null) {
+ return getManager(name, FACTORY, null);
+ }
+ final Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ properties.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
+ "provider URL. This is likely to cause problems.", initialContextFactoryName);
+ }
+ if (urlPkgPrefixes != null) {
+ properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipal != null) {
+ properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
+ if (securityCredentials != null) {
+ properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
+ securityPrincipal);
+ }
+ }
+ if (additionalProperties != null) {
+ properties.putAll(additionalProperties);
+ }
+ return getManager(name, FACTORY, properties);
+ }
+
+ @Override
+ protected void releaseSub() {
+ JndiCloser.closeSilently(this.context);
+ }
+
+ /**
+ * Looks up a named object through this JNDI context.
+ *
+ * @param name name of the object to look up.
+ * @param <T> the type of the object.
+ * @return the named object if it could be located.
+ * @throws NamingException
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(final String name) throws NamingException {
+ return (T) this.context.lookup(name);
+ }
+
+ private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
+
+ @Override
+ public JndiManager createManager(String name, Properties data) {
+ try {
+ return new JndiManager(name, new InitialContext(data));
+ } catch (final NamingException e) {
+ LOGGER.error("Error creating JNDI InitialContext.", e);
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/AbstractJmsReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/AbstractJmsReceiver.java
new file mode 100644
index 0000000..4d21d83
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/AbstractJmsReceiver.java
@@ -0,0 +1,82 @@
+/*
+ * 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.receiver;
+
+import java.io.Serializable;
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LogEventListener;
+
+/**
+ * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
+ */
+public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
+
+ /**
+ * Logger to capture diagnostics.
+ */
+ protected Logger logger = LogManager.getLogger(this.getClass().getName());
+
+ /**
+ * Listener that receives the event.
+ * @param message The received message.
+ */
+ @Override
+ public void onMessage(final javax.jms.Message message) {
+ try {
+ if (message instanceof ObjectMessage) {
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Serializable object = objectMessage.getObject();
+ if (object instanceof LogEvent) {
+ log((LogEvent) object);
+ } else {
+ logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
+ }
+ } else {
+ logger.warn("Received message is of type " + message.getJMSType()
+ + ", was expecting ObjectMessage.");
+ }
+ } catch (final JMSException jmse) {
+ logger.error("Exception thrown while processing incoming message.",
+ jmse);
+ }
+ }
+
+ /**
+ * Looks up an object from the Context.
+ * @param ctx The Context.
+ * @param name The name of the object to locate.
+ * @return The object.
+ * @throws NamingException if an error occurs.
+ */
+ protected Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ logger.error("Could not find name [" + name + "].");
+ throw e;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsQueueReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsQueueReceiver.java
new file mode 100644
index 0000000..0cd2efb
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsQueueReceiver.java
@@ -0,0 +1,106 @@
+/*
+ * 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.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Log Events over a JMS Queue. This implementation expects that all messages will
+ * contain a serialized LogEvent.
+ */
+public class JmsQueueReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param qcfBindingName The QueueConnectionFactory binding name.
+ * @param queueBindingName The Queue binding name.
+ * @param username The userid to connect to the queue.
+ * @param password The password to connect to the queue.
+ */
+ public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
+ final String password) {
+
+ try {
+ final Context ctx = new InitialContext();
+ QueueConnectionFactory queueConnectionFactory;
+ queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
+ final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
+ queueConnection.start();
+ final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) ctx.lookup(queueBindingName);
+ final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
+ queueReceiver.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String qcfBindingName = args[0];
+ final String queueBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
+ + " QueueConnectionFactoryBindingName QueueBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsTopicReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsTopicReceiver.java
new file mode 100644
index 0000000..31c0354
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/JmsTopicReceiver.java
@@ -0,0 +1,104 @@
+/*
+ * 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.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Topic messages that contain LogEvents. This implementation expects that all messages
+ * are serialized log events.
+ */
+public class JmsTopicReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param tcfBindingName The TopicConnectionFactory binding name.
+ * @param topicBindingName The Topic binding name.
+ * @param username The userid to connect to the topic.
+ * @param password The password to connect to the topic.
+ */
+ public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
+ final String password) {
+ try {
+ final Context ctx = new InitialContext();
+ TopicConnectionFactory topicConnectionFactory;
+ topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
+ final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
+ topicConnection.start();
+ final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) ctx.lookup(topicBindingName);
+ final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
+ topicSubscriber.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String tcfBindingName = args[0];
+ final String topicBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
+ + " TopicConnectionFactoryBindingName TopicBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/package-info.java
new file mode 100644
index 0000000..b53fd95
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/jms/receiver/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/**
+ * Supporting network code for JMS appenders.
+ * <p/>
+ * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
+ * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
+ * the running process. Of course, use of these classes as standalone executables are entirely optional and can
+ * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
+ */
+package org.apache.logging.log4j.jms.receiver;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
deleted file mode 100644
index f99e890..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
+++ /dev/null
@@ -1,198 +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.mom.jms.appender;
-
-import java.io.Serializable;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-
-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.AppenderLoggingException;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAliases;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.layout.SerializedLayout;
-import org.apache.logging.log4j.mom.jms.manager.JmsManager;
-import org.apache.logging.log4j.mom.jms.manager.JndiManager;
-
-/**
- * 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.
- */
-@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
-@PluginAliases({"JMSQueue", "JMSTopic"})
-public class JmsAppender extends AbstractAppender {
-
- private final JmsManager manager;
- private final MessageProducer producer;
-
- protected JmsAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
- final boolean ignoreExceptions, final JmsManager manager)
- throws JMSException {
- super(name, filter, layout, ignoreExceptions);
- this.manager = manager;
- this.producer = this.manager.createMessageProducer();
- }
-
- @Override
- public void append(final LogEvent event) {
- try {
- final Message message = this.manager.createMessage(getLayout().toSerializable(event));
- message.setJMSTimestamp(event.getTimeMillis());
- this.producer.send(message);
- } catch (JMSException e) {
- throw new AppenderLoggingException(e);
- }
- }
-
- @PluginBuilderFactory
- public static Builder newBuilder() {
- return new Builder();
- }
-
- public static class Builder implements org.apache.logging.log4j.core.util.Builder<JmsAppender> {
-
- @PluginBuilderAttribute
- private String name;
-
- @PluginBuilderAttribute
- private String factoryName;
-
- @PluginBuilderAttribute
- private String providerUrl;
-
- @PluginBuilderAttribute
- private String urlPkgPrefixes;
-
- @PluginBuilderAttribute
- private String securityPrincipalName;
-
- @PluginBuilderAttribute(sensitive = true)
- private String securityCredentials;
-
- @PluginBuilderAttribute
- private String factoryBindingName;
-
- @PluginBuilderAttribute
- @PluginAliases({"queueBindingName", "topicBindingName"})
- private String destinationBindingName;
-
- @PluginBuilderAttribute
- private String username;
-
- @PluginBuilderAttribute(sensitive = true)
- private String password;
-
- @PluginElement("Layout")
- private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
-
- @PluginElement("Filter")
- private Filter filter;
-
- @PluginBuilderAttribute
- private boolean ignoreExceptions = true;
-
- private Builder() {
- }
-
- public Builder setName(final String name) {
- this.name = name;
- return this;
- }
-
- public Builder setFactoryName(final String factoryName) {
- this.factoryName = factoryName;
- return this;
- }
-
- public Builder setProviderUrl(final String providerUrl) {
- this.providerUrl = providerUrl;
- return this;
- }
-
- public Builder setUrlPkgPrefixes(final String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- return this;
- }
-
- public Builder setSecurityPrincipalName(final String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- return this;
- }
-
- public Builder setSecurityCredentials(final String securityCredentials) {
- this.securityCredentials = securityCredentials;
- return this;
- }
-
- public Builder setFactoryBindingName(final String factoryBindingName) {
- this.factoryBindingName = factoryBindingName;
- return this;
- }
-
- public Builder setDestinationBindingName(final String destinationBindingName) {
- this.destinationBindingName = destinationBindingName;
- return this;
- }
-
- public Builder setUsername(final String username) {
- this.username = username;
- return this;
- }
-
- public Builder setPassword(final String password) {
- this.password = password;
- return this;
- }
-
- public Builder setLayout(final Layout<? extends Serializable> layout) {
- this.layout = layout;
- return this;
- }
-
- public Builder setFilter(final Filter filter) {
- this.filter = filter;
- return this;
- }
-
- public Builder setIgnoreExceptions(final boolean ignoreExceptions) {
- this.ignoreExceptions = ignoreExceptions;
- return this;
- }
-
- @Override
- public JmsAppender build() {
- final JndiManager jndiManager = JndiManager.getJndiManager(factoryName, providerUrl, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, null);
- final JmsManager jmsManager = JmsManager.getJmsManager(name, jndiManager, factoryBindingName,
- destinationBindingName, username, password);
- try {
- return new JmsAppender(name, filter, layout, ignoreExceptions, jmsManager);
- } catch (final JMSException e) {
- LOGGER.error("Error creating JmsAppender [{}].", name, e);
- return null;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
deleted file mode 100644
index 0c7a4ff..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-/**
- * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
- */
-package org.apache.logging.log4j.mom.jms.appender;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
deleted file mode 100644
index d3ce550..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
+++ /dev/null
@@ -1,169 +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.mom.jms.manager;
-
-import java.io.Serializable;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-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.Logger;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects
- * involving a configured ConnectionFactory and Destination.
- */
-public class JmsManager extends AbstractManager {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private static final JmsManagerFactory FACTORY = new JmsManagerFactory();
-
- private final JndiManager jndiManager;
- private final Connection connection;
- private final Session session;
- private final Destination destination;
-
- private JmsManager(final String name, final JndiManager jndiManager, final String connectionFactoryName,
- final String destinationName, final String username, final String password)
- throws NamingException, JMSException {
- super(name);
- this.jndiManager = jndiManager;
- final ConnectionFactory connectionFactory = this.jndiManager.lookup(connectionFactoryName);
- if (username != null && password != null) {
- this.connection = connectionFactory.createConnection(username, password);
- } else {
- this.connection = connectionFactory.createConnection();
- }
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- this.destination = this.jndiManager.lookup(destinationName);
- this.connection.start();
- }
-
- /**
- * Gets a JmsManager using the specified configuration parameters.
- *
- * @param name The name to use for this JmsManager.
- * @param jndiManager The JndiManager to look up JMS information through.
- * @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.
- * @return The JmsManager as configured.
- */
- public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
- final String connectionFactoryName, final String destinationName,
- final String username, final String password) {
- final JmsConfiguration configuration = new JmsConfiguration(jndiManager, connectionFactoryName, destinationName,
- username, password);
- return FACTORY.createManager(name, configuration);
- }
-
- /**
- * Creates a MessageConsumer on this Destination using the current Session.
- *
- * @return A MessageConsumer on this Destination.
- * @throws JMSException
- */
- public MessageConsumer createMessageConsumer() throws JMSException {
- return this.session.createConsumer(this.destination);
- }
-
- /**
- * Creates a MessageProducer on this Destination using the current Session.
- *
- * @return A MessageProducer on this Destination.
- * @throws JMSException
- */
- public MessageProducer createMessageProducer() throws JMSException {
- return this.session.createProducer(this.destination);
- }
-
- /**
- * Creates a TextMessage or ObjectMessage from a Serializable object. For instance, when using a text-based
- * {@link org.apache.logging.log4j.core.Layout} such as {@link org.apache.logging.log4j.core.layout.PatternLayout},
- * the {@link org.apache.logging.log4j.core.LogEvent} message will be serialized to a String. When using a
- * layout such as {@link org.apache.logging.log4j.core.layout.SerializedLayout}, the LogEvent message will be
- * serialized as a Java object.
- *
- * @param object The LogEvent or String message to wrap.
- * @return A new JMS message containing the provided object.
- * @throws JMSException
- */
- public Message createMessage(final Serializable object) throws JMSException {
- if (object instanceof String) {
- return this.session.createTextMessage((String) object);
- } else {
- return this.session.createObjectMessage(object);
- }
- }
-
- @Override
- protected void releaseSub() {
- try {
- this.session.close();
- } catch (final JMSException ignored) {
- }
- try {
- this.connection.close();
- } catch (final JMSException ignored) {
- }
- this.jndiManager.release();
- }
-
- private static class JmsConfiguration {
- private final JndiManager jndiManager;
- private final String connectionFactoryName;
- private final String destinationName;
- private final String username;
- private final String password;
-
- private JmsConfiguration(JndiManager jndiManager, String connectionFactoryName, String destinationName,
- String username, String password) {
- this.jndiManager = jndiManager;
- this.connectionFactoryName = connectionFactoryName;
- this.destinationName = destinationName;
- this.username = username;
- this.password = password;
- }
- }
-
- private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsConfiguration> {
-
- @Override
- public JmsManager createManager(String name, JmsConfiguration data) {
- try {
- return new JmsManager(name, data.jndiManager, data.connectionFactoryName, data.destinationName,
- data.username, data.password);
- } catch (final Exception e) {
- LOGGER.error("Error creating JmsManager using ConnectionFactory [{}] and Destination [{}].",
- data.connectionFactoryName, data.destinationName, e);
- return null;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
deleted file mode 100644
index 873b7f4..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
+++ /dev/null
@@ -1,125 +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.mom.jms.manager;
-
-import java.util.Properties;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.util.JndiCloser;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * JNDI context manager. Mainly useful for finding JMS objects and configuring the InitialContext.
- */
-public class JndiManager extends AbstractManager {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
-
- private final Context context;
-
- private JndiManager(String name, Context context) {
- super(name);
- this.context = context;
- }
-
- /**
- * Gets a JndiManager with the provided configuration information.
- *
- * @param initialContextFactoryName 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 JndiManager for the provided parameters.
- */
- public static JndiManager getJndiManager(final String initialContextFactoryName,
- final String providerURL,
- final String urlPkgPrefixes,
- final String securityPrincipal,
- final String securityCredentials,
- final Properties additionalProperties) {
- final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
- if (initialContextFactoryName == null) {
- return getManager(name, FACTORY, null);
- }
- final Properties properties = new Properties();
- properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- properties.setProperty(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
- "provider URL. This is likely to cause problems.", initialContextFactoryName);
- }
- if (urlPkgPrefixes != null) {
- properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipal != null) {
- properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
- if (securityCredentials != null) {
- properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
- securityPrincipal);
- }
- }
- if (additionalProperties != null) {
- properties.putAll(additionalProperties);
- }
- return getManager(name, FACTORY, properties);
- }
-
- @Override
- protected void releaseSub() {
- JndiCloser.closeSilently(this.context);
- }
-
- /**
- * Looks up a named object through this JNDI context.
- *
- * @param name name of the object to look up.
- * @param <T> the type of the object.
- * @return the named object if it could be located.
- * @throws NamingException
- */
- @SuppressWarnings("unchecked")
- public <T> T lookup(final String name) throws NamingException {
- return (T) this.context.lookup(name);
- }
-
- private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
-
- @Override
- public JndiManager createManager(String name, Properties data) {
- try {
- return new JndiManager(name, new InitialContext(data));
- } catch (final NamingException e) {
- LOGGER.error("Error creating JNDI InitialContext.", e);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
deleted file mode 100644
index bf86c65..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
+++ /dev/null
@@ -1,83 +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.mom.jms.receiver;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.ObjectMessage;
-import javax.naming.Context;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LogEventListener;
-
-/**
- * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
- */
-public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
-
- /**
- * Logger to capture diagnostics.
- */
- protected Logger logger = LogManager.getLogger(this.getClass().getName());
-
- /**
- * Listener that receives the event.
- * @param message The received message.
- */
- @Override
- public void onMessage(final javax.jms.Message message) {
- try {
- if (message instanceof ObjectMessage) {
- final ObjectMessage objectMessage = (ObjectMessage) message;
- final Serializable object = objectMessage.getObject();
- if (object instanceof LogEvent) {
- log((LogEvent) object);
- } else {
- logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
- }
- } else {
- logger.warn("Received message is of type " + message.getJMSType()
- + ", was expecting ObjectMessage.");
- }
- } catch (final JMSException jmse) {
- logger.error("Exception thrown while processing incoming message.",
- jmse);
- }
- }
-
- /**
- * Looks up an object from the Context.
- * @param ctx The Context.
- * @param name The name of the object to locate.
- * @return The object.
- * @throws NamingException if an error occurs.
- */
- protected Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- logger.error("Could not find name [" + name + "].");
- throw e;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
deleted file mode 100644
index b231489..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
+++ /dev/null
@@ -1,107 +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.mom.jms.receiver;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Log Events over a JMS Queue. This implementation expects that all messages will
- * contain a serialized LogEvent.
- */
-public class JmsQueueReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param qcfBindingName The QueueConnectionFactory binding name.
- * @param queueBindingName The Queue binding name.
- * @param username The userid to connect to the queue.
- * @param password The password to connect to the queue.
- */
- public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
- final String password) {
-
- try {
- final Context ctx = new InitialContext();
- QueueConnectionFactory queueConnectionFactory;
- queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
- final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
- queueConnection.start();
- final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) ctx.lookup(queueBindingName);
- final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
- queueReceiver.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String qcfBindingName = args[0];
- final String queueBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
- + " QueueConnectionFactoryBindingName QueueBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
deleted file mode 100644
index 0149ee5..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
+++ /dev/null
@@ -1,105 +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.mom.jms.receiver;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicSession;
-import javax.jms.TopicSubscriber;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Topic messages that contain LogEvents. This implementation expects that all messages
- * are serialized log events.
- */
-public class JmsTopicReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param tcfBindingName The TopicConnectionFactory binding name.
- * @param topicBindingName The Topic binding name.
- * @param username The userid to connect to the topic.
- * @param password The password to connect to the topic.
- */
- public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
- final String password) {
- try {
- final Context ctx = new InitialContext();
- TopicConnectionFactory topicConnectionFactory;
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
- final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
- topicConnection.start();
- final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) ctx.lookup(topicBindingName);
- final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
- topicSubscriber.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String tcfBindingName = args[0];
- final String topicBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
- + " TopicConnectionFactoryBindingName TopicBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
deleted file mode 100644
index 1f233e8..0000000
--- a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
+++ /dev/null
@@ -1,25 +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.
- */
-/**
- * Supporting network code for JMS appenders.
- * <p/>
- * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
- * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
- * the running process. Of course, use of these classes as standalone executables are entirely optional and can
- * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
- */
-package org.apache.logging.log4j.mom.jms.receiver;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ddb07bd/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderIT.java b/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderIT.java
new file mode 100644
index 0000000..fad68e5
--- /dev/null
+++ b/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderIT.java
@@ -0,0 +1,126 @@
+/*
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+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.layout.SerializedLayout;
+import org.apache.logging.log4j.jms.manager.JmsManager;
+import org.apache.logging.log4j.jms.manager.JndiManager;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Integration test for JmsAppender using an embedded ActiveMQ broker.
+ */
+public class JmsAppenderIT {
+
+ private static JmsManager jmsManager;
+
+ private JmsAppender appender;
+
+ @BeforeClass
+ public static void setUpClass() {
+ final Properties additional = new Properties();
+ additional.setProperty("queue.TestQueue", "TestQueue");
+ JndiManager jndiManager = JndiManager.getJndiManager(ActiveMQInitialContextFactory.class.getName(),
+ "vm://localhost?broker.persistent=false", null, null, null, additional);
+ jmsManager = JmsManager.getJmsManager("JmsManager", jndiManager, "ConnectionFactory", "TestQueue", null, null);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ jmsManager.release();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ appender = new JmsAppender("JmsAppender", null, SerializedLayout.createLayout(), true, jmsManager);
+ appender.start();
+ }
+
+ @Test
+ public void testLogToQueue() throws Exception {
+ final int messageCount = 100;
+ final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
+ final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount);
+ messageConsumer.setMessageListener(consumer);
+ final String messageText = "Hello, World!";
+ final String loggerName = this.getClass().getName();
+ for (int i = 0; i < messageCount; i++) {
+ final LogEvent event = Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.ERROR,
+ new SimpleMessage(messageText), null, null, null, null, Thread.currentThread().getName(), null,
+ System.currentTimeMillis());
+ appender.append(event);
+ }
+ consumer.awaitAndAssertAllMessagesConsumed();
+ }
+
+ private static class JmsQueueConsumer implements MessageListener {
+
+ private final int messageCount;
+ private final CountDownLatch countDownLatch;
+ private final Collection<LogEvent> events;
+
+ private JmsQueueConsumer(final int messageCount) {
+ this.messageCount = messageCount;
+ this.countDownLatch = new CountDownLatch(messageCount);
+ this.events = new ArrayList<LogEvent>(messageCount);
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ try {
+ consume((ObjectMessage) message);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void consume(ObjectMessage message) throws JMSException {
+ try {
+ final LogEvent event = (LogEvent) message.getObject();
+ events.add(event);
+ } finally {
+ countDownLatch.countDown();
+ }
+ }
+
+ public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
+ countDownLatch.await(5, TimeUnit.SECONDS);
+ assertEquals(messageCount, events.size());
+ }
+ }
+}
[28/29] git commit: Add copyright header.
Posted by ma...@apache.org.
Add copyright header.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f4721c24
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f4721c24
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f4721c24
Branch: refs/heads/master
Commit: f4721c24e2703c27262349949a8daaa8bd5061fd
Parents: 7ddb07b
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 23:54:27 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 23:54:27 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/jms/appender/JmsAppenderTest.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f4721c24/log4j-jms/src/test/java/org/apache/logging/log4j/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
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
index 55268cc..1babed2 100644
--- 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
@@ -1,3 +1,19 @@
+/*
+ * 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 javax.jms.Message;
[19/29] git commit: Rename log4j-mom to log4j-jms.
Posted by ma...@apache.org.
Rename log4j-mom to log4j-jms.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/89304e88
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/89304e88
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/89304e88
Branch: refs/heads/master
Commit: 89304e886075dffefd53ca5430d98ee4994fe2e3
Parents: e1db6e2
Author: Matt Sicker <bo...@gmail.com>
Authored: Sat Aug 30 17:18:04 2014 -0500
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sat Aug 30 17:18:04 2014 -0500
----------------------------------------------------------------------
log4j-jms/pom.xml | 69 ++++++
.../log4j/mom/jms/appender/JmsAppender.java | 195 +++++++++++++++
.../mom/jms/appender/JmsQueueAppender.java | 113 +++++++++
.../mom/jms/appender/JmsTopicAppender.java | 114 +++++++++
.../log4j/mom/jms/appender/package-info.java | 20 ++
.../mom/jms/manager/AbstractJmsManager.java | 156 ++++++++++++
.../log4j/mom/jms/manager/JmsManager.java | 169 +++++++++++++
.../log4j/mom/jms/manager/JmsQueueManager.java | 237 +++++++++++++++++++
.../log4j/mom/jms/manager/JmsTopicManager.java | 237 +++++++++++++++++++
.../log4j/mom/jms/manager/JndiManager.java | 125 ++++++++++
.../mom/jms/receiver/AbstractJmsReceiver.java | 83 +++++++
.../mom/jms/receiver/JmsQueueReceiver.java | 107 +++++++++
.../mom/jms/receiver/JmsTopicReceiver.java | 105 ++++++++
.../log4j/mom/jms/receiver/package-info.java | 25 ++
.../log4j/mom/jms/appender/JmsAppenderIT.java | 126 ++++++++++
.../log4j/mom/jms/appender/JmsAppenderTest.java | 79 +++++++
.../mom/jms/appender/JmsQueueAppenderTest.java | 85 +++++++
.../mom/jms/appender/JmsQueueFailoverTest.java | 122 ++++++++++
.../log4j/mom/jms/appender/JmsQueueTest.java | 147 ++++++++++++
.../mom/jms/appender/JmsTopicFailoverTest.java | 121 ++++++++++
.../log4j/mom/jms/appender/JmsTopicTest.java | 147 ++++++++++++
.../src/test/resources/JmsAppenderTest.xml | 32 +++
.../test/resources/log4j-jmsqueue-failover.xml | 52 ++++
log4j-jms/src/test/resources/log4j-jmsqueue.xml | 30 +++
.../test/resources/log4j-jmstopic-failover.xml | 52 ++++
log4j-mom/pom.xml | 73 ------
.../log4j/mom/jms/appender/JmsAppender.java | 195 ---------------
.../mom/jms/appender/JmsQueueAppender.java | 113 ---------
.../mom/jms/appender/JmsTopicAppender.java | 114 ---------
.../log4j/mom/jms/appender/package-info.java | 20 --
.../mom/jms/manager/AbstractJmsManager.java | 156 ------------
.../log4j/mom/jms/manager/JmsManager.java | 169 -------------
.../log4j/mom/jms/manager/JmsQueueManager.java | 237 -------------------
.../log4j/mom/jms/manager/JmsTopicManager.java | 237 -------------------
.../log4j/mom/jms/manager/JndiManager.java | 125 ----------
.../mom/jms/receiver/AbstractJmsReceiver.java | 83 -------
.../mom/jms/receiver/JmsQueueReceiver.java | 107 ---------
.../mom/jms/receiver/JmsTopicReceiver.java | 105 --------
.../log4j/mom/jms/receiver/package-info.java | 25 --
.../log4j/mom/jms/appender/JmsAppenderIT.java | 126 ----------
.../log4j/mom/jms/appender/JmsAppenderTest.java | 79 -------
.../mom/jms/appender/JmsQueueAppenderTest.java | 85 -------
.../mom/jms/appender/JmsQueueFailoverTest.java | 122 ----------
.../log4j/mom/jms/appender/JmsQueueTest.java | 147 ------------
.../mom/jms/appender/JmsTopicFailoverTest.java | 121 ----------
.../log4j/mom/jms/appender/JmsTopicTest.java | 147 ------------
.../src/test/resources/JmsAppenderTest.xml | 32 ---
.../test/resources/log4j-jmsqueue-failover.xml | 52 ----
log4j-mom/src/test/resources/log4j-jmsqueue.xml | 30 ---
.../test/resources/log4j-jmstopic-failover.xml | 52 ----
pom.xml | 7 +-
51 files changed, 2749 insertions(+), 2758 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-jms/pom.xml b/log4j-jms/pom.xml
new file mode 100644
index 0000000..21bbb42
--- /dev/null
+++ b/log4j-jms/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <artifactId>log4j</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <version>2.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>log4j-jms</artifactId>
+ <name>Log4j 2 JMS Plugins</name>
+ <description>JMS appender plugins for Log4j 2</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.spec.javax.jms</groupId>
+ <artifactId>jboss-jms-api_1.1_spec</artifactId>
+ </dependency>
+
+ <!-- tests -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockejb</groupId>
+ <artifactId>mockejb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- integration tests -->
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-broker</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
new file mode 100644
index 0000000..c98e2a1
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsAppender.java
@@ -0,0 +1,195 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsManager;
+import org.apache.logging.log4j.mom.jms.manager.JndiManager;
+
+/**
+ * Generic JMS appender plugin for both queues and topics.
+ */
+@Plugin(name = "JMS", category = "Core", elementType = "appender", printObject = true)
+// TODO: use @PluginAliases to make the separated plugins work through this one
+public class JmsAppender extends AbstractAppender {
+
+ private final JmsManager manager;
+ private final MessageProducer producer;
+
+ protected JmsAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final boolean ignoreExceptions, final JmsManager manager)
+ throws JMSException {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ this.producer = this.manager.createMessageProducer();
+ }
+
+ @Override
+ public void append(LogEvent event) {
+ try {
+ final Message message = this.manager.createMessage(getLayout().toSerializable(event));
+ message.setJMSTimestamp(event.getTimeMillis());
+ this.producer.send(message);
+ } catch (JMSException e) {
+ throw new AppenderLoggingException(e);
+ }
+ }
+
+ @PluginBuilderFactory
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public static class Builder implements org.apache.logging.log4j.core.util.Builder<JmsAppender> {
+
+ @PluginBuilderAttribute
+ private String name;
+
+ @PluginBuilderAttribute
+ private String factoryName;
+
+ @PluginBuilderAttribute
+ private String providerUrl;
+
+ @PluginBuilderAttribute
+ private String urlPkgPrefixes;
+
+ @PluginBuilderAttribute
+ private String securityPrincipalName;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String securityCredentials;
+
+ @PluginBuilderAttribute
+ private String factoryBindingName;
+
+ @PluginBuilderAttribute
+ private String destinationBindingName;
+
+ @PluginBuilderAttribute
+ private String username;
+
+ @PluginBuilderAttribute(sensitive = true)
+ private String password;
+
+ @PluginElement("Layout")
+ private Layout<? extends Serializable> layout = SerializedLayout.createLayout();
+
+ @PluginElement("Filter")
+ private Filter filter;
+
+ @PluginBuilderAttribute
+ private boolean ignoreExceptions = true;
+
+ private Builder() {
+ }
+
+ public Builder setName(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setFactoryName(final String factoryName) {
+ this.factoryName = factoryName;
+ return this;
+ }
+
+ public Builder setProviderUrl(final String providerUrl) {
+ this.providerUrl = providerUrl;
+ return this;
+ }
+
+ public Builder setUrlPkgPrefixes(final String urlPkgPrefixes) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ return this;
+ }
+
+ public Builder setSecurityPrincipalName(final String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ return this;
+ }
+
+ public Builder setSecurityCredentials(final String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ return this;
+ }
+
+ public Builder setFactoryBindingName(final String factoryBindingName) {
+ this.factoryBindingName = factoryBindingName;
+ return this;
+ }
+
+ public Builder setDestinationBindingName(final String destinationBindingName) {
+ this.destinationBindingName = destinationBindingName;
+ return this;
+ }
+
+ public Builder setUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ public Builder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public Builder setLayout(final Layout<? extends Serializable> layout) {
+ this.layout = layout;
+ return this;
+ }
+
+ public Builder setFilter(final Filter filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public Builder setIgnoreExceptions(final boolean ignoreExceptions) {
+ this.ignoreExceptions = ignoreExceptions;
+ return this;
+ }
+
+ @Override
+ public JmsAppender build() {
+ final JndiManager jndiManager = JndiManager.getJndiManager(factoryName, providerUrl, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, null);
+ final JmsManager jmsManager = JmsManager.getJmsManager(name, jndiManager, factoryBindingName,
+ destinationBindingName, username, password);
+ try {
+ return new JmsAppender(name, filter, layout, ignoreExceptions, jmsManager);
+ } catch (final JMSException e) {
+ LOGGER.error("Error creating JmsAppender [{}].", name, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
new file mode 100644
index 0000000..4a544e4
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppender.java
@@ -0,0 +1,113 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsQueueManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Queue.
+ */
+@Plugin(name = "JMSQueue", category = "Core", elementType = "appender", printObject = true)
+public final class JmsQueueAppender extends AbstractAppender {
+
+ private static final long serialVersionUID = 1L;
+
+ private final JmsQueueManager manager;
+
+ private JmsQueueAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsQueueManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ *
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsQueueAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The user ID to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsQueueAppender.
+ */
+ @PluginFactory
+ public static JmsQueueAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("queueBindingName") final String queueBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsQueueManager manager = JmsQueueManager.getJmsQueueManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsQueueAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
new file mode 100644
index 0000000..1b000ce
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicAppender.java
@@ -0,0 +1,114 @@
+/*
+ * 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.mom.jms.appender;
+
+import java.io.Serializable;
+
+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.AppenderLoggingException;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.logging.log4j.mom.jms.manager.JmsTopicManager;
+import org.apache.logging.log4j.core.util.Booleans;
+
+/**
+ * Appender to write to a JMS Topic.
+ */
+@Plugin(name = "JMSTopic", category = "Core", elementType = "appender", printObject = true)
+public final class JmsTopicAppender extends AbstractAppender {
+
+ private static final long serialVersionUID = 1L;
+
+ private final JmsTopicManager manager;
+
+ private JmsTopicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout,
+ final JmsTopicManager manager, final boolean ignoreExceptions) {
+ super(name, filter, layout, ignoreExceptions);
+ this.manager = manager;
+ }
+
+ /**
+ * Actual writing occurs here.
+ * <p/>
+ * @param event The LogEvent.
+ */
+ @Override
+ public void append(final LogEvent event) {
+ try {
+ manager.send(getLayout().toSerializable(event));
+ } catch (final Exception ex) {
+ throw new AppenderLoggingException(ex);
+ }
+ }
+
+ /**
+ * Create a JmsTopicAppender.
+ * @param name The name of the Appender.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @param layout The layout to use (defaults to SerializedLayout).
+ * @param filter The Filter or null.
+ * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+ * they are propagated to the caller.
+ * @return The JmsTopicAppender.
+ */
+ @PluginFactory
+ public static JmsTopicAppender createAppender(
+ @PluginAttribute("name") final String name,
+ @PluginAttribute("factoryName") final String factoryName,
+ @PluginAttribute("providerURL") final String providerURL,
+ @PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
+ @PluginAttribute("securityPrincipalName") final String securityPrincipalName,
+ @PluginAttribute("securityCredentials") final String securityCredentials,
+ @PluginAttribute("factoryBindingName") final String factoryBindingName,
+ @PluginAttribute("topicBindingName") final String topicBindingName,
+ @PluginAttribute("userName") final String userName,
+ @PluginAttribute("password") final String password,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("ignoreExceptions") final String ignore) {
+
+ if (name == null) {
+ LOGGER.error("No name provided for JmsQueueAppender");
+ return null;
+ }
+ final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+ final JmsTopicManager manager = JmsTopicManager.getJmsTopicManager(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
+ if (manager == null) {
+ return null;
+ }
+ if (layout == null) {
+ layout = SerializedLayout.createLayout();
+ }
+ return new JmsTopicAppender(name, filter, layout, manager, ignoreExceptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
new file mode 100644
index 0000000..0c7a4ff
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/appender/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Appender classes for using JMS. These are directly configured through your log4j2 configuration file.
+ */
+package org.apache.logging.log4j.mom.jms.appender;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
new file mode 100644
index 0000000..e53b175
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/AbstractJmsManager.java
@@ -0,0 +1,156 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.AbstractManager;
+
+/**
+ * Base Class for Managers of JMS connections.
+ */
+public abstract class AbstractJmsManager extends AbstractManager {
+
+ /**
+ * The Constructor.
+ * @param name The name of the Appender.
+ */
+ public AbstractJmsManager(final String name) {
+ super(name);
+ }
+
+ /**
+ * Create the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return the InitialContext.
+ * @throws NamingException if a naming error occurs.
+ */
+ protected static Context createContext(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials)
+ throws NamingException {
+
+ final Properties props = getEnvironment(factoryName, providerURL, urlPkgPrefixes, securityPrincipalName,
+ securityCredentials);
+ return new InitialContext(props);
+ }
+
+ /**
+ * Looks up the name in the context.
+ * @param ctx The Context.
+ * @param name The name to locate.
+ * @return The object to be located.
+ * @throws NamingException If an error occurs locating the name.
+ */
+ protected static Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ LOGGER.warn("Could not find name [{}].", name);
+ throw e;
+ }
+ }
+
+ /**
+ * Sets up the properties to pass to the InitialContext.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @return The Properties.
+ * @see javax.naming.Context
+ */
+ protected static Properties getEnvironment(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials) {
+ final Properties props = new Properties();
+ if (factoryName != null) {
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);
+ if (providerURL != null) {
+ props.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The InitialContext factory name has been provided without a ProviderURL. " +
+ "This is likely to cause problems");
+ }
+ if (urlPkgPrefixes != null) {
+ props.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipalName != null) {
+ props.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ props.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("SecurityPrincipalName has been set without SecurityCredentials. " +
+ "This is likely to cause problems.");
+ }
+ }
+ return props;
+ }
+ return null;
+ }
+
+ /**
+ * Send the message.
+ * @param object The Object to sent.
+ * @throws Exception if an error occurs.
+ */
+ public abstract void send(Serializable object) throws Exception;
+
+ /**
+ * Send the Object.
+ * @param object The Object to send.
+ * @param session The Session.
+ * @param producer The MessageProducer.
+ * @throws Exception if an error occurs.
+ */
+ public synchronized void send(final Serializable object, final Session session, final MessageProducer producer)
+ throws Exception {
+ try {
+ Message msg;
+ if (object instanceof String) {
+ msg = session.createTextMessage();
+ ((TextMessage) msg).setText((String) object);
+ } else {
+ msg = session.createObjectMessage();
+ ((ObjectMessage) msg).setObject(object);
+ }
+ producer.send(msg);
+ } catch (final JMSException ex) {
+ LOGGER.error("Could not publish message via JMS {}", getName());
+ throw ex;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
new file mode 100644
index 0000000..d3ce550
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsManager.java
@@ -0,0 +1,169 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+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.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JMS connection and session manager. Can be used to access MessageProducer, MessageConsumer, and Message objects
+ * involving a configured ConnectionFactory and Destination.
+ */
+public class JmsManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JmsManagerFactory FACTORY = new JmsManagerFactory();
+
+ private final JndiManager jndiManager;
+ private final Connection connection;
+ private final Session session;
+ private final Destination destination;
+
+ private JmsManager(final String name, final JndiManager jndiManager, final String connectionFactoryName,
+ final String destinationName, final String username, final String password)
+ throws NamingException, JMSException {
+ super(name);
+ this.jndiManager = jndiManager;
+ final ConnectionFactory connectionFactory = this.jndiManager.lookup(connectionFactoryName);
+ if (username != null && password != null) {
+ this.connection = connectionFactory.createConnection(username, password);
+ } else {
+ this.connection = connectionFactory.createConnection();
+ }
+ this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ this.destination = this.jndiManager.lookup(destinationName);
+ this.connection.start();
+ }
+
+ /**
+ * Gets a JmsManager using the specified configuration parameters.
+ *
+ * @param name The name to use for this JmsManager.
+ * @param jndiManager The JndiManager to look up JMS information through.
+ * @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.
+ * @return The JmsManager as configured.
+ */
+ public static JmsManager getJmsManager(final String name, final JndiManager jndiManager,
+ final String connectionFactoryName, final String destinationName,
+ final String username, final String password) {
+ final JmsConfiguration configuration = new JmsConfiguration(jndiManager, connectionFactoryName, destinationName,
+ username, password);
+ return FACTORY.createManager(name, configuration);
+ }
+
+ /**
+ * Creates a MessageConsumer on this Destination using the current Session.
+ *
+ * @return A MessageConsumer on this Destination.
+ * @throws JMSException
+ */
+ public MessageConsumer createMessageConsumer() throws JMSException {
+ return this.session.createConsumer(this.destination);
+ }
+
+ /**
+ * Creates a MessageProducer on this Destination using the current Session.
+ *
+ * @return A MessageProducer on this Destination.
+ * @throws JMSException
+ */
+ public MessageProducer createMessageProducer() throws JMSException {
+ return this.session.createProducer(this.destination);
+ }
+
+ /**
+ * Creates a TextMessage or ObjectMessage from a Serializable object. For instance, when using a text-based
+ * {@link org.apache.logging.log4j.core.Layout} such as {@link org.apache.logging.log4j.core.layout.PatternLayout},
+ * the {@link org.apache.logging.log4j.core.LogEvent} message will be serialized to a String. When using a
+ * layout such as {@link org.apache.logging.log4j.core.layout.SerializedLayout}, the LogEvent message will be
+ * serialized as a Java object.
+ *
+ * @param object The LogEvent or String message to wrap.
+ * @return A new JMS message containing the provided object.
+ * @throws JMSException
+ */
+ public Message createMessage(final Serializable object) throws JMSException {
+ if (object instanceof String) {
+ return this.session.createTextMessage((String) object);
+ } else {
+ return this.session.createObjectMessage(object);
+ }
+ }
+
+ @Override
+ protected void releaseSub() {
+ try {
+ this.session.close();
+ } catch (final JMSException ignored) {
+ }
+ try {
+ this.connection.close();
+ } catch (final JMSException ignored) {
+ }
+ this.jndiManager.release();
+ }
+
+ private static class JmsConfiguration {
+ private final JndiManager jndiManager;
+ private final String connectionFactoryName;
+ private final String destinationName;
+ private final String username;
+ private final String password;
+
+ private JmsConfiguration(JndiManager jndiManager, String connectionFactoryName, String destinationName,
+ String username, String password) {
+ this.jndiManager = jndiManager;
+ this.connectionFactoryName = connectionFactoryName;
+ this.destinationName = destinationName;
+ this.username = username;
+ this.password = password;
+ }
+ }
+
+ private static class JmsManagerFactory implements ManagerFactory<JmsManager, JmsConfiguration> {
+
+ @Override
+ public JmsManager createManager(String name, JmsConfiguration data) {
+ try {
+ return new JmsManager(name, data.jndiManager, data.connectionFactoryName, data.destinationName,
+ data.username, data.password);
+ } catch (final Exception e) {
+ LOGGER.error("Error creating JmsManager using ConnectionFactory [{}] and Destination [{}].",
+ data.connectionFactoryName, data.destinationName, e);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
new file mode 100644
index 0000000..fd00c03
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for a JMS Queue.
+ */
+public class JmsQueueManager extends AbstractJmsManager {
+
+ private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
+
+ private QueueInfo info;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+
+ /**
+ * The Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param queueBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final QueueInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JmsQueueManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
+ * @param queueBindingName The name to use to locate the Queue.
+ * @param userName The userid to use to create the Queue Connection.
+ * @param password The password to use to create the Queue Connection.
+ * @return The JmsQueueManager.
+ */
+ public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String queueBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsQueueManager");
+ return null;
+ }
+ if (queueBindingName == null) {
+ LOGGER.error("No topic name provided for JmsQueueManager");
+ return null;
+ }
+
+ final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
+ }
+
+ @Override
+ public synchronized void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.sender);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String queueBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String queueBindingName, final String userName,
+ final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.queueBindingName = queueBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static QueueInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
+ QueueConnection conn;
+ if (userName != null) {
+ conn = factory.createQueueConnection(userName, password);
+ } else {
+ conn = factory.createQueueConnection();
+ }
+ final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) lookup(context, queueBindingName);
+ final QueueSender sender = sess.createSender(queue);
+ conn.start();
+ return new QueueInfo(conn, sess, sender);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Queue connection information */
+ private static class QueueInfo {
+ private final QueueConnection conn;
+ private final QueueSession session;
+ private final QueueSender sender;
+
+ public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
+ this.conn = conn;
+ this.session = session;
+ this.sender = sender;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
+
+ @Override
+ public JmsQueueManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
+ data.password, true);
+ return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
new file mode 100644
index 0000000..9f45b72
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
@@ -0,0 +1,237 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+
+/**
+ * Manager for JMS Topic connections.
+ */
+public class JmsTopicManager extends AbstractJmsManager {
+
+ private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
+
+ private TopicInfo info;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+ private final Context context;
+ /**
+ * Constructor.
+ * @param name The unique name of the connection.
+ * @param context The context.
+ * @param factoryBindingName The factory binding name.
+ * @param topicBindingName The queue binding name.
+ * @param userName The user name.
+ * @param password The credentials for the user.
+ * @param info The Queue connection info.
+ */
+ protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
+ final String topicBindingName, final String userName, final String password,
+ final TopicInfo info) {
+ super(name);
+ this.context = context;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ this.info = info;
+ }
+
+ /**
+ * Obtain a JSMTopicManager.
+ * @param factoryName The fully qualified class name of the InitialContextFactory.
+ * @param providerURL The URL of the provider to use.
+ * @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 securityPrincipalName The name of the identity of the Principal.
+ * @param securityCredentials The security credentials of the Principal.
+ * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
+ * @param topicBindingName The name to use to locate the Topic.
+ * @param userName The userid to use to create the Topic Connection.
+ * @param password The password to use to create the Topic Connection.
+ * @return A JmsTopicManager.
+ */
+ public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
+ final String urlPkgPrefixes, final String securityPrincipalName,
+ final String securityCredentials, final String factoryBindingName,
+ final String topicBindingName, final String userName,
+ final String password) {
+
+ if (factoryBindingName == null) {
+ LOGGER.error("No factory name provided for JmsTopicManager");
+ return null;
+ }
+ if (topicBindingName == null) {
+ LOGGER.error("No topic name provided for JmsTopicManager");
+ return null;
+ }
+
+ final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
+ return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
+ securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
+ }
+
+
+ @Override
+ public void send(final Serializable object) throws Exception {
+ if (info == null) {
+ info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
+ }
+ try {
+ super.send(object, info.session, info.publisher);
+ } catch (final Exception ex) {
+ cleanup(true);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void releaseSub() {
+ if (info != null) {
+ cleanup(false);
+ }
+ }
+
+ private void cleanup(final boolean quiet) {
+ try {
+ info.session.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing session for " + getName(), e);
+ }
+ }
+ try {
+ info.conn.close();
+ } catch (final Exception e) {
+ if (!quiet) {
+ LOGGER.error("Error closing connection for " + getName(), e);
+ }
+ }
+ info = null;
+ }
+
+ /**
+ * Data for the factory.
+ */
+ private static class FactoryData {
+ private final String factoryName;
+ private final String providerURL;
+ private final String urlPkgPrefixes;
+ private final String securityPrincipalName;
+ private final String securityCredentials;
+ private final String factoryBindingName;
+ private final String topicBindingName;
+ private final String userName;
+ private final String password;
+
+ public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
+ final String securityPrincipalName, final String securityCredentials,
+ final String factoryBindingName, final String topicBindingName,
+ final String userName, final String password) {
+ this.factoryName = factoryName;
+ this.providerURL = providerURL;
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ this.securityPrincipalName = securityPrincipalName;
+ this.securityCredentials = securityCredentials;
+ this.factoryBindingName = factoryBindingName;
+ this.topicBindingName = topicBindingName;
+ this.userName = userName;
+ this.password = password;
+ }
+ }
+
+ private static TopicInfo connect(final Context context, final String factoryBindingName,
+ final String queueBindingName, final String userName, final String password,
+ final boolean suppress) throws Exception {
+ try {
+ final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
+ TopicConnection conn;
+ if (userName != null) {
+ conn = factory.createTopicConnection(userName, password);
+ } else {
+ conn = factory.createTopicConnection();
+ }
+ final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) lookup(context, queueBindingName);
+ final TopicPublisher publisher = sess.createPublisher(topic);
+ conn.start();
+ return new TopicInfo(conn, sess, publisher);
+ } catch (final NamingException ex) {
+ LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ } catch (final JMSException ex) {
+ LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
+ if (!suppress) {
+ throw ex;
+ }
+ }
+ return null;
+ }
+
+ /** Topic connection information */
+ private static class TopicInfo {
+ private final TopicConnection conn;
+ private final TopicSession session;
+ private final TopicPublisher publisher;
+
+ public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
+ this.conn = conn;
+ this.session = session;
+ this.publisher = publisher;
+ }
+ }
+
+ /**
+ * Factory to create the JmsQueueManager.
+ */
+ private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
+
+ @Override
+ public JmsTopicManager createManager(final String name, final FactoryData data) {
+ try {
+ final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
+ data.securityPrincipalName, data.securityCredentials);
+ final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
+ data.password, true);
+ return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
+ data.userName, data.password, info);
+ } catch (final NamingException ex) {
+ LOGGER.error("Unable to locate resource", ex);
+ } catch (final Exception ex) {
+ LOGGER.error("Unable to connect", ex);
+ }
+
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
new file mode 100644
index 0000000..f56e28f
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
@@ -0,0 +1,125 @@
+/*
+ * 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.mom.jms.manager;
+
+import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.AbstractManager;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * JNDI context manager. Mainly useful for finding JMS objects and configuring the InitialContext.
+ */
+public class JndiManager extends AbstractManager {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
+
+ private final Context context;
+
+ private JndiManager(String name, Context context) {
+ super(name);
+ this.context = context;
+ }
+
+ /**
+ * Gets a JndiManager with the provided configuration information.
+ *
+ * @param initialContextFactoryName 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 JndiManager for the provided parameters.
+ */
+ public static JndiManager getJndiManager(final String initialContextFactoryName,
+ final String providerURL,
+ final String urlPkgPrefixes,
+ final String securityPrincipal,
+ final String securityCredentials,
+ final Properties additionalProperties) {
+ final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
+ if (initialContextFactoryName == null) {
+ return getManager(name, FACTORY, null);
+ }
+ final Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ properties.setProperty(Context.PROVIDER_URL, providerURL);
+ } else {
+ LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
+ "provider URL. This is likely to cause problems.", initialContextFactoryName);
+ }
+ if (urlPkgPrefixes != null) {
+ properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+ if (securityPrincipal != null) {
+ properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
+ if (securityCredentials != null) {
+ properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
+ securityPrincipal);
+ }
+ }
+ if (additionalProperties != null) {
+ properties.putAll(additionalProperties);
+ }
+ return getManager(name, FACTORY, properties);
+ }
+
+ @Override
+ protected void releaseSub() {
+ Closer.closeSilently(this.context);
+ }
+
+ /**
+ * Looks up a named object through this JNDI context.
+ *
+ * @param name name of the object to look up.
+ * @param <T> the type of the object.
+ * @return the named object if it could be located.
+ * @throws NamingException
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(final String name) throws NamingException {
+ return (T) this.context.lookup(name);
+ }
+
+ private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
+
+ @Override
+ public JndiManager createManager(String name, Properties data) {
+ try {
+ return new JndiManager(name, new InitialContext(data));
+ } catch (final NamingException e) {
+ LOGGER.error("Error creating JNDI InitialContext.", e);
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
new file mode 100644
index 0000000..bf86c65
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
@@ -0,0 +1,83 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LogEventListener;
+
+/**
+ * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
+ */
+public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
+
+ /**
+ * Logger to capture diagnostics.
+ */
+ protected Logger logger = LogManager.getLogger(this.getClass().getName());
+
+ /**
+ * Listener that receives the event.
+ * @param message The received message.
+ */
+ @Override
+ public void onMessage(final javax.jms.Message message) {
+ try {
+ if (message instanceof ObjectMessage) {
+ final ObjectMessage objectMessage = (ObjectMessage) message;
+ final Serializable object = objectMessage.getObject();
+ if (object instanceof LogEvent) {
+ log((LogEvent) object);
+ } else {
+ logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
+ }
+ } else {
+ logger.warn("Received message is of type " + message.getJMSType()
+ + ", was expecting ObjectMessage.");
+ }
+ } catch (final JMSException jmse) {
+ logger.error("Exception thrown while processing incoming message.",
+ jmse);
+ }
+ }
+
+ /**
+ * Looks up an object from the Context.
+ * @param ctx The Context.
+ * @param name The name of the object to locate.
+ * @return The object.
+ * @throws NamingException if an error occurs.
+ */
+ protected Object lookup(final Context ctx, final String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (final NameNotFoundException e) {
+ logger.error("Could not find name [" + name + "].");
+ throw e;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
new file mode 100644
index 0000000..b231489
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
@@ -0,0 +1,107 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Log Events over a JMS Queue. This implementation expects that all messages will
+ * contain a serialized LogEvent.
+ */
+public class JmsQueueReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param qcfBindingName The QueueConnectionFactory binding name.
+ * @param queueBindingName The Queue binding name.
+ * @param username The userid to connect to the queue.
+ * @param password The password to connect to the queue.
+ */
+ public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
+ final String password) {
+
+ try {
+ final Context ctx = new InitialContext();
+ QueueConnectionFactory queueConnectionFactory;
+ queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
+ final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
+ queueConnection.start();
+ final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Queue queue = (Queue) ctx.lookup(queueBindingName);
+ final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
+ queueReceiver.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String qcfBindingName = args[0];
+ final String queueBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
+ + " QueueConnectionFactoryBindingName QueueBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
new file mode 100644
index 0000000..0149ee5
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
@@ -0,0 +1,105 @@
+/*
+ * 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.mom.jms.receiver;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Receives Topic messages that contain LogEvents. This implementation expects that all messages
+ * are serialized log events.
+ */
+public class JmsTopicReceiver extends AbstractJmsReceiver {
+
+ /**
+ * Constructor.
+ * @param tcfBindingName The TopicConnectionFactory binding name.
+ * @param topicBindingName The Topic binding name.
+ * @param username The userid to connect to the topic.
+ * @param password The password to connect to the topic.
+ */
+ public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
+ final String password) {
+ try {
+ final Context ctx = new InitialContext();
+ TopicConnectionFactory topicConnectionFactory;
+ topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
+ final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
+ topicConnection.start();
+ final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ final Topic topic = (Topic) ctx.lookup(topicBindingName);
+ final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
+ topicSubscriber.setMessageListener(this);
+ } catch (final JMSException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final NamingException e) {
+ logger.error("Could not read JMS message.", e);
+ } catch (final RuntimeException e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
+
+ /**
+ * Main startup for the receiver.
+ * @param args The command line arguments.
+ * @throws Exception if an error occurs.
+ */
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
+ usage("Wrong number of arguments.");
+ }
+
+ final String tcfBindingName = args[0];
+ final String topicBindingName = args[1];
+ final String username = args[2];
+ final String password = args[3];
+
+ new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
+
+ final Charset enc = Charset.defaultCharset();
+ final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
+ // Loop until the word "exit" is typed
+ System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
+ while (true) {
+ final String line = stdin.readLine();
+ if (line == null || line.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting. Kill the application if it does not exit "
+ + "due to daemon threads.");
+ return;
+ }
+ }
+ }
+
+ private static void usage(final String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
+ + " TopicConnectionFactoryBindingName TopicBindingName username password");
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
new file mode 100644
index 0000000..1f233e8
--- /dev/null
+++ b/log4j-jms/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/**
+ * Supporting network code for JMS appenders.
+ * <p/>
+ * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
+ * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
+ * the running process. Of course, use of these classes as standalone executables are entirely optional and can
+ * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
+ */
+package org.apache.logging.log4j.mom.jms.receiver;
\ No newline at end of file
[17/29] Rename log4j-mom to log4j-jms.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
deleted file mode 100644
index fd00c03..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsQueueManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.manager;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for a JMS Queue.
- */
-public class JmsQueueManager extends AbstractJmsManager {
-
- private static final JMSQueueManagerFactory FACTORY = new JMSQueueManagerFactory();
-
- private QueueInfo info;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
- private final Context context;
-
- /**
- * The Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param queueBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsQueueManager(final String name, final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final QueueInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JmsQueueManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
- * @param queueBindingName The name to use to locate the Queue.
- * @param userName The userid to use to create the Queue Connection.
- * @param password The password to use to create the Queue Connection.
- * @return The JmsQueueManager.
- */
- public static JmsQueueManager getJmsQueueManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String queueBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsQueueManager");
- return null;
- }
- if (queueBindingName == null) {
- LOGGER.error("No topic name provided for JmsQueueManager");
- return null;
- }
-
- final String name = "JMSQueue:" + factoryBindingName + '.' + queueBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password));
- }
-
- @Override
- public synchronized void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, queueBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.sender);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String queueBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String queueBindingName, final String userName,
- final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.queueBindingName = queueBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static QueueInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final QueueConnectionFactory factory = (QueueConnectionFactory) lookup(context, factoryBindingName);
- QueueConnection conn;
- if (userName != null) {
- conn = factory.createQueueConnection(userName, password);
- } else {
- conn = factory.createQueueConnection();
- }
- final QueueSession sess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) lookup(context, queueBindingName);
- final QueueSender sender = sess.createSender(queue);
- conn.start();
- return new QueueInfo(conn, sess, sender);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Queue connection information */
- private static class QueueInfo {
- private final QueueConnection conn;
- private final QueueSession session;
- private final QueueSender sender;
-
- public QueueInfo(final QueueConnection conn, final QueueSession session, final QueueSender sender) {
- this.conn = conn;
- this.session = session;
- this.sender = sender;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSQueueManagerFactory implements ManagerFactory<JmsQueueManager, FactoryData> {
-
- @Override
- public JmsQueueManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final QueueInfo info = connect(ctx, data.factoryBindingName, data.queueBindingName, data.userName,
- data.password, true);
- return new JmsQueueManager(name, ctx, data.factoryBindingName, data.queueBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
deleted file mode 100644
index 9f45b72..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JmsTopicManager.java
+++ /dev/null
@@ -1,237 +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.mom.jms.manager;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-
-/**
- * Manager for JMS Topic connections.
- */
-public class JmsTopicManager extends AbstractJmsManager {
-
- private static final JMSTopicManagerFactory FACTORY = new JMSTopicManagerFactory();
-
- private TopicInfo info;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
- private final Context context;
- /**
- * Constructor.
- * @param name The unique name of the connection.
- * @param context The context.
- * @param factoryBindingName The factory binding name.
- * @param topicBindingName The queue binding name.
- * @param userName The user name.
- * @param password The credentials for the user.
- * @param info The Queue connection info.
- */
- protected JmsTopicManager(final String name, final Context context, final String factoryBindingName,
- final String topicBindingName, final String userName, final String password,
- final TopicInfo info) {
- super(name);
- this.context = context;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- this.info = info;
- }
-
- /**
- * Obtain a JSMTopicManager.
- * @param factoryName The fully qualified class name of the InitialContextFactory.
- * @param providerURL The URL of the provider to use.
- * @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 securityPrincipalName The name of the identity of the Principal.
- * @param securityCredentials The security credentials of the Principal.
- * @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
- * @param topicBindingName The name to use to locate the Topic.
- * @param userName The userid to use to create the Topic Connection.
- * @param password The password to use to create the Topic Connection.
- * @return A JmsTopicManager.
- */
- public static JmsTopicManager getJmsTopicManager(final String factoryName, final String providerURL,
- final String urlPkgPrefixes, final String securityPrincipalName,
- final String securityCredentials, final String factoryBindingName,
- final String topicBindingName, final String userName,
- final String password) {
-
- if (factoryBindingName == null) {
- LOGGER.error("No factory name provided for JmsTopicManager");
- return null;
- }
- if (topicBindingName == null) {
- LOGGER.error("No topic name provided for JmsTopicManager");
- return null;
- }
-
- final String name = "JMSTopic:" + factoryBindingName + '.' + topicBindingName;
- return getManager(name, FACTORY, new FactoryData(factoryName, providerURL, urlPkgPrefixes,
- securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password));
- }
-
-
- @Override
- public void send(final Serializable object) throws Exception {
- if (info == null) {
- info = connect(context, factoryBindingName, topicBindingName, userName, password, false);
- }
- try {
- super.send(object, info.session, info.publisher);
- } catch (final Exception ex) {
- cleanup(true);
- throw ex;
- }
- }
-
- @Override
- public void releaseSub() {
- if (info != null) {
- cleanup(false);
- }
- }
-
- private void cleanup(final boolean quiet) {
- try {
- info.session.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing session for " + getName(), e);
- }
- }
- try {
- info.conn.close();
- } catch (final Exception e) {
- if (!quiet) {
- LOGGER.error("Error closing connection for " + getName(), e);
- }
- }
- info = null;
- }
-
- /**
- * Data for the factory.
- */
- private static class FactoryData {
- private final String factoryName;
- private final String providerURL;
- private final String urlPkgPrefixes;
- private final String securityPrincipalName;
- private final String securityCredentials;
- private final String factoryBindingName;
- private final String topicBindingName;
- private final String userName;
- private final String password;
-
- public FactoryData(final String factoryName, final String providerURL, final String urlPkgPrefixes,
- final String securityPrincipalName, final String securityCredentials,
- final String factoryBindingName, final String topicBindingName,
- final String userName, final String password) {
- this.factoryName = factoryName;
- this.providerURL = providerURL;
- this.urlPkgPrefixes = urlPkgPrefixes;
- this.securityPrincipalName = securityPrincipalName;
- this.securityCredentials = securityCredentials;
- this.factoryBindingName = factoryBindingName;
- this.topicBindingName = topicBindingName;
- this.userName = userName;
- this.password = password;
- }
- }
-
- private static TopicInfo connect(final Context context, final String factoryBindingName,
- final String queueBindingName, final String userName, final String password,
- final boolean suppress) throws Exception {
- try {
- final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
- TopicConnection conn;
- if (userName != null) {
- conn = factory.createTopicConnection(userName, password);
- } else {
- conn = factory.createTopicConnection();
- }
- final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) lookup(context, queueBindingName);
- final TopicPublisher publisher = sess.createPublisher(topic);
- conn.start();
- return new TopicInfo(conn, sess, publisher);
- } catch (final NamingException ex) {
- LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- } catch (final JMSException ex) {
- LOGGER.warn("Unable to create connection to queue " + queueBindingName, ex);
- if (!suppress) {
- throw ex;
- }
- }
- return null;
- }
-
- /** Topic connection information */
- private static class TopicInfo {
- private final TopicConnection conn;
- private final TopicSession session;
- private final TopicPublisher publisher;
-
- public TopicInfo(final TopicConnection conn, final TopicSession session, final TopicPublisher publisher) {
- this.conn = conn;
- this.session = session;
- this.publisher = publisher;
- }
- }
-
- /**
- * Factory to create the JmsQueueManager.
- */
- private static class JMSTopicManagerFactory implements ManagerFactory<JmsTopicManager, FactoryData> {
-
- @Override
- public JmsTopicManager createManager(final String name, final FactoryData data) {
- try {
- final Context ctx = createContext(data.factoryName, data.providerURL, data.urlPkgPrefixes,
- data.securityPrincipalName, data.securityCredentials);
- final TopicInfo info = connect(ctx, data.factoryBindingName, data.topicBindingName, data.userName,
- data.password, true);
- return new JmsTopicManager(name, ctx, data.factoryBindingName, data.topicBindingName,
- data.userName, data.password, info);
- } catch (final NamingException ex) {
- LOGGER.error("Unable to locate resource", ex);
- } catch (final Exception ex) {
- LOGGER.error("Unable to connect", ex);
- }
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
deleted file mode 100644
index f56e28f..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/manager/JndiManager.java
+++ /dev/null
@@ -1,125 +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.mom.jms.manager;
-
-import java.util.Properties;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.util.Closer;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * JNDI context manager. Mainly useful for finding JMS objects and configuring the InitialContext.
- */
-public class JndiManager extends AbstractManager {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- private static final JndiManagerFactory FACTORY = new JndiManagerFactory();
-
- private final Context context;
-
- private JndiManager(String name, Context context) {
- super(name);
- this.context = context;
- }
-
- /**
- * Gets a JndiManager with the provided configuration information.
- *
- * @param initialContextFactoryName 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 JndiManager for the provided parameters.
- */
- public static JndiManager getJndiManager(final String initialContextFactoryName,
- final String providerURL,
- final String urlPkgPrefixes,
- final String securityPrincipal,
- final String securityCredentials,
- final Properties additionalProperties) {
- final String name = JndiManager.class.getName() + '@' + JndiManager.class.hashCode();
- if (initialContextFactoryName == null) {
- return getManager(name, FACTORY, null);
- }
- final Properties properties = new Properties();
- properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- properties.setProperty(Context.PROVIDER_URL, providerURL);
- } else {
- LOGGER.warn("The JNDI InitialContextFactory class name [{}] was provided, but there was no associated " +
- "provider URL. This is likely to cause problems.", initialContextFactoryName);
- }
- if (urlPkgPrefixes != null) {
- properties.setProperty(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
- if (securityPrincipal != null) {
- properties.setProperty(Context.SECURITY_PRINCIPAL, securityPrincipal);
- if (securityCredentials != null) {
- properties.setProperty(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- LOGGER.warn("A security principal [{}] was provided, but with no corresponding security credentials.",
- securityPrincipal);
- }
- }
- if (additionalProperties != null) {
- properties.putAll(additionalProperties);
- }
- return getManager(name, FACTORY, properties);
- }
-
- @Override
- protected void releaseSub() {
- Closer.closeSilently(this.context);
- }
-
- /**
- * Looks up a named object through this JNDI context.
- *
- * @param name name of the object to look up.
- * @param <T> the type of the object.
- * @return the named object if it could be located.
- * @throws NamingException
- */
- @SuppressWarnings("unchecked")
- public <T> T lookup(final String name) throws NamingException {
- return (T) this.context.lookup(name);
- }
-
- private static class JndiManagerFactory implements ManagerFactory<JndiManager, Properties> {
-
- @Override
- public JndiManager createManager(String name, Properties data) {
- try {
- return new JndiManager(name, new InitialContext(data));
- } catch (final NamingException e) {
- LOGGER.error("Error creating JNDI InitialContext.", e);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
deleted file mode 100644
index bf86c65..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/AbstractJmsReceiver.java
+++ /dev/null
@@ -1,83 +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.mom.jms.receiver;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.ObjectMessage;
-import javax.naming.Context;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LogEventListener;
-
-/**
- * Abstract base class for receiving LogEvents over JMS. This class expects all messages to be serialized log events.
- */
-public abstract class AbstractJmsReceiver extends LogEventListener implements javax.jms.MessageListener {
-
- /**
- * Logger to capture diagnostics.
- */
- protected Logger logger = LogManager.getLogger(this.getClass().getName());
-
- /**
- * Listener that receives the event.
- * @param message The received message.
- */
- @Override
- public void onMessage(final javax.jms.Message message) {
- try {
- if (message instanceof ObjectMessage) {
- final ObjectMessage objectMessage = (ObjectMessage) message;
- final Serializable object = objectMessage.getObject();
- if (object instanceof LogEvent) {
- log((LogEvent) object);
- } else {
- logger.warn("Received message is of type " + object.getClass().getName() + ", was expecting LogEvent.");
- }
- } else {
- logger.warn("Received message is of type " + message.getJMSType()
- + ", was expecting ObjectMessage.");
- }
- } catch (final JMSException jmse) {
- logger.error("Exception thrown while processing incoming message.",
- jmse);
- }
- }
-
- /**
- * Looks up an object from the Context.
- * @param ctx The Context.
- * @param name The name of the object to locate.
- * @return The object.
- * @throws NamingException if an error occurs.
- */
- protected Object lookup(final Context ctx, final String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (final NameNotFoundException e) {
- logger.error("Could not find name [" + name + "].");
- throw e;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
deleted file mode 100644
index b231489..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsQueueReceiver.java
+++ /dev/null
@@ -1,107 +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.mom.jms.receiver;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Log Events over a JMS Queue. This implementation expects that all messages will
- * contain a serialized LogEvent.
- */
-public class JmsQueueReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param qcfBindingName The QueueConnectionFactory binding name.
- * @param queueBindingName The Queue binding name.
- * @param username The userid to connect to the queue.
- * @param password The password to connect to the queue.
- */
- public JmsQueueReceiver(final String qcfBindingName, final String queueBindingName, final String username,
- final String password) {
-
- try {
- final Context ctx = new InitialContext();
- QueueConnectionFactory queueConnectionFactory;
- queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName);
- final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(username, password);
- queueConnection.start();
- final QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- final Queue queue = (Queue) ctx.lookup(queueBindingName);
- final QueueReceiver queueReceiver = queueSession.createReceiver(queue);
- queueReceiver.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String qcfBindingName = args[0];
- final String queueBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsQueueReceiver(qcfBindingName, queueBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsQueueReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsQueueReceiver.class.getName()
- + " QueueConnectionFactoryBindingName QueueBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
deleted file mode 100644
index 0149ee5..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/JmsTopicReceiver.java
+++ /dev/null
@@ -1,105 +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.mom.jms.receiver;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicSession;
-import javax.jms.TopicSubscriber;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * Receives Topic messages that contain LogEvents. This implementation expects that all messages
- * are serialized log events.
- */
-public class JmsTopicReceiver extends AbstractJmsReceiver {
-
- /**
- * Constructor.
- * @param tcfBindingName The TopicConnectionFactory binding name.
- * @param topicBindingName The Topic binding name.
- * @param username The userid to connect to the topic.
- * @param password The password to connect to the topic.
- */
- public JmsTopicReceiver(final String tcfBindingName, final String topicBindingName, final String username,
- final String password) {
- try {
- final Context ctx = new InitialContext();
- TopicConnectionFactory topicConnectionFactory;
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
- final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
- topicConnection.start();
- final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- final Topic topic = (Topic) ctx.lookup(topicBindingName);
- final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
- topicSubscriber.setMessageListener(this);
- } catch (final JMSException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final NamingException e) {
- logger.error("Could not read JMS message.", e);
- } catch (final RuntimeException e) {
- logger.error("Could not read JMS message.", e);
- }
- }
-
- /**
- * Main startup for the receiver.
- * @param args The command line arguments.
- * @throws Exception if an error occurs.
- */
- public static void main(final String[] args) throws Exception {
- if (args.length != 4) {
- usage("Wrong number of arguments.");
- }
-
- final String tcfBindingName = args[0];
- final String topicBindingName = args[1];
- final String username = args[2];
- final String password = args[3];
-
- new JmsTopicReceiver(tcfBindingName, topicBindingName, username, password);
-
- final Charset enc = Charset.defaultCharset();
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc));
- // Loop until the word "exit" is typed
- System.out.println("Type \"exit\" to quit JmsTopicReceiver.");
- while (true) {
- final String line = stdin.readLine();
- if (line == null || line.equalsIgnoreCase("exit")) {
- System.out.println("Exiting. Kill the application if it does not exit "
- + "due to daemon threads.");
- return;
- }
- }
- }
-
- private static void usage(final String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + JmsTopicReceiver.class.getName()
- + " TopicConnectionFactoryBindingName TopicBindingName username password");
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java b/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
deleted file mode 100644
index 1f233e8..0000000
--- a/log4j-mom/src/main/java/org/apache/logging/log4j/mom/jms/receiver/package-info.java
+++ /dev/null
@@ -1,25 +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.
- */
-/**
- * Supporting network code for JMS appenders.
- * <p/>
- * Note that you can use JmsQueueReceiver or JmsTopicReceiver as executable main classes to receive log events over
- * JMS (sent via the appropriate JMS appender) that can be subsequently logged according to the configuration given to
- * the running process. Of course, use of these classes as standalone executables are entirely optional and can
- * be used directly in your application (e.g., through your Spring {@code beans.xml} configuration).
- */
-package org.apache.logging.log4j.mom.jms.receiver;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
deleted file mode 100644
index 9ed98fa..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderIT.java
+++ /dev/null
@@ -1,126 +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.mom.jms.appender;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.ObjectMessage;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-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.layout.SerializedLayout;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.mom.jms.manager.JmsManager;
-import org.apache.logging.log4j.mom.jms.manager.JndiManager;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Integration test for JmsAppender using an embedded ActiveMQ broker.
- */
-public class JmsAppenderIT {
-
- private static JmsManager jmsManager;
-
- private JmsAppender appender;
-
- @BeforeClass
- public static void setUpClass() {
- final Properties additional = new Properties();
- additional.setProperty("queue.TestQueue", "TestQueue");
- JndiManager jndiManager = JndiManager.getJndiManager(ActiveMQInitialContextFactory.class.getName(),
- "vm://localhost?broker.persistent=false", null, null, null, additional);
- jmsManager = JmsManager.getJmsManager("JmsManager", jndiManager, "ConnectionFactory", "TestQueue", null, null);
- }
-
- @AfterClass
- public static void tearDownClass() {
- jmsManager.release();
- }
-
- @Before
- public void setUp() throws Exception {
- appender = new JmsAppender("JmsAppender", null, SerializedLayout.createLayout(), true, jmsManager);
- appender.start();
- }
-
- @Test
- public void testLogToQueue() throws Exception {
- final int messageCount = 100;
- final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
- final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount);
- messageConsumer.setMessageListener(consumer);
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- for (int i = 0; i < messageCount; i++) {
- final LogEvent event = Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.ERROR,
- new SimpleMessage(messageText), null, null, null, null, Thread.currentThread().getName(), null,
- System.currentTimeMillis());
- appender.append(event);
- }
- consumer.awaitAndAssertAllMessagesConsumed();
- }
-
- private static class JmsQueueConsumer implements MessageListener {
-
- private final int messageCount;
- private final CountDownLatch countDownLatch;
- private final Collection<LogEvent> events;
-
- private JmsQueueConsumer(final int messageCount) {
- this.messageCount = messageCount;
- this.countDownLatch = new CountDownLatch(messageCount);
- this.events = new ArrayList<LogEvent>(messageCount);
- }
-
- @Override
- public void onMessage(Message message) {
- try {
- consume((ObjectMessage) message);
- } catch (JMSException e) {
- e.printStackTrace();
- }
- }
-
- private void consume(ObjectMessage message) throws JMSException {
- try {
- final LogEvent event = (LogEvent) message.getObject();
- events.add(event);
- } finally {
- countDownLatch.countDown();
- }
- }
-
- public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
- countDownLatch.await(5, TimeUnit.SECONDS);
- assertEquals(messageCount, events.size());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
deleted file mode 100644
index 8e54681..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsAppenderTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.logging.log4j.mom.jms.appender;
-
-import javax.jms.Message;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-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.util.Closer;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.*;
-
-public class JmsAppenderTest {
-
- private static final String CONNECTION_FACTORY_NAME = "jms/activemq";
- private static final String DESTINATION_NAME = "jms/destination";
- private static final String LOG_MESSAGE = "Hello, world!";
-
- private static Context context;
-
- private JmsAppender appender;
- private static MockQueue queue;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(CONNECTION_FACTORY_NAME, new QueueConnectionFactoryImpl());
- queue = new MockQueue(DESTINATION_NAME);
- context.rebind(DESTINATION_NAME, queue);
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- Closer.closeSilently(context);
- }
-
- @Rule
- public InitialLoggerContext ctx = new InitialLoggerContext("JmsAppenderTest.xml");
-
- @Before
- public void setUp() throws Exception {
- appender = (JmsAppender) ctx.getAppender("JmsQueueAppender");
- assertEquals(0, queue.size());
- }
-
- @Test
- public void testAppendToQueue() throws Exception {
- final String loggerName = this.getClass().getName();
- final long now = System.currentTimeMillis();
- final LogEvent event = createLogEvent(loggerName, now);
- appender.append(event);
- assertEquals(1, queue.size());
- final Message message = queue.getMessageAt(0);
- assertNotNull(message);
- assertThat(message, instanceOf(TextMessage.class));
- final TextMessage textMessage = (TextMessage) message;
- assertEquals(LOG_MESSAGE, textMessage.getText());
- }
-
- private static Log4jLogEvent createLogEvent(String loggerName, long now) {
- return Log4jLogEvent.createEvent(loggerName, null, loggerName, Level.INFO,
- new SimpleMessage(LOG_MESSAGE), null, null, null, null, Thread.currentThread().getName(), null, now);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
deleted file mode 100644
index f05a9fc..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueAppenderTest.java
+++ /dev/null
@@ -1,85 +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.mom.jms.appender;
-
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueAppenderTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue.xml";
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @Test
- public void testConfiguration() throws Exception {
- final LoggerContext ctx = (LoggerContext) LogManager.getContext();
- final Configuration config = ctx.getConfiguration();
- final Map<String, Appender> appenders = config.getAppenders();
- assertTrue(appenders.containsKey("JMSQueue"));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
deleted file mode 100644
index 25c3068..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueFailoverTest.java
+++ /dev/null
@@ -1,122 +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.mom.jms.appender;
-
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueFailoverTest {
-
- private static final String FACTORY_NAME = "QueueConnectionFactory";
- private static final String QUEUE_NAME = "Log4j2Queue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- private static final String CONFIG = "log4j-jmsqueue-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsQueueFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
deleted file mode 100644
index a36e148..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsQueueTest.java
+++ /dev/null
@@ -1,147 +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.mom.jms.appender;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsQueueReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockQueue;
-import org.mockejb.jms.QueueConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsQueueTest {
-
- private static final String FACTORY_NAME = "TestQueueConnectionFactory";
- private static final String QUEUE_NAME = "TestQueue";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsQueueTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new QueueConnectionFactoryImpl());
- context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsQueueAppender appender = JmsQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- QUEUE_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
-
- private static final long serialVersionUID = 1L;
-
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
deleted file mode 100644
index a8de6de..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicFailoverTest.java
+++ /dev/null
@@ -1,121 +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.mom.jms.appender;
-
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicFailoverTest {
-
- private static final String FACTORY_NAME = "TopicConnectionFactory";
- private static final String TOPIC_NAME = "Log4j2Topic";
-
- private static Context context;
-
- private static final String CONFIG = "log4j-jmstopic-failover.xml";
-
- private static Configuration config;
- private static ListAppender listAppender;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() throws Exception {
- setupQueue();
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- }
-
- @AfterClass
- public static void cleanupClass() {
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- ctx.reconfigure();
- StatusLogger.getLogger().reset();
- }
-
- @Before
- public void before() {
- config = ctx.getConfiguration();
- listAppender = (ListAppender) config.getAppender("List");
- assertNotNull("No Appender", listAppender);
- listAppender.clear();
- ThreadContext.clearMap();
- }
-
- private static void setupQueue() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- //context.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
- //System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- //receiver = new JmsQueueReceiver(FACTORY_NAME, QUEUE_NAME, null, null);
- }
-
- @Test
- public void testFailover() throws Exception {
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-
- @Test
- public void testReconnect() throws Exception {
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- final AbstractJmsReceiver receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- ThreadContext.put("appender", "Failover");
- final Logger logger = LogManager.getLogger(JmsTopicFailoverTest.class);
- logger.debug("Test Message");
- final List<LogEvent> events = listAppender.getEvents();
- assertNotNull("No events returned", events);
- assertTrue("No events returned", events.size() > 0);
- assertTrue("Incorrect event", "Test Message".equals(events.get(0).getMessage().getFormattedMessage()));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java b/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
deleted file mode 100644
index 890f929..0000000
--- a/log4j-mom/src/test/java/org/apache/logging/log4j/mom/jms/appender/JmsTopicTest.java
+++ /dev/null
@@ -1,147 +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.mom.jms.appender;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.filter.AbstractFilter;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.mom.jms.receiver.AbstractJmsReceiver;
-import org.apache.logging.log4j.mom.jms.receiver.JmsTopicReceiver;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockejb.jms.MockTopic;
-import org.mockejb.jms.TopicConnectionFactoryImpl;
-import org.mockejb.jndi.MockContextFactory;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JmsTopicTest {
-
- private static final String FACTORY_NAME = "TestTopicConnectionFactory";
- private static final String TOPIC_NAME = "TestTopic";
-
- private static Context context;
- private static AbstractJmsReceiver receiver;
-
- LoggerContext ctx = (LoggerContext) LogManager.getContext();
- Logger root = ctx.getLogger("JmsTopicTest");
-
- @BeforeClass
- public static void setupClass() throws Exception {
- // MockContextFactory becomes the primary JNDI provider
- final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR);
- StatusLogger.getLogger().registerListener(listener);
- MockContextFactory.setAsInitial();
- context = new InitialContext();
- context.rebind(FACTORY_NAME, new TopicConnectionFactoryImpl());
- context.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
- ((LoggerContext) LogManager.getContext()).reconfigure();
- receiver = new JmsTopicReceiver(FACTORY_NAME, TOPIC_NAME, null, null);
- }
-
- @AfterClass
- public static void cleanupClass() {
- StatusLogger.getLogger().reset();
- }
-
- @After
- public void teardown() {
- final Map<String,Appender> map = root.getAppenders();
- for (final Map.Entry<String, Appender> entry : map.entrySet()) {
- final Appender app = entry.getValue();
- root.removeAppender(app);
- app.stop();
- }
- }
-
- @Test
- public void testServer() throws Exception {
- final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
- final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
- final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
- final JmsTopicAppender appender = JmsTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
- TOPIC_NAME, null, null, null, clientFilters, "true");
- appender.start();
- final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
- final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
- listApp.start();
- final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build();
- final ConsoleAppender console =
- ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
- console.start();
- final Logger serverLogger = ctx.getLogger(JmsTopicReceiver.class.getName());
- serverLogger.addAppender(console);
- serverLogger.setAdditive(false);
-
-
- // set appender on root and set level to debug
- root.addAppender(listApp);
- root.addAppender(appender);
- root.setAdditive(false);
- root.setLevel(Level.DEBUG);
- root.debug("This is a test message");
- Thread.sleep(100);
- final List<LogEvent> events = listApp.getEvents();
- assertNotNull("No event retrieved", events);
- assertTrue("No events retrieved", events.size() > 0);
- assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
- }
-
- private class MessageFilter extends AbstractFilter {
-
- private static final long serialVersionUID = 1L;
-
- public MessageFilter(final Result onMatch, final Result onMismatch) {
- super(onMatch, onMismatch);
- }
-
- @Override
- public Result filter(final LogEvent event) {
- final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (final StackTraceElement element : stackTrace) {
- if (element.getMethodName().equals("onMessage")) {
- return onMatch;
- } else if (element.getMethodName().equals("testServer")) {
- return onMismatch;
- }
- }
- return onMismatch;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/resources/JmsAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/JmsAppenderTest.xml b/log4j-mom/src/test/resources/JmsAppenderTest.xml
deleted file mode 100644
index ceccbaa..0000000
--- a/log4j-mom/src/test/resources/JmsAppenderTest.xml
+++ /dev/null
@@ -1,32 +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="JmsQueueAppender"
- factoryBindingName="jms/activemq"
- destinationBindingName="jms/destination">
- <PatternLayout pattern="%m"/>
- </JMS>
- </Appenders>
- <Loggers>
- <Root level="info">
- <AppenderRef ref="JmsQueueAppender"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
deleted file mode 100644
index 8b86750..0000000
--- a/log4j-mom/src/test/resources/log4j-jmsqueue-failover.xml
+++ /dev/null
@@ -1,52 +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 status="OFF" name="FailoverTest">
- <Appenders>
- <List name="List"/>
- <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
- ignoreExceptions="false"/>
- <Rewrite name="Rewrite" ignoreExceptions="false">
- <PropertiesRewritePolicy>
- <Property name="appender">List</Property>
- </PropertiesRewritePolicy>
- <AppenderRef ref="Log4j2Queue"/>
- </Rewrite>
- <Failover name="Failover" primary="Rewrite" ignoreExceptions="false">
- <Failovers>
- <AppenderRef ref="List"/>
- </Failovers>
- </Failover>
- </Appenders>
-
- <Loggers>
- <Root level="debug">
- <AppenderRef ref="Failover">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="Failover"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- <AppenderRef ref="List">
- <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">
- <KeyValuePair key="appender" value="List"/>
- </ThreadContextMapFilter>
- </AppenderRef>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/89304e88/log4j-mom/src/test/resources/log4j-jmsqueue.xml
----------------------------------------------------------------------
diff --git a/log4j-mom/src/test/resources/log4j-jmsqueue.xml b/log4j-mom/src/test/resources/log4j-jmsqueue.xml
deleted file mode 100644
index 44ea169..0000000
--- a/log4j-mom/src/test/resources/log4j-jmsqueue.xml
+++ /dev/null
@@ -1,30 +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="ConfigTest" status="OFF" monitorInterval="5">
- <Appenders>
- <JMSQueue name="JMSQueue" factoryBindingName="TestQueueConnectionFactory" queueBindingName="TestQueue">
- <PatternLayout pattern="%m%n"/>
- </JMSQueue>
- </Appenders>
- <Loggers>
- <Root level="error">
- <AppenderRef ref="JMSQueue"/>
- </Root>
- </Loggers>
-</Configuration>
\ No newline at end of file