Fix property replacement bug in Log4jWebConfigurer
Previously, if the resolution of a ${...} placeholder resulted in a
valid URL for the location of a log4j properties/XML file, the URL
would ultimately be malformed by an unnecessary call to to
WebUtils#getRealPath.
The implementation of Log4jWebConfigurer#initLogging now eagerly
attempts SystemPropertyUtils#resolvePlaceholders before checking to see
if the location is a valid URL, and bypassing the call to
WebUtils#getRealPath if so.
Issue: SPR-9417
This commit is contained in:
parent
f1246a4317
commit
2503b7eb89
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -124,9 +124,9 @@ public abstract class Log4jWebConfigurer {
|
||||||
try {
|
try {
|
||||||
// Return a URL (e.g. "classpath:" or "file:") as-is;
|
// Return a URL (e.g. "classpath:" or "file:") as-is;
|
||||||
// consider a plain file path as relative to the web application root directory.
|
// consider a plain file path as relative to the web application root directory.
|
||||||
|
location = SystemPropertyUtils.resolvePlaceholders(location);
|
||||||
if (!ResourceUtils.isUrl(location)) {
|
if (!ResourceUtils.isUrl(location)) {
|
||||||
// Resolve system property placeholders before resolving real path.
|
// Resolve system property placeholders before resolving real path.
|
||||||
location = SystemPropertyUtils.resolvePlaceholders(location);
|
|
||||||
location = WebUtils.getRealPath(servletContext, location);
|
location = WebUtils.getRealPath(servletContext, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -37,8 +37,9 @@ import org.springframework.mock.web.MockServletContext;
|
||||||
public class Log4jWebConfigurerTests {
|
public class Log4jWebConfigurerTests {
|
||||||
|
|
||||||
private static final String TESTLOG4J_PROPERTIES = "testlog4j.properties";
|
private static final String TESTLOG4J_PROPERTIES = "testlog4j.properties";
|
||||||
private static final String CLASSPATH_RESOURCE = "classpath:org/springframework/web/util/testlog4j.properties";
|
private static final String PROPERTIES_LOCATION = "org/springframework/web/util/testlog4j.properties";
|
||||||
private static final String RELATIVE_PATH = "src/test/resources/org/springframework/web/util/testlog4j.properties";
|
private static final String CLASSPATH_RESOURCE = "classpath:" + PROPERTIES_LOCATION;
|
||||||
|
private static final String RELATIVE_PATH = "src/test/resources/" + PROPERTIES_LOCATION;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initLoggingWithClasspathResource() {
|
public void initLoggingWithClasspathResource() {
|
||||||
|
|
@ -60,6 +61,11 @@ public class Log4jWebConfigurerTests {
|
||||||
initLogging(RELATIVE_PATH, true);
|
initLogging(RELATIVE_PATH, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // See SPR-9417
|
||||||
|
public void initLoggingWithPlaceholderResolvingToValidUrl() {
|
||||||
|
initLogging("${some.prop.name:classpath:}" + PROPERTIES_LOCATION, true);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initLoggingWithUrl() {
|
public void initLoggingWithUrl() {
|
||||||
URL url = Log4jWebConfigurerTests.class.getResource(TESTLOG4J_PROPERTIES);
|
URL url = Log4jWebConfigurerTests.class.getResource(TESTLOG4J_PROPERTIES);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue