[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-04 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253682942
 
 

 ##
 File path: 
log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java
 ##
 @@ -0,0 +1,127 @@
+/*
+ * 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.spring.cloud.config.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.springframework.boot.logging.LogFile;
+import org.springframework.boot.logging.LoggingInitializationContext;
+import org.springframework.boot.logging.log4j2.Log4J2LoggingSystem;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
+
+/**
+ *
+ */
+public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
+private static final String FILE_PROTOCOL = "file";
+private static final String HTTPS = "https";
+private Logger LOGGER = StatusLogger.getLogger();
+
+public Log4j2CloudConfigLoggingSystem(ClassLoader loader) {
+super(loader);
+}
+
+@Override
+protected String[] getStandardConfigLocations() {
+String[] locations = super.getStandardConfigLocations();
+PropertiesUtil props = new PropertiesUtil(new Properties());
+String location = 
props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+if (location != null) {
+List list = 
Arrays.asList(super.getStandardConfigLocations());
+list.add(location);
+locations = list.toArray(new String[list.size()]);
 
 Review comment:
   You must be thinking of a different method. The javadoc for this says 
"Returns a fixed-size list backed by the specified array. (Changes to the 
returned list "write through" to the array.)". Looking at the implementation 
that is exactly what it does. Passing an array of size 0 would require me to 
manually populate the list from the array, which is the whole point of this 
method.
   
   Actually, I think you are thinking of ArrayList's toArray() method.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-04 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253682942
 
 

 ##
 File path: 
log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java
 ##
 @@ -0,0 +1,127 @@
+/*
+ * 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.spring.cloud.config.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.springframework.boot.logging.LogFile;
+import org.springframework.boot.logging.LoggingInitializationContext;
+import org.springframework.boot.logging.log4j2.Log4J2LoggingSystem;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
+
+/**
+ *
+ */
+public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
+private static final String FILE_PROTOCOL = "file";
+private static final String HTTPS = "https";
+private Logger LOGGER = StatusLogger.getLogger();
+
+public Log4j2CloudConfigLoggingSystem(ClassLoader loader) {
+super(loader);
+}
+
+@Override
+protected String[] getStandardConfigLocations() {
+String[] locations = super.getStandardConfigLocations();
+PropertiesUtil props = new PropertiesUtil(new Properties());
+String location = 
props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+if (location != null) {
+List list = 
Arrays.asList(super.getStandardConfigLocations());
+list.add(location);
+locations = list.toArray(new String[list.size()]);
 
 Review comment:
   You must be thinking of a different method. The javadoc for this says 
"Returns a fixed-size list backed by the specified array. (Changes to the 
returned list "write through" to the array.)". Looking at the implementation 
that is exactly what it does. Passing an array of size 0 would require me to 
manually populate the list from the array, which is the whole point of this 
method.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253350097
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatcherFactory.java
 ##
 @@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
+import org.apache.logging.log4j.core.config.plugins.util.PluginType;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * Creates Watchers of various types.
+ */
+public class WatcherFactory {
+
+private static Logger LOGGER = StatusLogger.getLogger();
+private static PluginManager pluginManager = new 
PluginManager(Watcher.CATEGORY);
+
+private static volatile WatcherFactory factory = null;
+
+private final Map> plugins;
+
+private WatcherFactory(List packages) {
+pluginManager.collectPlugins(packages);
+plugins = pluginManager.getPlugins();
+}
+
+public static WatcherFactory getInstance(List packages) {
+if (factory == null) {
+synchronized(pluginManager) {
+if (factory == null) {
+factory = new WatcherFactory(packages);
+}
+}
+}
+return factory;
+}
+
+@SuppressWarnings("unchecked")
+public Watcher newWatcher(Source source, final Configuration 
configuration, final Reconfigurable reconfigurable,
+final List configurationListeners, long 
lastModifiedMillis) {
+if (source.getFile() != null) {
+return new ConfigurationFileWatcher(configuration, reconfigurable, 
configurationListeners,
+lastModifiedMillis);
+} else {
+String name = source.getURI().getScheme();
+PluginType pluginType = plugins.get(name);
+if (pluginType != null) {
+return instantiate(name, (Class) 
pluginType.getPluginClass(),
+configuration, reconfigurable, configurationListeners, 
lastModifiedMillis);
+}
+LOGGER.info("No Watcher plugin is available for protocol '{}'", 
name);
+return null;
+}
+}
+
+@SuppressWarnings("unchecked")
+public static  T instantiate(String name, final 
Class clazz, final Configuration configuration,
+final Reconfigurable reconfigurable, final List 
listeners, long lastModifiedMillis) {
+Objects.requireNonNull(clazz, "No class provided");
+try {
+Constructor constructor = 
clazz.getConstructor(Configuration.class, Reconfigurable.class, List.class, 
long.class);
 
 Review comment:
   Good catch. I'll make that change.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349779
 
 

 ##
 File path: 
log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java
 ##
 @@ -0,0 +1,127 @@
+/*
+ * 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.spring.cloud.config.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.springframework.boot.logging.LogFile;
+import org.springframework.boot.logging.LoggingInitializationContext;
+import org.springframework.boot.logging.log4j2.Log4J2LoggingSystem;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
+
+/**
+ *
+ */
+public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
+private static final String FILE_PROTOCOL = "file";
+private static final String HTTPS = "https";
+private Logger LOGGER = StatusLogger.getLogger();
+
+public Log4j2CloudConfigLoggingSystem(ClassLoader loader) {
+super(loader);
+}
+
+@Override
+protected String[] getStandardConfigLocations() {
+String[] locations = super.getStandardConfigLocations();
+PropertiesUtil props = new PropertiesUtil(new Properties());
+String location = 
props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+if (location != null) {
+List list = 
Arrays.asList(super.getStandardConfigLocations());
+list.add(location);
+locations = list.toArray(new String[list.size()]);
 
 Review comment:
   I had always thought that if you pass in an array that toArray would just 
use it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349683
 
 

 ##
 File path: 
log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/java/org/apache/logging/log4j/spring/cloud/config/server/controller/Log4jResourceController.java
 ##
 @@ -0,0 +1,200 @@
+/*
+ * Copyright 2015-2016 the original author or authors.
+ *
+ * Licensed 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.spring.cloud.config.server.controller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.config.environment.Environment;
+import 
org.springframework.cloud.config.server.environment.EnvironmentRepository;
+import 
org.springframework.cloud.config.server.resource.NoSuchResourceException;
+import org.springframework.cloud.config.server.resource.ResourceRepository;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.ServletWebRequest;
+import org.springframework.web.util.UrlPathHelper;
+
+import static 
org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment;
+import static 
org.springframework.cloud.config.server.support.EnvironmentPropertySource.resolvePlaceholders;
+
+/**
+ * Modified version of Spring Cloud Config's ResourceController to support 
If-Modified-Since.
+ * Should be dropeed when Spring implements this.
+ *
+ * An HTTP endpoint for serving up templated plain text resources from an 
underlying
+ * repository. Can be used to supply config files for consumption by a wide 
variety of
+ * applications and services. A {@link ResourceRepository} is used to locate a
+ * {@link Resource}, specific to an application, and the contents are 
transformed to text.
+ * Then an {@link EnvironmentRepository} is used to supply key-value pairs 
which are used
+ * to replace placeholders in the resource text.
+ *
+ * @author Dave Syer
+ * @author Daniel Lavoie
+ *
+ */
+@RestController
+@RequestMapping(method = RequestMethod.GET, path = 
"${spring.cloud.config.server.prefix:}/resource")
+public class Log4jResourceController {
+
+@Autowired
+   private ResourceRepository resourceRepository;
 
 Review comment:
   This file was acquired from Spring. They use tabs. I'll reformat it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349622
 
 

 ##
 File path: 
log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchHttpTest.java
 ##
 @@ -0,0 +1,175 @@
+/*
+ * 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.util;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Queue;
+import java.util.TimeZone;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.ConfigurationScheduler;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.HttpWatcher;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+import org.apache.logging.log4j.core.net.ssl.TestConstants;
+import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.stubbing.StubMapping;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.removeStub;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test the WatchManager
+ */
+public class WatchHttpTest {
+
+private static final String FORCE_RUN_KEY = 
WatchHttpTest.class.getSimpleName() + ".forceRun";
+private final String file = "log4j-test1.xml";
+private static FastDateFormat formatter;
+private static final String XML = "application/xml";
+
+private static final boolean IS_WINDOWS = 
PropertiesUtil.getProperties().isOsWindows();
+
+@BeforeClass
+public static void beforeClass() {
+try {
+formatter = FastDateFormat.getInstance("EEE, dd MMM  
HH:mm:ss", TimeZone.getTimeZone("UTC"));
+} catch (Exception ex) {
+System.err.println("Unable to create date format.");
+ex.printStackTrace();
+throw ex;
+}
+}
+
+@Rule
+public WireMockRule wireMockRule = new 
WireMockRule(wireMockConfig().dynamicPort().dynamicHttpsPort()
+.keystorePath(TestConstants.KEYSTORE_FILE)
+.keystorePassword(String.valueOf(TestConstants.KEYSTORE_PWD()))
+.keystoreType(TestConstants.KEYSTORE_TYPE));
+
+@Test
+public void testWatchManager() throws Exception {
+BlockingQueue queue = new LinkedBlockingQueue<>();
+List listeners = new ArrayList<>();
+listeners.add(new TestConfigurationListener(queue, "log4j-test1.xml"));
+TimeZone timeZone = TimeZone.getTimeZone("UTC");
+Calendar now = Calendar.getInstance(timeZone);
+Calendar previous = now;
+previous.add(Calendar.MINUTE, -5);
+Configuration configuration = new DefaultConfiguration();
+Assume.assumeTrue(!IS_WINDOWS || Boolean.getBoolean(FORCE_RUN_KEY));
+URL url = new URL("http://localhost:; + wireMockRule.port() + 
"/log4j-test1.xml");
+StubMapping stubMapping = 
stubFor(get(urlPathEqualTo("/log4j-test1.xml"))
+.willReturn(aResponse()
+.withBodyFile(file)
+.withStatus(200)
+.withHeader("Last-Modified", formatter.format(previous) + " GMT")
+.withHeader("Content-Type", XML)));
+   

[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349792
 
 

 ##
 File path: 
log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/java/org/apache/logging/log4j/spring/cloud/config/server/controller/Log4jResourceController.java
 ##
 @@ -0,0 +1,200 @@
+/*
+ * Copyright 2015-2016 the original author or authors.
+ *
+ * Licensed 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.spring.cloud.config.server.controller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.config.environment.Environment;
+import 
org.springframework.cloud.config.server.environment.EnvironmentRepository;
+import 
org.springframework.cloud.config.server.resource.NoSuchResourceException;
+import org.springframework.cloud.config.server.resource.ResourceRepository;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.ServletWebRequest;
+import org.springframework.web.util.UrlPathHelper;
+
+import static 
org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment;
+import static 
org.springframework.cloud.config.server.support.EnvironmentPropertySource.resolvePlaceholders;
+
+/**
+ * Modified version of Spring Cloud Config's ResourceController to support 
If-Modified-Since.
+ * Should be dropeed when Spring implements this.
+ *
+ * An HTTP endpoint for serving up templated plain text resources from an 
underlying
+ * repository. Can be used to supply config files for consumption by a wide 
variety of
+ * applications and services. A {@link ResourceRepository} is used to locate a
+ * {@link Resource}, specific to an application, and the contents are 
transformed to text.
+ * Then an {@link EnvironmentRepository} is used to supply key-value pairs 
which are used
+ * to replace placeholders in the resource text.
+ *
+ * @author Dave Syer
+ * @author Daniel Lavoie
+ *
+ */
+@RestController
+@RequestMapping(method = RequestMethod.GET, path = 
"${spring.cloud.config.server.prefix:}/resource")
+public class Log4jResourceController {
+
+@Autowired
+   private ResourceRepository resourceRepository;
+
+@Autowired
+   private EnvironmentRepository environmentRepository;
+
+   private UrlPathHelper helper = new UrlPathHelper();
+
+   public Log4jResourceController(ResourceRepository resourceRepository,
+   EnvironmentRepository environmentRepository) {
+   this.resourceRepository = resourceRepository;
+   this.environmentRepository = environmentRepository;
+   this.helper.setAlwaysUseFullPath(true);
+   }
+
+   @RequestMapping("/{name}/{profile}/{label}/**")
+   public String retrieve(@PathVariable String name, @PathVariable String 
profile,
+   @PathVariable String label, ServletWebRequest request,
+@RequestParam(defaultValue = "true") boolean resolvePlaceholders)
+   throws IOException {
+   String path = getFilePath(request, name, profile, label);
+   return retrieve(request, name, profile, label, path, 
resolvePlaceholders);
+   }
+
+   @RequestMapping(value = "/{name}/{profile}/**", params = 
"useDefaultLabel")
+   public String retrieve(@PathVariable String name, @PathVariable String 
profile,
+   ServletWebRequest request, @RequestParam(defaultValue = 
"true") boolean resolvePlaceholders)
+   throws IOException {
+   String path = getFilePath(request, name, profile, null);
+   return 

[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349578
 
 

 ##
 File path: 
log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchHttpTest.java
 ##
 @@ -0,0 +1,175 @@
+/*
+ * 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.util;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Queue;
+import java.util.TimeZone;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.ConfigurationScheduler;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.HttpWatcher;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+import org.apache.logging.log4j.core.net.ssl.TestConstants;
+import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.stubbing.StubMapping;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.removeStub;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static 
com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test the WatchManager
+ */
+public class WatchHttpTest {
+
+private static final String FORCE_RUN_KEY = 
WatchHttpTest.class.getSimpleName() + ".forceRun";
+private final String file = "log4j-test1.xml";
+private static FastDateFormat formatter;
+private static final String XML = "application/xml";
+
+private static final boolean IS_WINDOWS = 
PropertiesUtil.getProperties().isOsWindows();
+
+@BeforeClass
+public static void beforeClass() {
+try {
+formatter = FastDateFormat.getInstance("EEE, dd MMM  
HH:mm:ss", TimeZone.getTimeZone("UTC"));
+} catch (Exception ex) {
+System.err.println("Unable to create date format.");
 
 Review comment:
   It is just a unit test. I am not sure what using LowLevelLogUtil would gain 
me here.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349447
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/util/Watcher.java
 ##
 @@ -0,0 +1,78 @@
+/*
+ * 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.util;
+
+import java.util.List;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+
+/**
+ * Watches for changes in a Source and performs an action when it is modified.
+ *
+ * @see WatchManager
+ */
+public interface Watcher {
+
+public static final String CATEGORY = "Watcher";
 
 Review comment:
   Fixed


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349431
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
 ##
 @@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.net.ssl;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+/**
+ * Creates an SSL configuration from Log4j properties.
+ */
+public class SslConfigurationFactory {
+
+private static final Logger LOGGER = StatusLogger.getLogger();
+private static SslConfiguration sslConfiguration = null;
+
+private static final String trustStorelocation = 
"log4j2.trustStore.location";
+private static final String trustStorePassword = 
"log4j2.trustStore.password";
 
 Review comment:
   Fixed


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349281
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
 ##
 @@ -79,6 +98,24 @@ public ConfigurationSource(final InputStream stream, final 
URL url) {
 this.location = url.toString();
 this.file = null;
 this.data = null;
+this.lastModified = 0;
+}
+
+/**
+ * Constructs a new {@code ConfigurationSource} with the specified input 
stream that originated from the specified
+ * url.
+ *
+ * @param stream the input stream
+ * @param url the URL where the input stream originated
+ * @param lastModified when the source was last modified.
+ */
+public ConfigurationSource(final InputStream stream, final URL url, long 
lastModified) {
 
 Review comment:
   Good luck with that. All this information has to be passed from one 
configuration to another to allow reconfiguration to occur.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349408
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/config/HttpWatcher.java
 ##
 @@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.config;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.AbstractWatcher;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+/**
+ *
+ */
+@Plugin(name = "http", category = Watcher.CATEGORY, printObject = true)
+@PluginAliases("https")
+public class HttpWatcher extends AbstractWatcher {
+
+private Logger LOGGER = StatusLogger.getLogger();
+
+private static int DEFAULT_TIMEOUT = 6;
+private int connectTimeoutMillis = DEFAULT_TIMEOUT;
+private int readTimeoutMillis = DEFAULT_TIMEOUT;
+private SslConfiguration sslConfiguration;
+private URL url;
+private volatile long lastModifiedMillis;
+private static final String JSON = "application/json";
+private static final String XML = "application/xml";
+private static final String PROPERTIES = "text/x-java-properties";
+private static final String TEXT = "text/plain";
+private static final int NOT_MODIFIED = 304;
+private static final int OK = 200;
+private static final int BUF_SIZE = 1024;
+private static final String HTTP = "http";
+private static final String HTTPS = "https";
+
+public HttpWatcher(final Configuration configuration, final Reconfigurable 
reconfigurable,
 
 Review comment:
   No. It is called by unit tests. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rgoers commented on a change in pull request #253: Log4 j2 913 - Add support for HTTP/S configuration monitoring. Support Spring Cloud Config

2019-02-03 Thread GitBox
rgoers commented on a change in pull request #253: Log4 j2 913 - Add support 
for HTTP/S configuration monitoring. Support Spring Cloud Config
URL: https://github.com/apache/logging-log4j2/pull/253#discussion_r253349277
 
 

 ##
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
 ##
 @@ -294,7 +302,22 @@ static String extractClassLoaderUriPath(final URI uri) {
 protected ConfigurationSource getInputFromString(final String config, 
final ClassLoader loader) {
 try {
 final URL url = new URL(config);
-return new ConfigurationSource(url.openStream(), 
FileUtils.fileFromUri(url.toURI()));
+URLConnection urlConnection = url.openConnection();
+if (url.getProtocol().equals(HTTPS)) {
+SslConfiguration sslConfiguration = 
SslConfigurationFactory.getSslConfiguration();
+if (sslConfiguration != null) {
+((HttpsURLConnection) 
urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+if (!sslConfiguration.isVerifyHostName()) {
+((HttpsURLConnection) 
urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
 
 Review comment:
   HostNameVerifier? I copied this code from the HttpAppender but since we 
haven't configured yet I had to get creative in how the SSL settings would be 
obtained.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services