logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1520406 [1/3] - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ log4j-core/src/main/java/org/apache/logging/log4j/core/net/ log...
Date Thu, 05 Sep 2013 20:02:35 GMT
Author: rgoers
Date: Thu Sep  5 20:02:34 2013
New Revision: 1520406

URL: http://svn.apache.org/r1520406
Log:
LOG4J2-338 - Add TLSAppender. Also added missing license headers to several files

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogFrame.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TLSSocketManager.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationException.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationDefaults.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationException.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationException.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationException.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/package-info.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTestBase.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/TLSSyslogAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/TLSSyslogFrameTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/MockSyslogServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/MockSyslogServerFactory.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/MockTCPSyslogServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/MockTLSSyslogServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/mock/MockUDPSyslogServer.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/LegacyBSDTLSSyslogInputStreamReader.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TLSSyslogInputStreamReader.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TLSSyslogInputStreamReaderBase.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TLSSyslogMessageFormat.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TLSSyslogTestUtil.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TestConstants.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/README
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/client.log4j2-crt.pem
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/client.log4j2-keystore.jks   (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/log4j2-cacert.pem
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/server.log4j2-crt.pem
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/server.log4j2-key.pem
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/syslog-ng-sample.conf
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/org/apache/logging/log4j/core/net/ssl/truststore.jks   (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JpaH2AppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JpaHyperSqlAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
    logging/log4j/log4j2/trunk/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
    logging/log4j/log4j2/trunk/log4j-slf4j-impl/src/main/java/org/slf4j/helpers/EventDataConverter.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml
    logging/log4j/log4j2/trunk/src/site/pdf.xml
    logging/log4j/log4j2/trunk/src/site/site.xml
    logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java?rev=1520406&r1=1520405&r2=1520406&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java Thu Sep  5 20:02:34 2013
@@ -41,7 +41,7 @@ import org.apache.logging.log4j.util.Eng
 @Plugin(name = "Syslog", category = "Core", elementType = "appender", printObject = true)
 public class SyslogAppender extends SocketAppender {
 
-    private static final String RFC5424 = "RFC5424";
+    protected static final String RFC5424 = "RFC5424";
 
     protected SyslogAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter,
                              final boolean ignoreExceptions, final boolean immediateFlush,
@@ -126,7 +126,8 @@ public class SyslogAppender extends Sock
         final boolean isAdvertise = Boolean.parseBoolean(advertise);
         final Layout<? extends Serializable> layout = (RFC5424.equalsIgnoreCase(format) ?
             RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, mdcPrefix, eventPrefix, includeNL,
-                escapeNL, appName, msgId, excludes, includes, required, exceptionPattern, loggerFields, config) :
+                escapeNL, appName, msgId, excludes, includes, required, exceptionPattern, "false", loggerFields,
+                config) :
             SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName));
 
         if (name == null) {

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogAppender.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogAppender.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogAppender.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,145 @@
+/*
+ * 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;
+
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.plugins.*;
+import org.apache.logging.log4j.core.helpers.Booleans;
+import org.apache.logging.log4j.core.layout.LoggerFields;
+import org.apache.logging.log4j.core.layout.RFC5424Layout;
+import org.apache.logging.log4j.core.layout.SyslogLayout;
+import org.apache.logging.log4j.core.net.AbstractSocketManager;
+import org.apache.logging.log4j.core.net.Advertiser;
+import org.apache.logging.log4j.core.net.TLSSocketManager;
+import org.apache.logging.log4j.core.net.ssl.SSLConfiguration;
+
+import java.io.Serializable;
+
+/**
+ *
+ * Secure Syslog Appender.
+ */
+@Plugin(name = "TLSSyslog", category = "Core", elementType = "appender", printObject = true)
+public final class TLSSyslogAppender extends SyslogAppender {
+
+
+    protected TLSSyslogAppender(String name, Layout<? extends Serializable> layout, Filter filter,
+                                boolean ignoreExceptions, boolean immediateFlush, AbstractSocketManager manager,
+                                Advertiser advertiser) {
+        super(name, layout, filter, ignoreExceptions, immediateFlush, manager, advertiser);
+    }
+
+    /**
+     * Create a SyslogAppender.
+     * @param host The name of the host to connect to.
+     * @param portNum The port to connect to on the target host.
+     * @param sslConfig   The SSL configuration
+     * @param delay The interval in which failed writes should be retried.
+     * @param immediateFail True if the write should fail if no socket is immediately available.
+     * @param name The name of the Appender.
+     * @param immediateFlush "true" if data should be flushed on each write.
+     * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
+     *               they are propagated to the caller.
+     * @param facility The Facility is used to try to classify the message.
+     * @param id The default structured data id to use when formatting according to RFC 5424.
+     * @param ein The IANA enterprise number.
+     * @param includeMDC Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog
+     * record. Defaults to "true:.
+     * @param mdcId The id to use for the MDC Structured Data Element.
+     * @param mdcPrefix The prefix to add to MDC key names.
+     * @param eventPrefix The prefix to add to event key names.
+     * @param includeNL If true, a newline will be appended to the end of the syslog record. The default is false.
+     * @param escapeNL String that should be used to replace newlines within the message text.
+     * @param appName The value to use as the APP-NAME in the RFC 5424 syslog record.
+     * @param msgId The default value to be used in the MSGID field of RFC 5424 syslog records.
+     * @param excludes A comma separated list of mdc keys that should be excluded from the LogEvent.
+     * @param includes A comma separated list of mdc keys that should be included in the FlumeEvent.
+     * @param required A comma separated list of mdc keys that must be present in the MDC.
+     * @param format If set to "RFC5424" the data will be formatted in accordance with RFC 5424. Otherwise,
+     * it will be formatted as a BSD Syslog record.
+     * @param filter A Filter to determine if the event should be handled by this Appender.
+     * @param config The Configuration.
+     * @param charsetName The character set to use when converting the syslog String to a byte array.
+     * @param exceptionPattern The converter pattern to use for formatting exceptions.
+     * @param loggerFields The logger fields
+     * @param advertise Whether to advertise
+     * @return A TLSSyslogAppender.
+     */
+    @PluginFactory
+    public static TLSSyslogAppender createAppender(@PluginAttribute("host") final String host,
+                                                   @PluginAttribute("port") final String portNum,
+                                                   @PluginElement("ssl") final SSLConfiguration sslConfig,
+                                                   @PluginAttribute("reconnectionDelay") final String delay,
+                                                   @PluginAttribute("immediateFail") final String immediateFail,
+                                                   @PluginAttribute("name") final String name,
+                                                   @PluginAttribute("immediateFlush") final String immediateFlush,
+                                                   @PluginAttribute("ignoreExceptions") final String ignore,
+                                                   @PluginAttribute("facility") final String facility,
+                                                   @PluginAttribute("id") final String id,
+                                                   @PluginAttribute("enterpriseNumber") final String ein,
+                                                   @PluginAttribute("includeMDC") final String includeMDC,
+                                                   @PluginAttribute("mdcId") final String mdcId,
+                                                   @PluginAttribute("mdcPrefix") final String mdcPrefix,
+                                                   @PluginAttribute("eventPrefix") final String eventPrefix,
+                                                   @PluginAttribute("newLine") final String includeNL,
+                                                   @PluginAttribute("newLineEscape") final String escapeNL,
+                                                   @PluginAttribute("appName") final String appName,
+                                                   @PluginAttribute("messageId") final String msgId,
+                                                   @PluginAttribute("mdcExcludes") final String excludes,
+                                                   @PluginAttribute("mdcIncludes") final String includes,
+                                                   @PluginAttribute("mdcRequired") final String required,
+                                                   @PluginAttribute("format") final String format,
+                                                   @PluginElement("filters") final Filter filter,
+                                                   @PluginConfiguration final Configuration config,
+                                                   @PluginAttribute("charset") final String charsetName,
+                                                   @PluginAttribute("exceptionPattern") final String exceptionPattern,
+                                                   @PluginElement("LoggerFields") final LoggerFields[] loggerFields,
+                                                   @PluginAttribute("advertise") final String advertise) {
+        final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
+        final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
+        final int reconnectDelay = AbstractAppender.parseInt(delay, 0);
+        final boolean fail = Booleans.parseBoolean(immediateFail, true);
+        final int port = AbstractAppender.parseInt(portNum, 0);
+        final boolean isAdvertise = Boolean.parseBoolean(advertise);
+        @SuppressWarnings("unchecked")
+        final Layout<? extends Serializable> layout = (RFC5424.equalsIgnoreCase(format) ?
+                RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, mdcPrefix, eventPrefix, includeNL,
+                    escapeNL, appName, msgId, excludes, includes, required, exceptionPattern, "true" ,loggerFields,
+                    config) :
+                SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName));
+
+        if (name == null) {
+            LOGGER.error("No name provided for TLSSyslogAppender");
+            return null;
+        }
+        final AbstractSocketManager manager = createSocketManager(sslConfig, host, port, reconnectDelay, fail, layout);
+        if (manager == null) {
+            return null;
+        }
+
+        return new TLSSyslogAppender(name, layout, filter, ignoreExceptions, isFlush, manager,
+                isAdvertise ? config.getAdvertiser() : null);
+    }
+
+    public static AbstractSocketManager createSocketManager(SSLConfiguration sslConf, String host, int port,
+                                                            int reconnectDelay, boolean fail,
+                                                            Layout<? extends Serializable> layout) {
+        return TLSSocketManager.getSocketManager(sslConf, host, port, reconnectDelay, fail, layout);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogFrame.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogFrame.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogFrame.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TLSSyslogFrame.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,72 @@
+/*
+* 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;
+
+/**
+ * Wrapper for messages that are formatted according to RFC 5425.
+ */
+public class TLSSyslogFrame {
+    public static final char SPACE = ' ';
+
+    private String message;
+    private int messageLengthInBytes;
+
+    public TLSSyslogFrame(String message) {
+        setMessage(message);
+    }
+
+    public String getMessage() {
+        return this.message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+        setLengthInBytes();
+    }
+
+    private void setLengthInBytes() {
+        messageLengthInBytes = message.length();
+    }
+
+    public byte[] getBytes() {
+        String frame = toString();
+        return frame.getBytes();
+    }
+
+    @Override
+    public String toString() {
+        String length = Integer.toString(messageLengthInBytes);
+        return length + SPACE + message;
+    }
+
+    @Override
+    public boolean equals(Object frame) {
+        return super.equals(frame);
+    }
+
+    public boolean equals(TLSSyslogFrame frame) {
+        return isLengthEquals(frame) && isMessageEquals(frame);
+    }
+
+    private boolean isLengthEquals(TLSSyslogFrame frame) {
+        return this.messageLengthInBytes == frame.messageLengthInBytes;
+    }
+
+    private boolean isMessageEquals(TLSSyslogFrame frame) {
+        return this.message.equals(frame.message);
+    }
+}

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1520406&r1=1520405&r2=1520406&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java Thu Sep  5 20:02:34 2013
@@ -31,6 +31,7 @@ import java.util.regex.Pattern;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LoggingException;
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.TLSSyslogFrame;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
@@ -60,10 +61,10 @@ import org.apache.logging.log4j.message.
  * @see <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>
  */
 @Plugin(name = "RFC5424Layout", category = "Core", elementType = "layout", printObject = true)
-public final class RFC5424Layout extends AbstractStringLayout {
+public class RFC5424Layout extends AbstractStringLayout {
 
     private static final String LF = "\n";
-    
+
     /**
      * Not a very good default - it is the Apache Software Foundation's enterprise number.
      */
@@ -81,7 +82,7 @@ public final class RFC5424Layout extends
      */
     public static final Pattern PARAM_VALUE_ESCAPE_PATTERN = Pattern.compile("[\\\"\\]\\\\]");
 
-    private static final String DEFAULT_MDCID = "mdc";
+    protected static final String DEFAULT_MDCID = "mdc";
     private static final int TWO_DIGITS = 10;
     private static final int THREE_DIGITS = 100;
     private static final int MILLIS_PER_MINUTE = 60000;
@@ -108,6 +109,7 @@ public final class RFC5424Layout extends
     private final ListChecker noopChecker = new NoopChecker();
     private final boolean includeNewLine;
     private final String escapeNewLine;
+    private final boolean useTLSMessageFormat;
 
     private long lastTimestamp = -1;
     private String timestamppStr;
@@ -120,7 +122,7 @@ public final class RFC5424Layout extends
                           final String mdcPrefix, final String eventPrefix,
                           final String appName, final String messageId, final String excludes, final String includes,
                           final String required, final Charset charset, final String exceptionPattern,
-                          final LoggerFields[] loggerFields) {
+                          final boolean useTLSMessageFormat, final LoggerFields[] loggerFields) {
         super(charset);
         final PatternParser exceptionParser = createPatternParser(config, ThrowablePatternConverter.class);
         exceptionFormatters = exceptionPattern == null ? null : exceptionParser.parse(exceptionPattern, false);
@@ -136,6 +138,7 @@ public final class RFC5424Layout extends
         this.eventPrefix = eventPrefix;
         this.appName = appName;
         this.messageId = messageId;
+        this.useTLSMessageFormat = useTLSMessageFormat;
         this.localHostName = NetUtils.getLocalHostname();
         ListChecker c = null;
         if (excludes != null) {
@@ -269,6 +272,9 @@ public final class RFC5424Layout extends
         appendSpace(buf);
         appendStructuredElements(buf, event);
         appendMessage(buf, event);
+        if (useTLSMessageFormat) {
+            return new TLSSyslogFrame(buf.toString()).toString();
+        }
         return buf.toString();
     }
 
@@ -610,6 +616,7 @@ public final class RFC5424Layout extends
      * @param includes         A comma separated list of MDC keys that should be included in the FlumeEvent.
      * @param required         A comma separated list of MDC keys that must be present in the MDC.
      * @param exceptionPattern The pattern for formatting exceptions.
+     * @param useTLSMessageFormat If true the message will be formatted according to RFC 5425.
      * @param loggerFields     Container for the KeyValuePairs containing the patterns
      * @param config           The Configuration. Some Converters require access to the Interpolator.
      * @return An RFC5424Layout.
@@ -631,6 +638,7 @@ public final class RFC5424Layout extends
             @PluginAttribute("mdcIncludes") String includes,
             @PluginAttribute("mdcRequired") final String required,
             @PluginAttribute("exceptionPattern") final String exceptionPattern,
+            @PluginAttribute("useTLSMessageFormat") final String useTLSMessageFormat, // RFC 5425
             @PluginElement("LoggerFields") final LoggerFields[] loggerFields,
             @PluginConfiguration final Configuration config) {
         final Charset charset = Charsets.UTF_8;
@@ -642,12 +650,14 @@ public final class RFC5424Layout extends
         final int enterpriseNumber = Integers.parseInt(ein, DEFAULT_ENTERPRISE_NUMBER);
         final boolean isMdc = Booleans.parseBoolean(includeMDC, true);
         final boolean includeNewLine = Boolean.parseBoolean(includeNL);
+        final boolean useTlsMessageFormat = Booleans.parseBoolean(useTLSMessageFormat, false);
         if (mdcId == null) {
             mdcId = DEFAULT_MDCID;
         }
 
         return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine, escapeNL, mdcId, mdcPrefix,
-                eventPrefix, appName, msgId, excludes, includes, required, charset, exceptionPattern, loggerFields);
+                eventPrefix, appName, msgId, excludes, includes, required, charset, exceptionPattern,
+                useTlsMessageFormat, loggerFields);
     }
 
     private class FieldFormatter {

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java?rev=1520406&r1=1520405&r2=1520406&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java Thu Sep  5 20:02:34 2013
@@ -193,7 +193,7 @@ public class TCPSocketManager extends Ab
             while (!shutdown) {
                 try {
                     sleep(reconnectionDelay);
-                    final Socket sock = new Socket(address, port);
+                    final Socket sock = createSocket(address, port);
                     final OutputStream newOS = sock.getOutputStream();
                     synchronized (owner) {
                         try {
@@ -221,6 +221,14 @@ public class TCPSocketManager extends Ab
         }
     }
 
+    protected Socket createSocket(InetAddress host, int port) throws IOException {
+        return createSocket(host.getHostName(), port);
+    }
+
+    protected Socket createSocket(String host, int port) throws IOException {
+        return new Socket(host, port);
+    }
+
     /**
      * Data for the factory.
      */
@@ -244,8 +252,7 @@ public class TCPSocketManager extends Ab
     /**
      * Factory to create a TCPSocketManager.
      */
-    private static class TCPSocketManagerFactory implements ManagerFactory<TCPSocketManager, FactoryData> {
-
+    protected static class TCPSocketManagerFactory implements ManagerFactory<TCPSocketManager, FactoryData> {
         @Override
         public TCPSocketManager createManager(final String name, final FactoryData data) {
 

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TLSSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TLSSocketManager.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TLSSocketManager.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/TLSSocketManager.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,170 @@
+/*
+ * 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;
+
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
+import org.apache.logging.log4j.core.net.ssl.SSLConfiguration;
+
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+/**
+ *
+ */
+public class TLSSocketManager extends TCPSocketManager {
+    public static final int DEFAULT_PORT = 6514;
+    private static final TLSSocketManagerFactory FACTORY = new TLSSocketManagerFactory();
+    private SSLConfiguration sslConfig;
+
+    /**
+     *
+     *
+     * @param name          The unique name of this connection.
+     * @param os            The OutputStream.
+     * @param sock          The Socket.
+     * @param addr          The internet address of the host.
+     * @param host          The name of the host.
+     * @param port          The port number on the host.
+     * @param delay         Reconnection interval.
+     * @param immediateFail
+     * @param layout        The Layout.
+     */
+    public TLSSocketManager(String name, OutputStream os, Socket sock, SSLConfiguration sslConfig, InetAddress addr,
+                            String host, int port, int delay, boolean immediateFail, Layout layout) {
+        super(name, os, sock, addr, host, port, delay, immediateFail, layout);
+        this.sslConfig = sslConfig;
+    }
+
+    private static class TLSFactoryData {
+        protected SSLConfiguration sslConfig;
+        private final String host;
+        private final int port;
+        private final int delay;
+        private final boolean immediateFail;
+        private final Layout layout;
+
+        public TLSFactoryData(SSLConfiguration sslConfig, String host, int port, int delay, boolean immediateFail,
+                              Layout layout) {
+            this.host = host;
+            this.port = port;
+            this.delay = delay;
+            this.immediateFail = immediateFail;
+            this.layout = layout;
+            this.sslConfig = sslConfig;
+        }
+    }
+
+    public static TLSSocketManager getSocketManager(final SSLConfiguration sslConfig, final String host, int port,
+                                                    int delay, final boolean immediateFail, final Layout layout ) {
+        if (Strings.isEmpty(host)) {
+            throw new IllegalArgumentException("A host name is required");
+        }
+        if (port <= 0) {
+            port = DEFAULT_PORT;
+        }
+        if (delay == 0) {
+            delay = DEFAULT_RECONNECTION_DELAY;
+        }
+        return (TLSSocketManager) getManager("TLS:" + host + ":" + port,
+                new TLSFactoryData(sslConfig, host, port, delay, immediateFail, layout), FACTORY);
+    }
+
+    @Override
+    protected Socket createSocket(String host, int port) throws IOException {
+        SSLSocketFactory socketFactory = createSSLSocketFactory(sslConfig);
+        return socketFactory.createSocket(host, port);
+    }
+
+    private static SSLSocketFactory createSSLSocketFactory(SSLConfiguration sslConf) {
+        SSLSocketFactory socketFactory;
+
+        if (sslConf != null)
+            socketFactory = sslConf.getSSLSocketFactory();
+        else
+            socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
+
+        return socketFactory;
+    }
+
+
+    private static class TLSSocketManagerFactory implements ManagerFactory<TLSSocketManager, TLSFactoryData> {
+
+        private class TLSSocketManagerFactoryException extends Exception {
+        }
+
+        @Override
+        public TLSSocketManager createManager(final String name, final TLSFactoryData data) {
+            InetAddress address = null;
+            OutputStream os = null;
+            Socket socket = null;
+
+            try {
+                address = resolveAddress(data.host);
+                socket = createSocket(data);
+                os = socket.getOutputStream();
+                checkDelay(data.delay, os);
+            }
+            catch (IOException e) {
+                LOGGER.error("TLSSocketManager (" + name + ") " + e);
+                os = new ByteArrayOutputStream();
+            }
+            catch (TLSSocketManagerFactoryException e) {
+                return null;
+            }
+            return createManager(name, os, socket, data.sslConfig, address, data.host, data.port, data.delay, data.immediateFail, data.layout);
+        }
+
+        private InetAddress resolveAddress(String hostName) throws TLSSocketManagerFactoryException {
+            InetAddress address;
+
+            try {
+                address = InetAddress.getByName(hostName);
+            } catch (final UnknownHostException ex) {
+                LOGGER.error("Could not find address of " + hostName, ex);
+                throw new TLSSocketManagerFactoryException();
+            }
+
+            return address;
+        }
+
+        private void checkDelay(int delay, OutputStream os) throws TLSSocketManagerFactoryException {
+            if (delay == 0 && os == null)
+                throw new TLSSocketManagerFactoryException();
+        }
+
+        private Socket createSocket(TLSFactoryData data) throws IOException {
+            SSLSocketFactory socketFactory;
+            SSLSocket socket;
+
+            socketFactory = createSSLSocketFactory(data.sslConfig);
+            socket = (SSLSocket) socketFactory.createSocket(data.host, data.port);
+            return socket;
+        }
+
+        private TLSSocketManager createManager(String name, OutputStream os, Socket socket, SSLConfiguration sslConfig, InetAddress address, String host, int port, int delay, boolean immediateFail, Layout layout) {
+            return new TLSSocketManager(name, os, socket, sslConfig, address, host, port, delay, immediateFail, layout);
+        }
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java Thu Sep  5 20:02:34 2013
@@ -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.core.net.ssl;
+
+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.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+
+/**
+ * Configuration of the KeyStore
+ */
+@Plugin(name = "keyStore", category = "Core", printObject = true)
+public class KeyStoreConfiguration extends StoreConfiguration {
+    private static final StatusLogger LOGGER = StatusLogger.getLogger();
+    private KeyStore keyStore;
+    private String keyStoreType;
+
+
+    public KeyStoreConfiguration(String location, String password) {
+        super(location, password);
+        this.keyStoreType = SSLConfigurationDefaults.KEYSTORE_TYPE;
+        this.keyStore = null;
+    }
+
+    @Override
+    protected void load() throws StoreConfigurationException {
+        FileInputStream fin = null;
+
+        LOGGER.debug("Loading keystore from file with params(location={})", getLocation());
+        try {
+            if (getLocation() == null) {
+                throw new IOException("The location is null");
+            }
+            fin = new FileInputStream(getLocation());
+            KeyStore ks = KeyStore.getInstance(keyStoreType);
+            ks.load(fin, getPasswordAsCharArray());
+            keyStore = ks;
+        }
+         catch (CertificateException e) {
+            LOGGER.error("No Provider supports a KeyStoreSpi implementation for the specified type {}", keyStoreType);
+            throw new StoreConfigurationException(e);
+        } catch (NoSuchAlgorithmException e) {
+            LOGGER.error("The algorithm used to check the integrity of the keystore cannot be found");
+            throw new StoreConfigurationException(e);
+        } catch (KeyStoreException e) {
+            LOGGER.error(e);
+            throw new StoreConfigurationException(e);
+        } catch (FileNotFoundException e) {
+            LOGGER.error("The keystore file({}) is not found", getLocation());
+            throw new StoreConfigurationException(e);
+        } catch (IOException e) {
+            LOGGER.error("Something is wrong with the format of the keystore or the given password");
+            throw new StoreConfigurationException(e);
+        }
+        finally {
+            try {
+                if (fin != null)
+                    fin.close();
+            } catch (IOException e) {
+            }
+        }
+        LOGGER.debug("Keystore successfully loaded with params(location={})", getLocation());
+    }
+
+    public KeyStore getKeyStore() throws StoreConfigurationException {
+        if (keyStore == null) {
+            load();
+        }
+        return keyStore;
+    }
+
+    /**
+     * Create a KeyStoreConfiguration.
+     * @param location The location of the KeyStore.
+     * @param password The password to access the KeyStore.
+     * @return
+     */
+    @PluginFactory
+    public static KeyStoreConfiguration createKeyStoreConfiguration(@PluginAttribute("location") String location,
+                                                                    @PluginAttribute("password") String password) {
+        return new KeyStoreConfiguration(location, password);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationException.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationException.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationException.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationException.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.ssl;
+
+/**
+ *
+ */
+public class KeyStoreConfigurationException extends StoreConfigurationException {
+    public KeyStoreConfigurationException(Exception e) {
+        super(e);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfiguration.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfiguration.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfiguration.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,247 @@
+/*
+ * 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.ssl;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import javax.net.ssl.*;
+import java.security.*;
+
+/**
+ *  SSL Configuration
+ */
+@Plugin(name = "ssl", category = "Core", printObject = true)
+public class SSLConfiguration {
+    private static final StatusLogger LOGGER = StatusLogger.getLogger();
+    private KeyStoreConfiguration keyStoreConfig;
+    private TrustStoreConfiguration trustStoreConfig;
+    private SSLContext sslContext;
+
+    private SSLConfiguration(KeyStoreConfiguration keyStoreConfig, TrustStoreConfiguration trustStoreConfig) {
+        this.keyStoreConfig = keyStoreConfig;
+        this.trustStoreConfig = trustStoreConfig;
+        this.sslContext = null;
+    }
+
+    public SSLSocketFactory getSSLSocketFactory() {
+        if (sslContext == null) {
+            this.sslContext = createSSLContext();
+        }
+        return sslContext.getSocketFactory();
+    }
+
+    public SSLServerSocketFactory getSSLServerSocketFactory() {
+            if (sslContext == null) {
+                this.sslContext = createSSLContext();
+            }
+            return sslContext.getServerSocketFactory();
+    }
+
+    private SSLContext createSSLContext() {
+        SSLContext context = null;
+
+        try {
+            context = createSSLContextBasedOnConfiguration();
+            LOGGER.debug("Creating SSLContext with the given parameters");
+        }
+        catch (TrustStoreConfigurationException e) {
+            context = createSSLContextWithTrustStoreFailure();
+        }
+        catch (KeyStoreConfigurationException e) {
+            context = createSSLContextWithKeyStoreFailure();
+        }
+        return context;
+    }
+
+    private SSLContext createSSLContextWithTrustStoreFailure() {
+        SSLContext context;
+
+        try {
+            context = createSSLContextWithDefaultTrustManagerFactory();
+            LOGGER.debug("Creating SSLContext with default truststore");
+        }
+        catch (KeyStoreConfigurationException e) {
+            context = createDefaultSSLContext();
+            LOGGER.debug("Creating SSLContext with default configuration");
+        }
+        return context;
+    }
+
+    private SSLContext createSSLContextWithKeyStoreFailure() {
+        SSLContext context;
+
+        try {
+            context = createSSLContextWithDefaultKeyManagerFactory();
+            LOGGER.debug("Creating SSLContext with default keystore");
+        }
+        catch (TrustStoreConfigurationException e) {
+            context = createDefaultSSLContext();
+            LOGGER.debug("Creating SSLContext with default configuration");
+        }
+        return context;
+    }
+
+    private SSLContext createSSLContextBasedOnConfiguration() throws KeyStoreConfigurationException, TrustStoreConfigurationException {
+        return createSSLContext(false, false);
+    }
+
+    private SSLContext createSSLContextWithDefaultKeyManagerFactory() throws TrustStoreConfigurationException {
+        try {
+            return createSSLContext(true, false);
+        } catch (KeyStoreConfigurationException dummy) {
+             LOGGER.debug("Exception occured while using default keystore. This should be a BUG");
+             return null;
+        }
+    }
+
+    private SSLContext createSSLContextWithDefaultTrustManagerFactory() throws KeyStoreConfigurationException {
+        try {
+            return createSSLContext(false, true);
+        }
+        catch (TrustStoreConfigurationException dummy) {
+            LOGGER.debug("Exception occured while using default truststore. This should be a BUG");
+            return null;
+        }
+    }
+
+    private SSLContext createDefaultSSLContext() {
+        try {
+            return SSLContext.getDefault();
+        } catch (NoSuchAlgorithmException e) {
+            LOGGER.error("Failed to create an SSLContext with default configuration");
+            return null;
+        }
+    }
+
+    private SSLContext createSSLContext(boolean loadDefaultKeyManagerFactory, boolean loadDefaultTrustManagerFactory)
+            throws KeyStoreConfigurationException, TrustStoreConfigurationException {
+        try {
+            KeyManager[] kManagers = null;
+            TrustManager[] tManagers = null;
+
+            SSLContext sslContext = SSLContext.getInstance(SSLConfigurationDefaults.PROTOCOL);
+            if (!loadDefaultKeyManagerFactory) {
+                KeyManagerFactory kmFactory = loadKeyManagerFactory();
+                kManagers = kmFactory.getKeyManagers();
+            }
+            if (!loadDefaultTrustManagerFactory) {
+                TrustManagerFactory tmFactory = loadTrustManagerFactory();
+                tManagers = tmFactory.getTrustManagers();
+            }
+
+            sslContext.init(kManagers, tManagers, null);
+            return sslContext;
+        }
+        catch (NoSuchAlgorithmException e) {
+            LOGGER.error("No Provider supports a TrustManagerFactorySpi implementation for the specified protocol");
+            throw new TrustStoreConfigurationException(e);
+        }
+        catch (KeyManagementException e) {
+            LOGGER.error("Failed to initialize the SSLContext");
+            throw new KeyStoreConfigurationException(e);
+        }
+    }
+
+    private TrustManagerFactory loadTrustManagerFactory() throws TrustStoreConfigurationException {
+        KeyStore trustStore = null;
+        TrustManagerFactory tmFactory = null;
+
+        if (trustStoreConfig == null)
+            throw new TrustStoreConfigurationException(new Exception("The trustStoreConfiguration is null"));
+
+        try {
+            trustStore = trustStoreConfig.getTrustStore();
+            tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+            tmFactory.init(trustStore);
+        }
+        catch (NoSuchAlgorithmException e) {
+            LOGGER.error("The specified algorithm is not available from the specified provider");
+            throw new TrustStoreConfigurationException(e);
+        } catch (KeyStoreException e) {
+            LOGGER.error("Failed to initialize the TrustManagerFactory");
+            throw new TrustStoreConfigurationException(e);
+        } catch (StoreConfigurationException e) {
+            throw new TrustStoreConfigurationException(e);
+        }
+
+        return tmFactory;
+    }
+
+    private KeyManagerFactory loadKeyManagerFactory() throws KeyStoreConfigurationException {
+        KeyStore keyStore = null;
+        KeyManagerFactory kmFactory = null;
+
+        if (keyStoreConfig == null)
+            throw new KeyStoreConfigurationException(new Exception("The keyStoreConfiguration is null"));
+
+        try {
+            keyStore = keyStoreConfig.getKeyStore();
+            kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+            kmFactory.init(keyStore, keyStoreConfig.getPasswordAsCharArray());
+        }
+        catch (NoSuchAlgorithmException e) {
+            LOGGER.error("The specified algorithm is not available from the specified provider");
+            throw new KeyStoreConfigurationException(e);
+        } catch (KeyStoreException e) {
+            LOGGER.error("Failed to initialize the TrustManagerFactory");
+            throw new KeyStoreConfigurationException(e);
+        } catch (StoreConfigurationException e) {
+            throw new KeyStoreConfigurationException(e);
+        } catch (UnrecoverableKeyException e) {
+            LOGGER.error("The key cannot be recovered (e.g. the given password is wrong)");
+            throw new KeyStoreConfigurationException(e);
+        }
+
+        return kmFactory;
+    }
+
+    public boolean equals(SSLConfiguration config) {
+        if (config == null)
+            return false;
+
+        boolean keyStoreEquals = false;
+        boolean trustStoreEquals = false;
+
+        if (keyStoreConfig != null)
+            keyStoreEquals = keyStoreConfig.equals(config.keyStoreConfig);
+        else
+            keyStoreEquals = keyStoreConfig == config.keyStoreConfig;
+
+        if (trustStoreConfig != null)
+            trustStoreEquals = trustStoreConfig.equals(config.trustStoreConfig);
+        else
+            trustStoreEquals = trustStoreConfig == config.trustStoreConfig;
+
+        return keyStoreEquals && trustStoreEquals;
+    }
+
+    /**
+     * Create an SSLConfiguration from a KeyStoreConfiguration and a TrustStoreConfiguration.
+     * @param keyStoreConfig The KeyStoreConfiguration.
+     * @param trustStoreConfig The TrustStoreConfiguration.
+     * @return
+     */
+    @PluginFactory
+    public static SSLConfiguration createSSLConfiguration(
+            @PluginElement("keyStore") KeyStoreConfiguration keyStoreConfig,
+            @PluginElement("trustStore") TrustStoreConfiguration trustStoreConfig) {
+        return new SSLConfiguration(keyStoreConfig, trustStoreConfig);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationDefaults.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationDefaults.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationDefaults.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationDefaults.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,27 @@
+/*
+ * 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.ssl;
+
+/**
+ *
+ */
+public class SSLConfigurationDefaults {
+
+    public static final String KEYSTORE_TYPE = "JKS";
+    public static final String PROTOCOL = "SSL";
+
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationException.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationException.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationException.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SSLConfigurationException.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.ssl;
+
+/**
+ *
+ */
+public class SSLConfigurationException extends Exception {
+    public SSLConfigurationException(Exception e) {
+        super(e);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.ssl;
+
+/**
+ *
+ */
+public class StoreConfiguration {
+    private String location;
+    private String password;
+
+    public StoreConfiguration(String location, String password) {
+        this.location = location;
+        this.password = password;
+    }
+
+    public String getLocation() {
+        return location;
+    }
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public char[] getPasswordAsCharArray() {
+        if (password == null)
+            return null;
+        else
+            return password.toCharArray();
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public boolean equals(StoreConfiguration config) {
+        if (config == null)
+            return false;
+
+        boolean locationEquals = false;
+        boolean passwordEquals = false;
+
+        if (location != null)
+            locationEquals = location.equals(config.location);
+        else
+            locationEquals = location == config.location;
+
+        if (password != null)
+            passwordEquals = password.equals(config.password);
+        else
+            passwordEquals = password == config.password;
+
+        return locationEquals && passwordEquals;
+    }
+
+    protected void load() throws StoreConfigurationException {
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationException.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationException.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationException.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationException.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,26 @@
+/*
+* 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.ssl;
+
+/**
+ *
+ */
+public class StoreConfigurationException extends Exception {
+    public StoreConfigurationException(Exception e) {
+        super(e);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java Thu Sep  5 20:02:34 2013
@@ -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.core.net.ssl;
+
+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.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import java.io.*;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+
+/**
+ * The TrustStoreConfiguration.
+ */
+@Plugin(name = "trustStore", category = "Core", printObject = true)
+public class TrustStoreConfiguration extends StoreConfiguration {
+    private static final StatusLogger LOGGER = StatusLogger.getLogger();
+    private KeyStore trustStore;
+    private String trustStoreType;
+
+    public TrustStoreConfiguration(String location, String password) {
+        super(location, password);
+        trustStoreType = SSLConfigurationDefaults.KEYSTORE_TYPE;
+        trustStore = null;
+    }
+
+    @Override
+    protected void load() throws StoreConfigurationException {
+        KeyStore ts = null;
+        InputStream in = null;
+
+        LOGGER.debug("Loading truststore from file with params(location={})", getLocation());
+        try {
+            if (getLocation() == null) {
+                throw new IOException("The location is null");
+            }
+            ts = KeyStore.getInstance(trustStoreType);
+            in = new FileInputStream(getLocation());
+            ts.load(in, getPasswordAsCharArray());
+        }
+        catch (CertificateException e) {
+            LOGGER.error("No Provider supports a KeyStoreSpi implementation for the specified type {}", trustStoreType);
+            throw new StoreConfigurationException(e);
+        } catch (NoSuchAlgorithmException e) {
+            LOGGER.error("The algorithm used to check the integrity of the keystore cannot be found");
+            throw new StoreConfigurationException(e);
+        } catch (KeyStoreException e) {
+            LOGGER.error(e);
+            throw new StoreConfigurationException(e);
+        } catch (FileNotFoundException e) {
+            LOGGER.error("The keystore file({}) is not found", getLocation());
+            throw new StoreConfigurationException(e);
+        } catch (IOException e) {
+            LOGGER.error("Something is wrong with the format of the truststore or the given password: {}", e.getMessage());
+            throw new StoreConfigurationException(e);
+        } finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            }
+            catch (Exception e) {
+                LOGGER.warn("Error closing {}", getLocation(), e);
+            }
+        }
+        trustStore = ts;
+        LOGGER.debug("Truststore successfully loaded with params(location={})", getLocation());
+    }
+
+    public KeyStore getTrustStore() throws StoreConfigurationException {
+        if (trustStore == null) {
+            load();
+        }
+        return trustStore;
+    }
+
+    /**
+     * Create a TrustStoreConfiguration.
+     * @param location The location of the TrustStore.
+     * @param password The password required to access the TrustStore.
+     * @return
+     */
+    @PluginFactory
+    public static TrustStoreConfiguration createTrustStoreConfiguration(@PluginAttribute("location") String location,
+                                                                        @PluginAttribute("password") String password){
+        return new TrustStoreConfiguration(location, password);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationException.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationException.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationException.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationException.java Thu Sep  5 20:02:34 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.ssl;
+
+/**
+ *
+ */
+public class TrustStoreConfigurationException extends StoreConfigurationException {
+    public TrustStoreConfigurationException(Exception e) {
+        super(e);
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/package-info.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/package-info.java?rev=1520406&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/package-info.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/package-info.java Thu Sep  5 20:02:34 2013
@@ -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.
+ */
+/**
+ * Log4j 2.0 SSL support
+ */
+package org.apache.logging.log4j.core.net.ssl;
\ No newline at end of file

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd?rev=1520406&r1=1520405&r2=1520406&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd Thu Sep  5 20:02:34 2013
@@ -1,4 +1,20 @@
 <?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.
+-->
 <!--DTD generated by XMLSpy v2011 rel. 3 sp1 (x64) (http://www.altova.com)-->
 <!--the entity declarations may be overridden in the internal subset-->
 <!--namespace prefixes-->

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java?rev=1520406&r1=1520405&r2=1520406&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java Thu Sep  5 20:02:34 2013
@@ -16,287 +16,98 @@
  */
 package org.apache.logging.log4j.core.appender;
 
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.MarkerManager;
-import org.apache.logging.log4j.ThreadContext;
-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.message.StructuredDataMessage;
+import org.apache.logging.log4j.core.net.mock.MockSyslogServerFactory;
 import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import java.net.SocketException;
 
 /**
  *
  */
-public class SyslogAppenderTest {
-
-    private static final String PORT = "8199";
-    private static final int PORTNUM = Integer.parseInt(PORT);
-
-    private static BlockingQueue<String> list = new ArrayBlockingQueue<String>(10);
-
-    private static TCPSocketServer tcp;
-    private static UDPSocketServer udp;
-
-    LoggerContext ctx = (LoggerContext) LogManager.getContext();
-    Logger root = ctx.getLogger("SyslogAppenderTest");
+public class SyslogAppenderTest extends SyslogAppenderTestBase {
 
-    private static int tcpCount = 0;
-    private static int udpCount = 0;
-
-    private static final String line1 =
-        "TestApp - Audit [Transfer@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"]" +
-        "[RequestContext@18060 ipAddress=\"192.168.0.120\" loginId=\"JohnDoe\"] Transfer Complete\n";
-
-    @BeforeClass
-    public static void setupClass() throws Exception {
-        tcp = new TCPSocketServer();
-        tcp.start();
-        udp = new UDPSocketServer();
-        udp.start();
-        ((LoggerContext) LogManager.getContext()).reconfigure();
+    public SyslogAppenderTest() {
+        root = ctx.getLogger("SyslogAppenderTest");
     }
 
-    @AfterClass
-    public static void cleanupClass() {
-        tcp.shutdown();
-        udp.shutdown();
+    @Before
+    public void setUp() {
+        sentMessages.clear();
     }
 
     @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();
+        removeAppenders();
+        if (syslogServer != null) {
+            syslogServer.shutdown();
         }
-        tcpCount = 0;
-        udpCount = 0;
     }
 
     @Test
     public void testTCPAppender() throws Exception {
-        final SyslogAppender appender = createAppender("tcp", "bsd");
-        appender.start();
+        initTCPTestEnvironment(null);
 
-        // set appender on root and set level to debug
-        root.addAppender(appender);
-        root.setAdditive(false);
-        root.setLevel(Level.DEBUG);
-        root.debug("This is a test message");
-        String msg = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", msg);
-        assertTrue("Incorrect msg: " + msg, msg.endsWith("This is a test message\n"));
-        assertTrue("Message not delivered via TCP", tcpCount > 0);
-        root.debug("This is test message 2");
-        msg = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", msg);
-        assertTrue("Incorrect msg: " + msg, msg.endsWith("This is test message 2\n"));
-        assertTrue("Message not delivered via TCP", tcpCount > 1);
+        sendAndCheckLegacyBSDMessage("This is a test message");
+        sendAndCheckLegacyBSDMessage("This is a test message 2");
     }
 
-
     @Test
     public void testDefaultAppender() throws Exception {
-        final SyslogAppender appender = createAppender("tcp", null);
-        appender.start();
+        initTCPTestEnvironment(null);
 
-        // set appender on root and set level to debug
-        root.addAppender(appender);
-        root.setAdditive(false);
-        root.setLevel(Level.DEBUG);
-        root.debug("This is a test message");
-        String msg = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", msg);
-        assertTrue("Incorrect msg: " + msg, msg.endsWith("This is a test message\n"));
-        assertTrue("Message not delivered via TCP", tcpCount > 0);
-        root.debug("This is test message 2");
-        msg = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", msg);
-        assertTrue("Incorrect msg: " + msg, msg.endsWith("This is test message 2\n"));
-        assertTrue("Message not delivered via TCP", tcpCount > 1);
+        sendAndCheckLegacyBSDMessage("This is a test message");
+        sendAndCheckLegacyBSDMessage("This is a test message 2");
     }
 
-
-
     @Test
     public void testTCPStructuredAppender() throws Exception {
-        final SyslogAppender appender = createAppender("tcp", "RFC5424");
-        appender.start();
+        initTCPTestEnvironment("RFC5424");
 
-        // set appender on root and set level to debug
-        root.addAppender(appender);
-        root.setLevel(Level.DEBUG);
-        root.setAdditive(false);
-        ThreadContext.put("loginId", "JohnDoe");
-        ThreadContext.put("ipAddress", "192.168.0.120");
-        ThreadContext.put("locale", Locale.US.getDisplayName());
-        final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit");
-        msg.put("ToAccount", "123456");
-        msg.put("FromAccount", "123457");
-        msg.put("Amount", "200.00");
-        root.info(MarkerManager.getMarker("EVENT"), msg);
-        final String str = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", str);
-        assertTrue("Incorrect msg: " + str, str.endsWith(line1));
-        assertTrue("Message not delivered via TCP", tcpCount > 0);
+        sendAndCheckStructuredMessage();
     }
 
-
     @Test
     public void testUDPAppender() throws Exception {
+        initUDPTestEnvironment("bsd");
 
-        final SyslogAppender appender = createAppender("udp", "bsd");
-        appender.start();
-
-        // set appender on root and set level to debug
-        root.addAppender(appender);
-        root.setLevel(Level.DEBUG);
-        root.setAdditive(false);
-        root.debug("This is a test message");
-        final String str = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", str);
-        assertTrue("Incorrect msg: " + str, str.endsWith("This is a test message\n"));
-        assertTrue("Message not delivered via UDP", udpCount > 0);
+        sendAndCheckLegacyBSDMessage("This is a test message");
         root.removeAppender(appender);
         appender.stop();
     }
 
-
     @Test
     public void testUDPStructuredAppender() throws Exception {
-        final SyslogAppender appender = createAppender("udp", "RFC5424");
-        appender.start();
+        initUDPTestEnvironment("RFC5424");
 
-        // set appender on root and set level to debug
-        root.addAppender(appender);
-        root.setLevel(Level.DEBUG);
-        root.setAdditive(false);
-        ThreadContext.put("loginId", "JohnDoe");
-        ThreadContext.put("ipAddress", "192.168.0.120");
-        ThreadContext.put("locale", Locale.US.getDisplayName());
-        final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit");
-        msg.put("ToAccount", "123456");
-        msg.put("FromAccount", "123457");
-        msg.put("Amount", "200.00");
-        root.info(MarkerManager.getMarker("EVENT"), msg);
-        final String str = list.poll(3, TimeUnit.SECONDS);
-        assertNotNull("No event retrieved", str);
-        assertTrue("Incorrect msg: " + str, str.endsWith(line1));
-        assertTrue("Message not delivered via TCP", udpCount > 0);
+        sendAndCheckStructuredMessage();
         root.removeAppender(appender);
         appender.stop();
     }
 
-    private SyslogAppender createAppender(final String protocol, final String format) {
-        return SyslogAppender.createAppender("localhost", PORT, protocol, "-1", null, "Test", "true", "false", "LOCAL0", "Audit",
-            "18060", "true", "RequestContext", null, null, "true", null, "TestApp", "Test", null, "ipAddress,loginId",
-            null, format, null, null, null, null, null, null);
+    protected void initUDPTestEnvironment(String messageFormat) throws SocketException {
+        syslogServer = MockSyslogServerFactory.createUDPSyslogServer(1, PORTNUM);
+        syslogServer.start();
+        initAppender("udp", messageFormat);
     }
 
-    public static class UDPSocketServer extends Thread {
-        private final DatagramSocket sock;
-        private boolean shutdown = false;
-        private Thread thread;
-
-        public UDPSocketServer() throws IOException {
-            this.sock = new DatagramSocket(PORTNUM);
-        }
-
-        public void shutdown() {
-            this.shutdown = true;
-            thread.interrupt();
-        }
-
-        @Override
-        public void run() {
-            this.thread = Thread.currentThread();
-            final byte[] bytes = new byte[4096];
-            final DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
-            try {
-                while (!shutdown) {
-                    sock.receive(packet);
-                    final String str = new String(packet.getData(), 0, packet.getLength());
-                    ++udpCount;
-                    list.add(str);
-                }
-            } catch (final Exception ex) {
-                if (!shutdown) {
-                    throw new RuntimeException(ex);
-                }
-            }
-        }
+    protected void initTCPTestEnvironment(String messageFormat) throws IOException {
+        syslogServer = MockSyslogServerFactory.createTCPSyslogServer(1, PORTNUM);
+        syslogServer.start();
+        initAppender("tcp", messageFormat);
     }
 
-    public static class TCPSocketServer extends Thread {
-
-        private final ServerSocket sock;
-        private boolean shutdown = false;
-        private Thread thread;
-
-        public TCPSocketServer() throws IOException {
-            this.sock = new ServerSocket(PORTNUM);
-        }
-
-        public void shutdown() {
-            this.shutdown = true;
-            thread.interrupt();
-        }
-
-        @Override
-        public void run() {
-            this.thread = Thread.currentThread();
-            while (!shutdown) {
-                try {
-                    final byte[] buffer = new byte[4096];
-                    final Socket socket = sock.accept();
-                    socket.setSoLinger(true, 0);
-                    if (socket != null) {
-                        final InputStream in = socket.getInputStream();
-                        int i = in.read(buffer, 0, buffer.length);
-                        while (i != -1) {
-                            if (i < buffer.length) {
-                                final String line = new String(buffer, 0, i);
-                                ++tcpCount;
-                                list.add(line);
-                                i = in.read(buffer, 0, buffer.length);
-                            } else if (i == 0) {
-                                System.out.println("No data received");
-                            } else {
-                                System.out.println("Message too long");
-                            }
-                        }
-
-                        socket.close();
-                    }
-                } catch (final Exception ex) {
-                    if (!shutdown) {
-                        System.out.println("Caught exception: " + ex.getMessage());
-                    }
-                }
-            }
-
-        }
+    protected void initAppender(String transportFormat, String messageFormat) {
+        appender = createAppender(transportFormat, messageFormat);
+        appender.start();
+       initRootLogger(appender);
     }
 
+    private SyslogAppender createAppender(final String protocol, final String format) {
+        return SyslogAppender.createAppender("localhost", PORT, protocol, "-1", null, "Test", "true", "false", "LOCAL0", "Audit",
+            "18060", "true", "RequestContext", null, null, includeNewLine, null, "TestApp", "Test", null, "ipAddress,loginId",
+            null, format, null, null, null, null, null, null);
+    }
 }



Mime
View raw message