Repository: logging-log4j2 Updated Branches: refs/heads/master 77e4a3813 -> d0597f6d1
[LOG4J2-1127] log4j2.xml cannot be parsed on Oracle Weblogic 12c Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d0597f6d Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d0597f6d Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d0597f6d Branch: refs/heads/master Commit: d0597f6d1b1535aff334dac313bd2160f54ea5fd Parents: 77e4a38 Author: ggregory <[email protected]> Authored: Tue Sep 22 11:07:38 2015 -0700 Committer: ggregory <[email protected]> Committed: Tue Sep 22 11:07:38 2015 -0700 ---------------------------------------------------------------------- .../log4j/core/config/xml/XmlConfiguration.java | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d0597f6d/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java index 6174939..2adc756 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java @@ -74,14 +74,16 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu /** * Creates a new DocumentBuilder suitable for parsing a configuration file. - * + * @param xIncludeAware enabled XInclude * @return a new DocumentBuilder * @throws ParserConfigurationException */ - static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + static DocumentBuilder newDocumentBuilder(boolean xIncludeAware) throws ParserConfigurationException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); - enableXInclude(factory); + if (xIncludeAware) { + enableXInclude(factory); + } return factory.newDocumentBuilder(); } @@ -102,13 +104,6 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu } catch (final NoSuchMethodError err) { // LOG4J2-919 LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, err); - } catch (final Exception e) { - // LOG4J2-1127 - if (e.getCause() instanceof UnsupportedOperationException) { - LOGGER.warn("The DocumentBuilderFactory [{}] does not support XInclude: {}", factory, e); - } else { - throw e; - } } try { // Alternative: We could specify all features and values with system properties like: @@ -144,7 +139,21 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu } final InputSource source = new InputSource(new ByteArrayInputStream(buffer)); source.setSystemId(configSource.getLocation()); - final Document document = newDocumentBuilder().parse(source); + final DocumentBuilder documentBuilder = newDocumentBuilder(true); + Document document; + try { + document = documentBuilder.parse(source); + } catch (final Exception e) { + // LOG4J2-1127 + if (e.getCause() instanceof UnsupportedOperationException) { + LOGGER.warn( + "The DocumentBuilder {} does not support an operation: {}. Trying again without XInclude...", + documentBuilder, e); + document = newDocumentBuilder(false).parse(source); + } else { + throw e; + } + } rootElement = document.getDocumentElement(); final Map<String, String> attrs = processAttributes(rootNode, rootElement); final StatusConfiguration statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES)
