You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2017/05/23 08:49:44 UTC

[01/14] logging-log4j2 git commit: LOG4J2-1442 Generic HTTP appender

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 92e4b8754 -> bbf769685


LOG4J2-1442 Generic HTTP 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/410f9d36
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/410f9d36
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/410f9d36

Branch: refs/heads/master
Commit: 410f9d360eabcdc6949c75973b786c9e2cec9c66
Parents: 8852cd1
Author: Mikael Ståldal <mi...@magine.com>
Authored: Thu May 4 14:21:59 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Thu May 4 14:45:04 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/appender/HttpAppender.java       | 161 +++++++++++++++++++
 .../log4j/core/appender/HttpManager.java        |  82 ++++++++++
 .../log4j/core/appender/HttpAppenderTest.java   |  52 ++++++
 .../src/test/resources/HttpAppenderTest.xml     |  43 +++++
 src/changes/changes.xml                         |   3 +
 src/site/site.xml                               |   1 +
 src/site/xdoc/manual/appenders.xml              |  78 +++++++++
 7 files changed, 420 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
new file mode 100644
index 0000000..e0f1b27
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
@@ -0,0 +1,161 @@
+/*
+ * 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 java.io.IOException;
+import java.io.Serializable;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Node;
+import org.apache.logging.log4j.core.config.Property;
+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.config.plugins.validation.constraints.Required;
+
+/**
+ * Sends log events over HTTP.
+ */
+@Plugin(name = "Http", category = Node.CATEGORY, elementType = Appender.ELEMENT_TYPE, printObject = true)
+public final class HttpAppender extends AbstractAppender {
+
+    /**
+     * Builds HttpAppender instances.
+     * @param <B> The type to build
+     */
+    public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B>
+            implements org.apache.logging.log4j.core.util.Builder<HttpAppender> {
+
+        @PluginBuilderAttribute
+        @Required(message = "No URL provided for HttpAppender")
+        private String url;
+
+        @PluginBuilderAttribute
+        private String method = "POST";
+
+        @PluginBuilderAttribute
+        private int connectTimeoutMillis = 0;
+
+        @PluginBuilderAttribute
+        private int readTimeoutMillis = 0;
+
+        @PluginElement("Headers")
+        private Property[] headers;
+
+        @Override
+        public HttpAppender build() {
+            final HttpManager httpManager = new HttpManager(getConfiguration(), getConfiguration().getLoggerContext(),
+                getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers);
+            return new HttpAppender(getName(), getLayout(), getFilter(), isIgnoreExceptions(), httpManager);
+        }
+
+        public String getUrl() {
+            return url;
+        }
+
+        public String getMethod() {
+            return method;
+        }
+
+        public int getConnectTimeoutMillis() {
+            return connectTimeoutMillis;
+        }
+
+        public int getReadTimeoutMillis() {
+            return readTimeoutMillis;
+        }
+
+        public Property[] getHeaders() {
+            return headers;
+        }
+
+        public B setUrl(final String url) {
+            this.url = url;
+            return asBuilder();
+        }
+
+        public B setMethod(final String method) {
+            this.method = method;
+            return asBuilder();
+        }
+
+        public B setConnectTimeoutMillis(int connectTimeoutMillis) {
+            this.connectTimeoutMillis = connectTimeoutMillis;
+            return asBuilder();
+        }
+
+        public B setReadTimeoutMillis(int readTimeoutMillis) {
+            this.readTimeoutMillis = readTimeoutMillis;
+            return asBuilder();
+        }
+
+        public B setHeaders(final Property[] headers) {
+            this.headers = headers;
+            return asBuilder();
+        }
+    }
+
+    /**
+     * @return a builder for a HttpAppender.
+     */
+    @PluginBuilderFactory
+    public static <B extends Builder<B>> B newBuilder() {
+        return new Builder<B>().asBuilder();
+    }
+
+    private final HttpManager manager;
+
+    private HttpAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter,
+                         final boolean ignoreExceptions, final HttpManager manager) {
+        super(name, filter, layout, ignoreExceptions);
+        Objects.requireNonNull(layout, "layout");
+        this.manager = Objects.requireNonNull(manager, "manager");
+    }
+
+    @Override
+    public void append(final LogEvent event) {
+        try {
+            manager.send(getLayout(), event);
+        } catch (final Exception e) {
+            error("Unable to send HTTP in appender [" + getName() + "]", event, e);
+        }
+    }
+
+    @Override
+    public boolean stop(final long timeout, final TimeUnit timeUnit) {
+        setStopping();
+        boolean stopped = super.stop(timeout, timeUnit, false);
+        stopped &= manager.stop(timeout, timeUnit);
+        setStopped();
+        return stopped;
+    }
+
+    @Override
+    public String toString() {
+        return "HttpAppender{" +
+            "name=" + getName() +
+            ", state=" + getState() +
+            '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
new file mode 100644
index 0000000..8f69659
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.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.core.appender;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Objects;
+
+import org.apache.logging.log4j.core.Layout;
+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.ConfigurationException;
+import org.apache.logging.log4j.core.config.Property;
+
+public class HttpManager extends AbstractManager {
+
+    private final Configuration configuration;
+    private final URL url;
+    private final String method;
+    private final int connectTimeoutMillis;
+    private final int readTimeoutMillis;
+    private final Property[] headers;
+
+    public HttpManager(final Configuration configuration, LoggerContext loggerContext, final String name,
+                       final String url, final String method, final int connectTimeoutMillis, final int readTimeoutMillis,
+                       final Property[] headers) {
+        super(loggerContext, name);
+        this.configuration = Objects.requireNonNull(configuration);
+        try {
+            this.url = new URL(url);
+        } catch (MalformedURLException e) {
+            throw new ConfigurationException(e);
+        }
+        this.method = Objects.requireNonNull(method, "method");
+        this.connectTimeoutMillis = connectTimeoutMillis;
+        this.readTimeoutMillis = readTimeoutMillis;
+        this.headers = headers != null ? headers : new Property[0];
+    }
+
+    public void send(final Layout<?> layout, final LogEvent event) throws IOException {
+        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
+        urlConnection.setAllowUserInteraction(false);
+        urlConnection.setDoOutput(true);
+        urlConnection.setDoInput(true);
+        urlConnection.setRequestMethod(method);
+        if (connectTimeoutMillis > 0) urlConnection.setConnectTimeout(connectTimeoutMillis);
+        if (readTimeoutMillis > 0) urlConnection.setReadTimeout(readTimeoutMillis);
+        if (layout.getContentType() != null) urlConnection.setRequestProperty("Content-Type", layout.getContentType());
+        for (Property header : headers) {
+            urlConnection.setRequestProperty(
+                header.getName(),
+                header.isValueNeedsLookup() ? configuration.getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
+        }
+        byte[] msg = layout.toByteArray(event);
+        urlConnection.setFixedLengthStreamingMode(msg.length);
+        urlConnection.connect();
+        try (OutputStream os = urlConnection.getOutputStream()) {
+            os.write(msg);
+        }
+        urlConnection.getInputStream().close();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
new file mode 100644
index 0000000..98120a1
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -0,0 +1,52 @@
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.Rule;
+import org.junit.Test;
+
+// TODO this test requires manual verification
+public class HttpAppenderTest {
+
+    private static final String LOG_MESSAGE = "Hello, world!";
+
+    private static Log4jLogEvent createLogEvent() {
+        return Log4jLogEvent.newBuilder()
+            .setLoggerName(HttpAppenderTest.class.getName())
+            .setLoggerFqcn(HttpAppenderTest.class.getName())
+            .setLevel(Level.INFO)
+            .setMessage(new SimpleMessage(LOG_MESSAGE))
+            .build();
+    }
+
+    @Rule
+    public LoggerContextRule ctx = new LoggerContextRule("HttpAppenderTest.xml");
+
+    @Test
+    public void testAppendSuccess() throws Exception {
+        final Appender appender = ctx.getRequiredAppender("HttpSuccess");
+        appender.append(createLogEvent());
+    }
+
+    @Test
+    public void testAppendErrorIgnore() throws Exception {
+        final Appender appender = ctx.getRequiredAppender("HttpErrorIgnore");
+        appender.append(createLogEvent());
+    }
+
+    @Test(expected = AppenderLoggingException.class)
+    public void testAppendError() throws Exception {
+        final Appender appender = ctx.getRequiredAppender("HttpError");
+        appender.append(createLogEvent());
+    }
+
+    @Test
+    public void testAppendSubst() throws Exception {
+        final Appender appender = ctx.getRequiredAppender("HttpSubst");
+        appender.append(createLogEvent());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/log4j-core/src/test/resources/HttpAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/HttpAppenderTest.xml b/log4j-core/src/test/resources/HttpAppenderTest.xml
new file mode 100644
index 0000000..30edaa0
--- /dev/null
+++ b/log4j-core/src/test/resources/HttpAppenderTest.xml
@@ -0,0 +1,43 @@
+<?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="HttpAppenderTest" status="WARN">
+  <Appenders>
+    <Http name="HttpSuccess" url="http://localhost:9200/test/log4j/">
+      <Property name="X-Test" value="header value" />
+      <JsonLayout properties="true"/>
+    </Http>
+    <Http name="HttpErrorIgnore" url="http://localhost:9200/test/log4j/" method="PUT">
+      <JsonLayout properties="true"/>
+    </Http>
+    <Http name="HttpError" url="http://localhost:9200/test/log4j/" method="PUT" ignoreExceptions="false">
+      <JsonLayout properties="true"/>
+    </Http>
+    <Http name="HttpSubst" url="http://localhost:9200/test/log4j/">
+      <Property name="X-Test" value="$${java:runtime}" />
+      <JsonLayout properties="true"/>
+    </Http>
+  </Appenders>
+  <Loggers>
+    <Root level="info">
+      <AppenderRef ref="HttpSuccess"/>
+      <AppenderRef ref="HttpErrorIgnore"/>
+      <AppenderRef ref="HttpError"/>
+      <AppenderRef ref="HttpSubst"/>
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 379c21e..d0f8133 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
          - "remove" - Removed
     -->
     <release version="2.9.0" date="2017-MM-DD" description="GA Release 2.9.0">
+      <action issue="LOG4J2-1442" dev="mikes" type="add">
+        Generic HTTP appender.
+      </action>
       <action issue="LOG4J2-1854" dev="mikes" type="add" due-to="Xavier Jodoin">
         Support null byte delimiter in GelfLayout.
       </action>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index e380c82..aa161fe 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -134,6 +134,7 @@
         <item name="JDBC" href="/manual/appenders.html#JDBCAppender"/>
         <item name="JMS" href="/manual/appenders.html#JMSAppender"/>
         <item name="JPA" href="/manual/appenders.html#JPAAppender"/>
+        <item name="HTTP" href="/manual/appenders.html#HttpAppender"/>
         <item name="Kafka" href="/manual/appenders.html#KafkaAppender"/>
         <item name="Memory Mapped File" href="/manual/appenders.html#MemoryMappedFileAppender"/>
         <item name="NoSQL" href="/manual/appenders.html#NoSQLAppender"/>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/410f9d36/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index 28d9aa4..f7721df 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1538,6 +1538,84 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
     ...
 }]]></pre>
         </subsection>
+        <a name="HttpAppender"/>
+        <subsection name="HttpAppender">
+          <p>
+            The HttpAppender sends log events over HTTP. A Layout must be provided to format the LogEvent.
+          </p>
+          <p>
+            Will set the <code>Content-Type</code> header according to the layout. Additional headers can be specified
+            with embedded Property elements.
+          </p>
+          <table>
+            <caption align="top">HttpAppender Parameters</caption>
+            <tr>
+              <th>Parameter Name</th>
+              <th>Type</th>
+              <th>Description</th>
+            </tr>
+            <tr>
+              <td>name</td>
+              <td>String</td>
+              <td>The name of the Appender.</td>
+            </tr>
+            <tr>
+              <td>filter</td>
+              <td>Filter</td>
+              <td>A Filter to determine if the event should be handled by this Appender. More than one Filter
+                may be used by using a CompositeFilter.</td>
+            </tr>
+            <tr>
+              <td>layout</td>
+              <td>Layout</td>
+              <td>The Layout to use to format the LogEvent.</td>
+            </tr>
+            <tr>
+              <td>url</td>
+              <td>string</td>
+              <td>The URL to use. The URL scheme must be "http" or "https".</td>
+            </tr>
+            <tr>
+              <td>method</td>
+              <td>string</td>
+              <td>The HTTP method to use. Optional, default is "POST".</td>
+            </tr>
+            <tr>
+              <td>connectTimeoutMillis</td>
+              <td>integer</td>
+              <td>The connect timeout in milliseconds. Optional, default is 0 (infinite timeout).</td>
+            </tr>
+            <tr>
+              <td>readTimeoutMillis</td>
+              <td>integer</td>
+              <td>The socket read timeout in milliseconds. Optional, default is 0 (infinite timeout).</td>
+            </tr>
+            <tr>
+              <td>headers</td>
+              <td>Property[]</td>
+              <td>Additional HTTP headers to use. The values support <a href="lookups.html">lookups</a></td>
+            </tr>
+            <tr>
+              <td>ignoreExceptions</td>
+              <td>boolean</td>
+              <td>The default is <code>true</code>, causing exceptions encountered while appending events to be
+                internally logged and then ignored. When set to <code>false</code> exceptions will be propagated to the
+                caller, instead. You must set this to <code>false</code> when wrapping this Appender in a
+                <a href="#FailoverAppender">FailoverAppender</a>.</td>
+            </tr>
+          </table>
+          <p>
+            Here is a sample HttpAppender configuration snippet:
+          </p>
+          <pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
+  ...
+  <Appenders>
+    <Http name="Http" url="http://localhost:9200/test/log4j/">
+      <Property name="X-Java-Runtime" value="$${java:runtime}" />
+      <JsonLayout properties="true"/>
+    </Http>
+  </Appenders>]]></pre>
+        </subsection>
         <a name="KafkaAppender"/>
         <subsection name="KafkaAppender">
           <p>


[06/14] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1442

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1442


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bcb72644
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bcb72644
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bcb72644

Branch: refs/heads/master
Commit: bcb7264491b89a4cb9f672a276cc00ff48c484cd
Parents: 7f9f60b 68e43b8
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed May 10 14:12:34 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed May 10 14:12:34 2017 +0200

----------------------------------------------------------------------
 .travis-toolchains.xml                          |  37 +++
 .travis.yml                                     |  20 +-
 BUILDING.md                                     |  12 +-
 .../java/org/apache/logging/log4j/Timer.java    |  25 +-
 .../logging/log4j/core/SimplePerfTest.java      |   2 +-
 .../logging/log4j/core/ThreadedPerfTest.java    |   2 +-
 .../net/ssl/AbstractKeyStoreConfiguration.java  |   4 +
 .../core/net/ssl/KeyStoreConfiguration.java     |   4 +
 .../log4j/core/net/ssl/SslConfiguration.java    |  16 ++
 .../log4j/core/net/ssl/StoreConfiguration.java  |  44 ++-
 .../core/net/ssl/TrustStoreConfiguration.java   |   4 +
 .../logging/log4j/core/util/WatchManager.java   |   6 +
 .../apache/logging/log4j/core/util/Timer.java   | 273 -------------------
 pom.xml                                         |  10 +-
 src/changes/changes.xml                         |   9 +
 src/site/markdown/build.md                      |  18 +-
 src/site/site.xml                               |   7 +-
 toolchains-sample-linux.xml                     |  52 ++++
 toolchains-sample-mac.xml                       |  52 ++++
 toolchains-sample-win.xml                       |  52 ++++
 toolchains-sample.xml                           |  52 ----
 21 files changed, 320 insertions(+), 381 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcb72644/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcb72644/src/changes/changes.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcb72644/src/site/site.xml
----------------------------------------------------------------------


[14/14] logging-log4j2 git commit: LOG4J2-1442 fix configuration

Posted by mi...@apache.org.
LOG4J2-1442 fix configuration


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bbf76968
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bbf76968
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bbf76968

Branch: refs/heads/master
Commit: bbf7696855b86d2bfe51b12693edb633cbe02c73
Parents: 8c10f78
Author: Mikael Ståldal <mi...@magine.com>
Authored: Tue May 23 10:04:59 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Tue May 23 10:04:59 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/appender/HttpURLConnectionManager.java       | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bbf76968/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
index a47684e..923b15f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
@@ -43,6 +43,7 @@ public class HttpURLConnectionManager extends HttpManager {
     private static final Charset CHARSET = Charset.forName("US-ASCII");
 
     private final URL url;
+    private final boolean isHttps;
     private final String method;
     private final int connectTimeoutMillis;
     private final int readTimeoutMillis;
@@ -63,17 +64,15 @@ public class HttpURLConnectionManager extends HttpManager {
         } catch (MalformedURLException e) {
             throw new ConfigurationException(e);
         }
+        this.isHttps = this.url.getProtocol().equalsIgnoreCase("https");
         this.method = Objects.requireNonNull(method, "method");
         this.connectTimeoutMillis = connectTimeoutMillis;
         this.readTimeoutMillis = readTimeoutMillis;
         this.headers = headers != null ? headers : new Property[0];
         this.sslConfiguration = sslConfiguration;
-        if (this.sslConfiguration != null && !this.url.getProtocol().equalsIgnoreCase("https")) {
+        if (this.sslConfiguration != null && !isHttps) {
             throw new ConfigurationException("SSL configuration can only be specified with URL scheme https");
         }
-        if (!this.verifyHostname && !this.url.getProtocol().equalsIgnoreCase("https")) {
-            throw new ConfigurationException("verifyHostname=false can only be specified with URL scheme https");
-        }
     }
 
     @Override
@@ -94,7 +93,7 @@ public class HttpURLConnectionManager extends HttpManager {
         if (sslConfiguration != null) {
             ((HttpsURLConnection)urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
         }
-        if (!verifyHostname) {
+        if (isHttps && !verifyHostname) {
             ((HttpsURLConnection)urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
         }
 


[03/14] logging-log4j2 git commit: Fix typo

Posted by mi...@apache.org.
Fix typo


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/857c3e1d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/857c3e1d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/857c3e1d

Branch: refs/heads/master
Commit: 857c3e1dd432b46c53e1c83c405511416f9f7b96
Parents: 0af515f
Author: Mikael Ståldal <mi...@magine.com>
Authored: Thu May 4 15:37:09 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Thu May 4 15:37:09 2017 +0200

----------------------------------------------------------------------
 src/site/xdoc/manual/appenders.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/857c3e1d/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index f7721df..add1e52 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1593,7 +1593,7 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
             <tr>
               <td>headers</td>
               <td>Property[]</td>
-              <td>Additional HTTP headers to use. The values support <a href="lookups.html">lookups</a></td>
+              <td>Additional HTTP headers to use. The values support <a href="lookups.html">lookups</a>.</td>
             </tr>
             <tr>
               <td>ignoreExceptions</td>


[05/14] logging-log4j2 git commit: LOG4J2-1442 Unit tests

Posted by mi...@apache.org.
LOG4J2-1442 Unit 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/7f9f60be
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7f9f60be
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7f9f60be

Branch: refs/heads/master
Commit: 7f9f60be12d85ef85e6448ccd3794c26ab041aea
Parents: fd1d7ea
Author: Mikael Ståldal <mi...@magine.com>
Authored: Tue May 9 17:40:15 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Tue May 9 17:40:15 2017 +0200

----------------------------------------------------------------------
 log4j-core/pom.xml                              |   6 +
 .../core/appender/HttpURLConnectionManager.java |  35 ++++-
 .../log4j/core/appender/HttpAppenderTest.java   | 152 ++++++++++++++++++-
 .../src/test/resources/HttpAppenderTest.xml     |  26 +---
 pom.xml                                         |   7 +
 5 files changed, 197 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7f9f60be/log4j-core/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index 7881cc4..f98b03e 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -324,6 +324,12 @@
       <version>2.4.7</version>
       <scope>test</scope>
     </dependency>
+    <!-- Used for testing HttpAppender -->
+    <dependency>
+      <groupId>com.github.tomakehurst</groupId>
+      <artifactId>wiremock</artifactId>
+      <scope>test</scope>
+    </dependency>
     <!-- GC-free -->
     <dependency>
       <groupId>com.google.code.java-allocation-instrumenter</groupId>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7f9f60be/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
index 357c5b7..d656c90 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
@@ -18,10 +18,12 @@
 package org.apache.logging.log4j.core.appender;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.Objects;
 
 import org.apache.logging.log4j.core.Layout;
@@ -30,9 +32,12 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.util.IOUtils;
 
 public class HttpURLConnectionManager extends HttpManager {
 
+    private static final Charset CHARSET = Charset.forName("US-ASCII");
+
     private final URL url;
     private final String method;
     private final int connectTimeoutMillis;
@@ -69,13 +74,41 @@ public class HttpURLConnectionManager extends HttpManager {
                 header.getName(),
                 header.isValueNeedsLookup() ? getConfiguration().getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
         }
+
         byte[] msg = layout.toByteArray(event);
         urlConnection.setFixedLengthStreamingMode(msg.length);
         urlConnection.connect();
         try (OutputStream os = urlConnection.getOutputStream()) {
             os.write(msg);
         }
-        urlConnection.getInputStream().close();
+
+        byte[] buffer = new byte[1024];
+        InputStream is = null;
+        try {
+            is = urlConnection.getInputStream();
+            while (IOUtils.EOF != is.read(buffer));
+        } catch (IOException e) {
+            StringBuilder errorMessage = new StringBuilder();
+            try (InputStream es = urlConnection.getErrorStream()) {
+                errorMessage.append(urlConnection.getResponseCode());
+                if (urlConnection.getResponseMessage() != null) {
+                    errorMessage.append(' ').append(urlConnection.getResponseMessage());
+                }
+                if (es != null) {
+                    errorMessage.append(" - ");
+                    int n;
+                    while (IOUtils.EOF != (n = es.read(buffer))) {
+                        errorMessage.append(new String(buffer, 0, n, CHARSET));
+                    }
+                }
+            }
+            if (urlConnection.getResponseCode() > -1)
+                throw new IOException(errorMessage.toString());
+            else
+                throw e;
+        } finally {
+            if (is != null) is.close();
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7f9f60be/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
index 98120a1..c9f9385 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -1,14 +1,28 @@
 package org.apache.logging.log4j.core.appender;
 
+import java.io.IOException;
+
+import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.layout.JsonLayout;
+import org.apache.logging.log4j.core.lookup.JavaLookup;
 import org.apache.logging.log4j.junit.LoggerContextRule;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.status.StatusData;
+import org.apache.logging.log4j.status.StatusListener;
+import org.apache.logging.log4j.status.StatusLogger;
 import org.junit.Rule;
 import org.junit.Test;
 
-// TODO this test requires manual verification
+import static org.junit.Assert.*;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+
+// TODO test HTTPS
 public class HttpAppenderTest {
 
     private static final String LOG_MESSAGE = "Hello, world!";
@@ -22,30 +36,152 @@ public class HttpAppenderTest {
             .build();
     }
 
+    private final ResponseDefinitionBuilder SUCCESS_RESPONSE = aResponse().withStatus(201)
+        .withHeader("Content-Type", "application/json")
+        .withBody("{\"status\":\"created\"}");
+
+    private final ResponseDefinitionBuilder FAILURE_RESPONSE = aResponse().withStatus(400)
+        .withHeader("Content-Type", "application/json")
+        .withBody("{\"status\":\"error\"}");
+
+    private final JavaLookup JAVA_LOOKUP = new JavaLookup();
+
     @Rule
     public LoggerContextRule ctx = new LoggerContextRule("HttpAppenderTest.xml");
 
+    @Rule
+    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+    @Test
+    public void testAppend() throws Exception {
+        wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
+            .willReturn(SUCCESS_RESPONSE));
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .build();
+        appender.append(createLogEvent());
+
+        wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
+            .withHeader("Host", containing("localhost"))
+            .withHeader("Content-Type", containing("application/json"))
+            .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
+    }
+
+    @Test
+    public void testAppendMethodPut() throws Exception {
+        wireMockRule.stubFor(put(urlEqualTo("/test/log4j/1234"))
+            .willReturn(SUCCESS_RESPONSE));
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .setMethod("PUT")
+            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/1234")
+            .build();
+        appender.append(createLogEvent());
+
+        wireMockRule.verify(putRequestedFor(urlEqualTo("/test/log4j/1234"))
+            .withHeader("Host", containing("localhost"))
+            .withHeader("Content-Type", containing("application/json"))
+            .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
+    }
+
     @Test
-    public void testAppendSuccess() throws Exception {
-        final Appender appender = ctx.getRequiredAppender("HttpSuccess");
+    public void testAppendCustomHeader() throws Exception {
+        wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
+            .willReturn(SUCCESS_RESPONSE));
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .setHeaders(new Property[] {
+                Property.createProperty("X-Test", "header value"),
+                Property.createProperty("X-Runtime", "${java:runtime}")
+            })
+            .build();
         appender.append(createLogEvent());
+
+        wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
+            .withHeader("Host", containing("localhost"))
+            .withHeader("X-Test", equalTo("header value"))
+            .withHeader("X-Runtime", equalTo(JAVA_LOOKUP.getRuntime()))
+            .withHeader("Content-Type", containing("application/json"))
+            .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
     }
 
+    volatile StatusData error;
+
     @Test
     public void testAppendErrorIgnore() throws Exception {
-        final Appender appender = ctx.getRequiredAppender("HttpErrorIgnore");
+        wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
+            .willReturn(FAILURE_RESPONSE));
+
+        StatusLogger.getLogger().registerListener(new StatusListener() {
+            @Override
+            public void log(StatusData data) {
+                error = data;
+            }
+
+            @Override
+            public Level getStatusLevel() {
+                return Level.ERROR;
+            }
+
+            @Override
+            public void close() throws IOException { }
+        });
+
+        error = null;
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .build();
         appender.append(createLogEvent());
+
+        wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
+            .withHeader("Host", containing("localhost"))
+            .withHeader("Content-Type", containing("application/json"))
+            .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
+
+        assertNotNull(error);
+        assertEquals(Level.ERROR, error.getLevel());
+        assertEquals("Unable to send HTTP in appender [Http]", error.getMessage().toString());
     }
 
     @Test(expected = AppenderLoggingException.class)
     public void testAppendError() throws Exception {
-        final Appender appender = ctx.getRequiredAppender("HttpError");
+        wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
+            .willReturn(FAILURE_RESPONSE));
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .withIgnoreExceptions(false)
+            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .build();
         appender.append(createLogEvent());
     }
 
-    @Test
-    public void testAppendSubst() throws Exception {
-        final Appender appender = ctx.getRequiredAppender("HttpSubst");
+    @Test(expected = AppenderLoggingException.class)
+    public void testAppendConnectError() throws Exception {
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .withIgnoreExceptions(false)
+            .setUrl("http://localhost:"+(wireMockRule.port()+1)+"/test/log4j/")
+            .build();
         appender.append(createLogEvent());
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7f9f60be/log4j-core/src/test/resources/HttpAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/HttpAppenderTest.xml b/log4j-core/src/test/resources/HttpAppenderTest.xml
index 30edaa0..4521ed6 100644
--- a/log4j-core/src/test/resources/HttpAppenderTest.xml
+++ b/log4j-core/src/test/resources/HttpAppenderTest.xml
@@ -17,27 +17,13 @@
   -->
 <Configuration name="HttpAppenderTest" status="WARN">
   <Appenders>
-    <Http name="HttpSuccess" url="http://localhost:9200/test/log4j/">
-      <Property name="X-Test" value="header value" />
-      <JsonLayout properties="true"/>
-    </Http>
-    <Http name="HttpErrorIgnore" url="http://localhost:9200/test/log4j/" method="PUT">
-      <JsonLayout properties="true"/>
-    </Http>
-    <Http name="HttpError" url="http://localhost:9200/test/log4j/" method="PUT" ignoreExceptions="false">
-      <JsonLayout properties="true"/>
-    </Http>
-    <Http name="HttpSubst" url="http://localhost:9200/test/log4j/">
-      <Property name="X-Test" value="$${java:runtime}" />
-      <JsonLayout properties="true"/>
-    </Http>
+    <Console name="Console" target="SYSTEM_OUT">
+        <PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
+    </Console>
   </Appenders>
   <Loggers>
-    <Root level="info">
-      <AppenderRef ref="HttpSuccess"/>
-      <AppenderRef ref="HttpErrorIgnore"/>
-      <AppenderRef ref="HttpError"/>
-      <AppenderRef ref="HttpSubst"/>
+    <Root level="WARN">
+      <AppenderRef ref="Console"/>
     </Root>
   </Loggers>
-</Configuration>
\ No newline at end of file
+</Configuration>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7f9f60be/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2ff0acd..cd0d4b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -751,6 +751,13 @@
         <version>2.5</version>
         <scope>test</scope>
       </dependency>
+      <!-- Used for testing HttpAppender -->
+      <dependency>
+        <groupId>com.github.tomakehurst</groupId>
+        <artifactId>wiremock</artifactId>
+        <scope>test</scope>
+        <version>2.6.0</version>
+      </dependency>
       <!-- Used for compressing to formats other than zip and gz -->
       <dependency>
         <groupId>org.apache.commons</groupId>


[08/14] logging-log4j2 git commit: LOG4J2-1442 fix failing unit tests

Posted by mi...@apache.org.
LOG4J2-1442 fix failing unit 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/2959f19c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2959f19c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2959f19c

Branch: refs/heads/master
Commit: 2959f19c8843038181f5750bd82e07af93d33e94
Parents: 9caf597
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Thu May 18 19:00:12 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Thu May 18 19:00:12 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/async/AbstractAsyncThreadContextTestBase.java   | 1 +
 .../logging/log4j/core/impl/NestedLoggingFromToStringTest.java | 6 ++++++
 2 files changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2959f19c/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AbstractAsyncThreadContextTestBase.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AbstractAsyncThreadContextTestBase.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AbstractAsyncThreadContextTestBase.java
index f6aa1d4..00cad14 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AbstractAsyncThreadContextTestBase.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AbstractAsyncThreadContextTestBase.java
@@ -45,6 +45,7 @@ public abstract class AbstractAsyncThreadContextTestBase {
 
     @BeforeClass
     public static void beforeClass() {
+        System.setProperty("log4j2.is.webapp", "false");
         System.setProperty("AsyncLogger.RingBufferSize", "128"); // minimum ringbuffer size
         System.setProperty("AsyncLoggerConfig.RingBufferSize", "128"); // minimum ringbuffer size
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2959f19c/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/NestedLoggingFromToStringTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/NestedLoggingFromToStringTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/NestedLoggingFromToStringTest.java
index fbd9dce..c5c037c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/NestedLoggingFromToStringTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/NestedLoggingFromToStringTest.java
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.junit.LoggerContextRule;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -45,6 +46,11 @@ import static org.junit.Assert.*;
  */
 public class NestedLoggingFromToStringTest {
 
+    @BeforeClass
+    public static void beforeClass() {
+        System.setProperty("log4j2.is.webapp", "false");
+    }
+    
     @Rule
     public LoggerContextRule context = new LoggerContextRule("log4j-sync-to-list.xml");
     private ListAppender listAppender;


[11/14] logging-log4j2 git commit: Fix formatting

Posted by mi...@apache.org.
Fix formatting


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b12c25c5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b12c25c5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b12c25c5

Branch: refs/heads/master
Commit: b12c25c5e13dc1cbb4e8087b855b509616a7e6f7
Parents: 93ac8ab
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon May 22 20:55:25 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon May 22 20:55:25 2017 +0200

----------------------------------------------------------------------
 .../logging/log4j/core/appender/HttpAppenderTest.java   | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b12c25c5/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
index 9ce31e0..3f55adc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -66,7 +66,7 @@ public class HttpAppenderTest {
             .withName("Http")
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
-            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .setUrl("http://localhost:" + wireMockRule.port() + "/test/log4j/")
             .build();
         appender.append(createLogEvent());
 
@@ -85,7 +85,7 @@ public class HttpAppenderTest {
             .withName("Http")
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
-            .setUrl("https://localhost:"+wireMockRule.httpsPort()+"/test/log4j/")
+            .setUrl("https://localhost:" + wireMockRule.httpsPort() + "/test/log4j/")
             .setSslConfiguration(SslConfiguration.createSSLConfiguration("TLS",
                 KeyStoreConfiguration.createKeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD, TestConstants.KEYSTORE_TYPE, null),
                 null))
@@ -108,7 +108,7 @@ public class HttpAppenderTest {
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
             .setMethod("PUT")
-            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/1234")
+            .setUrl("http://localhost:" + wireMockRule.port() + "/test/log4j/1234")
             .build();
         appender.append(createLogEvent());
 
@@ -127,7 +127,7 @@ public class HttpAppenderTest {
             .withName("Http")
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
-            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .setUrl("http://localhost:" + wireMockRule.port() + "/test/log4j/")
             .setHeaders(new Property[] {
                 Property.createProperty("X-Test", "header value"),
                 Property.createProperty("X-Runtime", "${java:runtime}")
@@ -171,7 +171,7 @@ public class HttpAppenderTest {
             .withName("Http")
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
-            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .setUrl("http://localhost:" + wireMockRule.port() + "/test/log4j/")
             .build();
         appender.append(createLogEvent());
 
@@ -195,7 +195,7 @@ public class HttpAppenderTest {
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
             .withIgnoreExceptions(false)
-            .setUrl("http://localhost:"+wireMockRule.port()+"/test/log4j/")
+            .setUrl("http://localhost:" + wireMockRule.port() + "/test/log4j/")
             .build();
         appender.append(createLogEvent());
     }


[02/14] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1442

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1442


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0af515f3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0af515f3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0af515f3

Branch: refs/heads/master
Commit: 0af515f3b1ec67422de254d08ac87b135e3c6923
Parents: 410f9d3 9ce722c
Author: Mikael Ståldal <mi...@magine.com>
Authored: Thu May 4 14:49:15 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Thu May 4 14:49:15 2017 +0200

----------------------------------------------------------------------
 .../core/appender/mom/kafka/KafkaAppender.java  | 42 +++++++++++---------
 .../core/appender/mom/kafka/KafkaManager.java   |  2 +-
 src/site/xdoc/manual/api.xml                    | 15 +++----
 3 files changed, 32 insertions(+), 27 deletions(-)
----------------------------------------------------------------------



[13/14] logging-log4j2 git commit: LOG4J2-1442 verifyHostname

Posted by mi...@apache.org.
LOG4J2-1442 verifyHostname


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8c10f781
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8c10f781
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8c10f781

Branch: refs/heads/master
Commit: 8c10f7818407c4962675adfdb8ee098ae4aa7ad3
Parents: 9b26bbe
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon May 22 22:18:11 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon May 22 22:18:11 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/appender/HttpAppender.java       | 14 +++++++-
 .../core/appender/HttpURLConnectionManager.java | 12 ++++++-
 .../log4j/core/net/ssl/LaxHostnameVerifier.java | 38 ++++++++++++++++++++
 .../log4j/core/appender/HttpAppenderTest.java   |  6 ++--
 src/site/xdoc/manual/appenders.xml              |  6 ++++
 5 files changed, 72 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c10f781/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
index efc9942..40c387f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
@@ -66,10 +66,13 @@ public final class HttpAppender extends AbstractAppender {
         @PluginElement("SslConfiguration")
         private SslConfiguration sslConfiguration;
 
+        @PluginBuilderAttribute
+        private boolean verifyHostname = true;
+
         @Override
         public HttpAppender build() {
             final HttpManager httpManager = new HttpURLConnectionManager(getConfiguration(), getConfiguration().getLoggerContext(),
-                getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers, sslConfiguration);
+                getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers, sslConfiguration, verifyHostname);
             return new HttpAppender(getName(), getLayout(), getFilter(), isIgnoreExceptions(), httpManager);
         }
 
@@ -97,6 +100,10 @@ public final class HttpAppender extends AbstractAppender {
             return sslConfiguration;
         }
 
+        public boolean isVerifyHostname() {
+            return verifyHostname;
+        }
+
         public B setUrl(final String url) {
             this.url = url;
             return asBuilder();
@@ -126,6 +133,11 @@ public final class HttpAppender extends AbstractAppender {
             this.sslConfiguration = sslConfiguration;
             return asBuilder();
         }
+
+        public B setVerifyHostname(boolean verifyHostname) {
+            this.verifyHostname = verifyHostname;
+            return asBuilder();
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c10f781/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
index de9225c..a47684e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
@@ -34,6 +34,7 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
 import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
 import org.apache.logging.log4j.core.util.IOUtils;
 
@@ -47,13 +48,16 @@ public class HttpURLConnectionManager extends HttpManager {
     private final int readTimeoutMillis;
     private final Property[] headers;
     private final SslConfiguration sslConfiguration;
+    private final boolean verifyHostname;
 
     public HttpURLConnectionManager(final Configuration configuration, LoggerContext loggerContext, final String name,
                                     final String url, final String method, final int connectTimeoutMillis,
                                     final int readTimeoutMillis,
                                     final Property[] headers,
-                                    SslConfiguration sslConfiguration) {
+                                    SslConfiguration sslConfiguration,
+                                    boolean verifyHostname) {
         super(configuration, loggerContext, name);
+        this.verifyHostname = verifyHostname;
         try {
             this.url = new URL(url);
         } catch (MalformedURLException e) {
@@ -67,6 +71,9 @@ public class HttpURLConnectionManager extends HttpManager {
         if (this.sslConfiguration != null && !this.url.getProtocol().equalsIgnoreCase("https")) {
             throw new ConfigurationException("SSL configuration can only be specified with URL scheme https");
         }
+        if (!this.verifyHostname && !this.url.getProtocol().equalsIgnoreCase("https")) {
+            throw new ConfigurationException("verifyHostname=false can only be specified with URL scheme https");
+        }
     }
 
     @Override
@@ -87,6 +94,9 @@ public class HttpURLConnectionManager extends HttpManager {
         if (sslConfiguration != null) {
             ((HttpsURLConnection)urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
         }
+        if (!verifyHostname) {
+            ((HttpsURLConnection)urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
+        }
 
         byte[] msg = layout.toByteArray(event);
         urlConnection.setFixedLengthStreamingMode(msg.length);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c10f781/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/LaxHostnameVerifier.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/LaxHostnameVerifier.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/LaxHostnameVerifier.java
new file mode 100644
index 0000000..2431cde
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/LaxHostnameVerifier.java
@@ -0,0 +1,38 @@
+/*
+ * 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 javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSession;
+
+/**
+ * An HostnameVerifier which accepts everything.
+ */
+public final class LaxHostnameVerifier implements HostnameVerifier {
+    /**
+     * Singleton instance.
+     */
+    public static final HostnameVerifier INSTANCE = new LaxHostnameVerifier();
+
+    private LaxHostnameVerifier() {
+    }
+
+    @Override
+    public boolean verify(String s, SSLSession sslSession) {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c10f781/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
index 3f55adc..419d340 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -13,6 +13,7 @@ import org.apache.logging.log4j.core.lookup.JavaLookup;
 import org.apache.logging.log4j.core.net.ssl.KeyStoreConfiguration;
 import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
 import org.apache.logging.log4j.core.net.ssl.TestConstants;
+import org.apache.logging.log4j.core.net.ssl.TrustStoreConfiguration;
 import org.apache.logging.log4j.junit.LoggerContextRule;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.status.StatusData;
@@ -86,9 +87,10 @@ public class HttpAppenderTest {
             .withLayout(JsonLayout.createDefaultLayout())
             .setConfiguration(ctx.getConfiguration())
             .setUrl("https://localhost:" + wireMockRule.httpsPort() + "/test/log4j/")
-            .setSslConfiguration(SslConfiguration.createSSLConfiguration("TLS",
+            .setSslConfiguration(SslConfiguration.createSSLConfiguration(null,
                 KeyStoreConfiguration.createKeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD, TestConstants.KEYSTORE_TYPE, null),
-                null))
+                TrustStoreConfiguration.createKeyStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD, TestConstants.TRUSTSTORE_TYPE, null)))
+            .setVerifyHostname(false)
             .build();
         appender.append(createLogEvent());
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8c10f781/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index f26dd35..60a3e96 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1584,6 +1584,12 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
                   Optional, uses Java runtime defaults if not specified.</td>
             </tr>
             <tr>
+              <td>verifyHostname</td>
+              <td>boolean</td>
+              <td>Whether to verify server hostname against certificate. Only valid for https.
+                  Optional, defaults to true</td>
+            </tr>
+            <tr>
               <td>url</td>
               <td>string</td>
               <td>The URL to use. The URL scheme must be "http" or "https".</td>


[10/14] logging-log4j2 git commit: Https support (W.I.P.)

Posted by mi...@apache.org.
Https support (W.I.P.)


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/93ac8ab8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/93ac8ab8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/93ac8ab8

Branch: refs/heads/master
Commit: 93ac8ab82037ea77eee5e99cd3e6b26b0ea1ad95
Parents: 42dcb45
Author: Mikael Ståldal <mi...@magine.com>
Authored: Mon May 22 18:02:13 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Mon May 22 18:02:13 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/appender/HttpAppender.java       | 15 +++++++++-
 .../core/appender/HttpURLConnectionManager.java | 17 +++++++++--
 .../log4j/core/appender/HttpAppenderTest.java   | 31 ++++++++++++++++++--
 3 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/93ac8ab8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
index c43c63d..efc9942 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
@@ -32,6 +32,7 @@ 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.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
 
 /**
  * Sends log events over HTTP.
@@ -62,10 +63,13 @@ public final class HttpAppender extends AbstractAppender {
         @PluginElement("Headers")
         private Property[] headers;
 
+        @PluginElement("SslConfiguration")
+        private SslConfiguration sslConfiguration;
+
         @Override
         public HttpAppender build() {
             final HttpManager httpManager = new HttpURLConnectionManager(getConfiguration(), getConfiguration().getLoggerContext(),
-                getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers);
+                getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers, sslConfiguration);
             return new HttpAppender(getName(), getLayout(), getFilter(), isIgnoreExceptions(), httpManager);
         }
 
@@ -89,6 +93,10 @@ public final class HttpAppender extends AbstractAppender {
             return headers;
         }
 
+        public SslConfiguration getSslConfiguration() {
+            return sslConfiguration;
+        }
+
         public B setUrl(final String url) {
             this.url = url;
             return asBuilder();
@@ -113,6 +121,11 @@ public final class HttpAppender extends AbstractAppender {
             this.headers = headers;
             return asBuilder();
         }
+
+        public B setSslConfiguration(final SslConfiguration sslConfiguration) {
+            this.sslConfiguration = sslConfiguration;
+            return asBuilder();
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/93ac8ab8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
index d656c90..de9225c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
@@ -26,12 +26,15 @@ import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.Objects;
 
+import javax.net.ssl.HttpsURLConnection;
+
 import org.apache.logging.log4j.core.Layout;
 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.ConfigurationException;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
 import org.apache.logging.log4j.core.util.IOUtils;
 
 public class HttpURLConnectionManager extends HttpManager {
@@ -43,10 +46,13 @@ public class HttpURLConnectionManager extends HttpManager {
     private final int connectTimeoutMillis;
     private final int readTimeoutMillis;
     private final Property[] headers;
+    private final SslConfiguration sslConfiguration;
 
     public HttpURLConnectionManager(final Configuration configuration, LoggerContext loggerContext, final String name,
-                                    final String url, final String method, final int connectTimeoutMillis, final int readTimeoutMillis,
-                                    final Property[] headers) {
+                                    final String url, final String method, final int connectTimeoutMillis,
+                                    final int readTimeoutMillis,
+                                    final Property[] headers,
+                                    SslConfiguration sslConfiguration) {
         super(configuration, loggerContext, name);
         try {
             this.url = new URL(url);
@@ -57,6 +63,10 @@ public class HttpURLConnectionManager extends HttpManager {
         this.connectTimeoutMillis = connectTimeoutMillis;
         this.readTimeoutMillis = readTimeoutMillis;
         this.headers = headers != null ? headers : new Property[0];
+        this.sslConfiguration = sslConfiguration;
+        if (this.sslConfiguration != null && !this.url.getProtocol().equalsIgnoreCase("https")) {
+            throw new ConfigurationException("SSL configuration can only be specified with URL scheme https");
+        }
     }
 
     @Override
@@ -74,6 +84,9 @@ public class HttpURLConnectionManager extends HttpManager {
                 header.getName(),
                 header.isValueNeedsLookup() ? getConfiguration().getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
         }
+        if (sslConfiguration != null) {
+            ((HttpsURLConnection)urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+        }
 
         byte[] msg = layout.toByteArray(event);
         urlConnection.setFixedLengthStreamingMode(msg.length);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/93ac8ab8/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
index c9f9385..9ce31e0 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java
@@ -10,6 +10,9 @@ import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.layout.JsonLayout;
 import org.apache.logging.log4j.core.lookup.JavaLookup;
+import org.apache.logging.log4j.core.net.ssl.KeyStoreConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.TestConstants;
 import org.apache.logging.log4j.junit.LoggerContextRule;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.status.StatusData;
@@ -22,7 +25,6 @@ import static org.junit.Assert.*;
 import static com.github.tomakehurst.wiremock.client.WireMock.*;
 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
 
-// TODO test HTTPS
 public class HttpAppenderTest {
 
     private static final String LOG_MESSAGE = "Hello, world!";
@@ -50,7 +52,10 @@ public class HttpAppenderTest {
     public LoggerContextRule ctx = new LoggerContextRule("HttpAppenderTest.xml");
 
     @Rule
-    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort().dynamicHttpsPort()
+        .keystorePath(TestConstants.KEYSTORE_FILE)
+        .keystorePassword(TestConstants.KEYSTORE_PWD)
+        .keystoreType(TestConstants.KEYSTORE_TYPE));
 
     @Test
     public void testAppend() throws Exception {
@@ -72,6 +77,28 @@ public class HttpAppenderTest {
     }
 
     @Test
+    public void testAppendHttps() throws Exception {
+        wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
+            .willReturn(SUCCESS_RESPONSE));
+
+        final Appender appender = HttpAppender.newBuilder()
+            .withName("Http")
+            .withLayout(JsonLayout.createDefaultLayout())
+            .setConfiguration(ctx.getConfiguration())
+            .setUrl("https://localhost:"+wireMockRule.httpsPort()+"/test/log4j/")
+            .setSslConfiguration(SslConfiguration.createSSLConfiguration("TLS",
+                KeyStoreConfiguration.createKeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD, TestConstants.KEYSTORE_TYPE, null),
+                null))
+            .build();
+        appender.append(createLogEvent());
+
+        wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
+            .withHeader("Host", containing("localhost"))
+            .withHeader("Content-Type", containing("application/json"))
+            .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
+    }
+
+    @Test
     public void testAppendMethodPut() throws Exception {
         wireMockRule.stubFor(put(urlEqualTo("/test/log4j/1234"))
             .willReturn(SUCCESS_RESPONSE));


[09/14] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1442

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1442

# Conflicts:
#	src/changes/changes.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/42dcb458
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/42dcb458
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/42dcb458

Branch: refs/heads/master
Commit: 42dcb4588d79016b7906737ab66603ce9c27f968
Parents: 2959f19 92e4b87
Author: Mikael Ståldal <mi...@magine.com>
Authored: Mon May 22 13:47:58 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Mon May 22 13:47:58 2017 +0200

----------------------------------------------------------------------
 log4j-api/pom.xml                               | 23 ++++--
 .../org/apache/logging/log4j/spi/Provider.java  | 73 +++++++++++++++++---
 .../apache/logging/log4j/util/Activator.java    |  4 +-
 .../logging/log4j/util/ClassNamePredicate.java  | 45 ------------
 .../logging/log4j/util/ClassPredicate.java      | 46 ------------
 .../apache/logging/log4j/util/ProviderUtil.java | 11 +++
 .../log4j/util/StackWalkerStackLocator.java     | 63 -----------------
 .../logging/log4j/util/ClassNamePredicate.java  | 45 ++++++++++++
 .../logging/log4j/util/ClassPredicate.java      | 46 ++++++++++++
 .../log4j/util/StackWalkerStackLocator.java     | 63 +++++++++++++++++
 .../org/apache/logging/log4j/TestProvider.java  | 28 ++++++++
 .../META-INF/log4j-provider.properties          |  3 -
 .../org.apache.logging.log4j.spi.Provider       |  1 +
 .../logging/log4j/core/impl/Log4jProvider.java  | 28 ++++++++
 .../META-INF/log4j-provider.properties          | 18 -----
 .../org.apache.logging.log4j.spi.Provider       |  1 +
 .../appender/AsyncAppenderNoLocationTest.java   | 20 +++++-
 .../org/apache/logging/slf4j/SLF4JProvider.java | 28 ++++++++
 .../META-INF/log4j-provider.properties          | 19 -----
 .../org.apache.logging.log4j.spi.Provider       |  1 +
 pom.xml                                         |  2 +-
 src/changes/changes.xml                         |  3 +
 src/site/xdoc/manual/extending.xml              | 37 ++++++----
 23 files changed, 379 insertions(+), 229 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/42dcb458/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/42dcb458/src/changes/changes.xml
----------------------------------------------------------------------
diff --cc src/changes/changes.xml
index 8dc14f1,db263d1..063b229
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@@ -31,9 -31,9 +31,12 @@@
           - "remove" - Removed
      -->
      <release version="2.9.0" date="2017-MM-DD" description="GA Release 2.9.0">
 +      <action issue="LOG4J2-1442" dev="mikes" type="add">
 +        Generic HTTP appender.
 +      </action>
+       <action issue="LOG4J2-1917" dev="rgoers" type="update">
+         Support using java.util.ServiceLoader to locate Log4j 2 API providers.
+       </action>
        <action issue="LOG4J2-1854" dev="mikes" type="add" due-to="Xavier Jodoin">
          Support null byte delimiter in GelfLayout.
        </action>


[07/14] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1442

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1442


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9caf597d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9caf597d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9caf597d

Branch: refs/heads/master
Commit: 9caf597d1dc08b7bb64e0b6f5a128ddf18684fdb
Parents: bcb7264 f78adaa
Author: Mikael Ståldal <mi...@magine.com>
Authored: Mon May 15 16:21:42 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Mon May 15 16:21:42 2017 +0200

----------------------------------------------------------------------
 .../appender/SecureSocketAppenderSocketOptionsTest.java  | 11 ++++++++++-
 .../core/appender/SocketAppenderSocketOptionsTest.java   | 11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[04/14] logging-log4j2 git commit: HttpManager as facade to enable multiple implementations

Posted by mi...@apache.org.
HttpManager as facade to enable multiple implementations


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fd1d7ea2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fd1d7ea2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fd1d7ea2

Branch: refs/heads/master
Commit: fd1d7ea204df40bd079750b2c2f4df4047afa2fe
Parents: 857c3e1
Author: Mikael Ståldal <mi...@magine.com>
Authored: Thu May 4 17:53:37 2017 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Thu May 4 17:53:37 2017 +0200

----------------------------------------------------------------------
 .../log4j/core/appender/HttpAppender.java       |  9 ++-
 .../log4j/core/appender/HttpManager.java        | 56 +++-----------
 .../core/appender/HttpURLConnectionManager.java | 81 ++++++++++++++++++++
 3 files changed, 97 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd1d7ea2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
index e0f1b27..c43c63d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpAppender.java
@@ -17,7 +17,6 @@
 
 package org.apache.logging.log4j.core.appender;
 
-import java.io.IOException;
 import java.io.Serializable;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
@@ -65,7 +64,7 @@ public final class HttpAppender extends AbstractAppender {
 
         @Override
         public HttpAppender build() {
-            final HttpManager httpManager = new HttpManager(getConfiguration(), getConfiguration().getLoggerContext(),
+            final HttpManager httpManager = new HttpURLConnectionManager(getConfiguration(), getConfiguration().getLoggerContext(),
                 getName(), url, method, connectTimeoutMillis, readTimeoutMillis, headers);
             return new HttpAppender(getName(), getLayout(), getFilter(), isIgnoreExceptions(), httpManager);
         }
@@ -134,6 +133,12 @@ public final class HttpAppender extends AbstractAppender {
     }
 
     @Override
+    public void start() {
+        super.start();
+        manager.startup();
+    }
+
+    @Override
     public void append(final LogEvent event) {
         try {
             manager.send(getLayout(), event);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd1d7ea2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
index 8f69659..dc3d218 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpManager.java
@@ -17,66 +17,28 @@
 
 package org.apache.logging.log4j.core.appender;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.Objects;
 
 import org.apache.logging.log4j.core.Layout;
 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.ConfigurationException;
-import org.apache.logging.log4j.core.config.Property;
-
-public class HttpManager extends AbstractManager {
 
+public abstract class HttpManager extends AbstractManager {
     private final Configuration configuration;
-    private final URL url;
-    private final String method;
-    private final int connectTimeoutMillis;
-    private final int readTimeoutMillis;
-    private final Property[] headers;
 
-    public HttpManager(final Configuration configuration, LoggerContext loggerContext, final String name,
-                       final String url, final String method, final int connectTimeoutMillis, final int readTimeoutMillis,
-                       final Property[] headers) {
+    protected HttpManager(final Configuration configuration, final LoggerContext loggerContext, final String name) {
         super(loggerContext, name);
         this.configuration = Objects.requireNonNull(configuration);
-        try {
-            this.url = new URL(url);
-        } catch (MalformedURLException e) {
-            throw new ConfigurationException(e);
-        }
-        this.method = Objects.requireNonNull(method, "method");
-        this.connectTimeoutMillis = connectTimeoutMillis;
-        this.readTimeoutMillis = readTimeoutMillis;
-        this.headers = headers != null ? headers : new Property[0];
     }
 
-    public void send(final Layout<?> layout, final LogEvent event) throws IOException {
-        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
-        urlConnection.setAllowUserInteraction(false);
-        urlConnection.setDoOutput(true);
-        urlConnection.setDoInput(true);
-        urlConnection.setRequestMethod(method);
-        if (connectTimeoutMillis > 0) urlConnection.setConnectTimeout(connectTimeoutMillis);
-        if (readTimeoutMillis > 0) urlConnection.setReadTimeout(readTimeoutMillis);
-        if (layout.getContentType() != null) urlConnection.setRequestProperty("Content-Type", layout.getContentType());
-        for (Property header : headers) {
-            urlConnection.setRequestProperty(
-                header.getName(),
-                header.isValueNeedsLookup() ? configuration.getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
-        }
-        byte[] msg = layout.toByteArray(event);
-        urlConnection.setFixedLengthStreamingMode(msg.length);
-        urlConnection.connect();
-        try (OutputStream os = urlConnection.getOutputStream()) {
-            os.write(msg);
-        }
-        urlConnection.getInputStream().close();
+    public Configuration getConfiguration() {
+        return configuration;
+    }
+
+    public void startup() {
+        // This default implementation does nothing
     }
 
+    public abstract void send(Layout<?> layout, LogEvent event) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd1d7ea2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
new file mode 100644
index 0000000..357c5b7
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/HttpURLConnectionManager.java
@@ -0,0 +1,81 @@
+/*
+ * 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 java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Objects;
+
+import org.apache.logging.log4j.core.Layout;
+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.ConfigurationException;
+import org.apache.logging.log4j.core.config.Property;
+
+public class HttpURLConnectionManager extends HttpManager {
+
+    private final URL url;
+    private final String method;
+    private final int connectTimeoutMillis;
+    private final int readTimeoutMillis;
+    private final Property[] headers;
+
+    public HttpURLConnectionManager(final Configuration configuration, LoggerContext loggerContext, final String name,
+                                    final String url, final String method, final int connectTimeoutMillis, final int readTimeoutMillis,
+                                    final Property[] headers) {
+        super(configuration, loggerContext, name);
+        try {
+            this.url = new URL(url);
+        } catch (MalformedURLException e) {
+            throw new ConfigurationException(e);
+        }
+        this.method = Objects.requireNonNull(method, "method");
+        this.connectTimeoutMillis = connectTimeoutMillis;
+        this.readTimeoutMillis = readTimeoutMillis;
+        this.headers = headers != null ? headers : new Property[0];
+    }
+
+    @Override
+    public void send(final Layout<?> layout, final LogEvent event) throws IOException {
+        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
+        urlConnection.setAllowUserInteraction(false);
+        urlConnection.setDoOutput(true);
+        urlConnection.setDoInput(true);
+        urlConnection.setRequestMethod(method);
+        if (connectTimeoutMillis > 0) urlConnection.setConnectTimeout(connectTimeoutMillis);
+        if (readTimeoutMillis > 0) urlConnection.setReadTimeout(readTimeoutMillis);
+        if (layout.getContentType() != null) urlConnection.setRequestProperty("Content-Type", layout.getContentType());
+        for (Property header : headers) {
+            urlConnection.setRequestProperty(
+                header.getName(),
+                header.isValueNeedsLookup() ? getConfiguration().getStrSubstitutor().replace(event, header.getValue()) : header.getValue());
+        }
+        byte[] msg = layout.toByteArray(event);
+        urlConnection.setFixedLengthStreamingMode(msg.length);
+        urlConnection.connect();
+        try (OutputStream os = urlConnection.getOutputStream()) {
+            os.write(msg);
+        }
+        urlConnection.getInputStream().close();
+    }
+
+}


[12/14] logging-log4j2 git commit: LOG4J2-1442 Documentation

Posted by mi...@apache.org.
LOG4J2-1442 Documentation


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9b26bbe5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9b26bbe5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9b26bbe5

Branch: refs/heads/master
Commit: 9b26bbe57655c045f819142527056d578c9633e4
Parents: b12c25c
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Mon May 22 21:12:45 2017 +0200
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Mon May 22 21:12:45 2017 +0200

----------------------------------------------------------------------
 src/site/xdoc/manual/appenders.xml | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9b26bbe5/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index add1e52..f26dd35 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1547,6 +1547,13 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
             Will set the <code>Content-Type</code> header according to the layout. Additional headers can be specified
             with embedded Property elements.
           </p>
+          <p>
+            Will wait for response from server, and throw error if no 2xx response is received.
+          </p>
+          <p>
+            Implemented with
+            <a href="https://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html">HttpURLConnection</a>.
+          </p>
           <table>
             <caption align="top">HttpAppender Parameters</caption>
             <tr>
@@ -1571,6 +1578,12 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
               <td>The Layout to use to format the LogEvent.</td>
             </tr>
             <tr>
+              <td>Ssl</td>
+              <td>SslConfiguration</td>
+              <td>Contains the configuration for the KeyStore and TrustStore for https.
+                  Optional, uses Java runtime defaults if not specified.</td>
+            </tr>
+            <tr>
               <td>url</td>
               <td>string</td>
               <td>The URL to use. The URL scheme must be "http" or "https".</td>
@@ -1610,9 +1623,13 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
           <pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
   ...
   <Appenders>
-    <Http name="Http" url="http://localhost:9200/test/log4j/">
+    <Http name="Http" url="https://localhost:9200/test/log4j/">
       <Property name="X-Java-Runtime" value="$${java:runtime}" />
       <JsonLayout properties="true"/>
+      <Ssl>
+        <KeyStore location="log4j2-keystore.jks" password="changeme"/>
+        <TrustStore location="truststore.jks" password="changeme"/>
+      </Ssl>
     </Http>
   </Appenders>]]></pre>
         </subsection>