Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1091

Error occur when parsing logback.xml if the logback.xml declared external entities

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 1.1.10
    • 1.1.3
    • None
    • jdk 7u67, slf4j1.1.12

    Description

      An exception occur saying the external entity file could not be found even actually the file put in the correct path. I try to parse the logback.xml with w3c dom. the xml could be parsed. that means the path of the external entity file is correct.

      Exception message:

      Failed to auto configure default logger context
      Reported exception:

      ch.qos.logback.core.joran.spi.JoranException: Problem parsing XML document. See previously reported errors.
      	at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:67)
      	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:134)
      	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
      	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
      	at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77)
      	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:152)
      	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
      	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
      	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:141)
      	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
      	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
      	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
      	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
      	at com.kingland.independence.Test.main(Test.java:9)
      Caused by: org.xml.sax.SAXException: Stopping after fatal error: File "common.ent" not found.
      	at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1245)
      	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExternalEntity(DefaultEntityHandler.java:780)
      	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromParameterEntity(DefaultEntityHandler.java:703)
      	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromEntity(DefaultEntityHandler.java:588)
      	at org.apache.xerces.framework.XMLDTDScanner.scanDecls(XMLDTDScanner.java:1498)
      	at org.apache.xerces.framework.XMLDTDScanner.scanDoctypeDecl(XMLDTDScanner.java:1123)
      	at org.apache.xerces.framework.XMLDocumentScanner.scanDoctypeDecl(XMLDocumentScanner.java:2145)
      	at org.apache.xerces.framework.XMLDocumentScanner.access$0(XMLDocumentScanner.java:2100)
      	at org.apache.xerces.framework.XMLDocumentScanner$PrologDispatcher.dispatch(XMLDocumentScanner.java:831)
      	at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      	at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
      	at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
      	at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:61)
      	... 13 more
      17:36:36,538 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
      17:36:36,538 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/C:/Development/Hub/Master/Independence/Independence/webApplication/WEB-INF/classes/logback-test.xml]
      17:36:36,881 |-ERROR in ch.qos.logback.core.joran.event.SaxEventRecorder@2c54366 - XML_PARSING - Parsing fatal error on line 0 and column 0 org.xml.sax.SAXParseException; systemId: ; lineNumber: 0; columnNumber: 0; File "common.ent" not found.
      	at org.xml.sax.SAXParseException: File "common.ent" not found.
      	at 	at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1219)
      	at 	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExternalEntity(DefaultEntityHandler.java:780)
      	at 	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromParameterEntity(DefaultEntityHandler.java:703)
      	at 	at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromEntity(DefaultEntityHandler.java:588)
      	at 	at org.apache.xerces.framework.XMLDTDScanner.scanDecls(XMLDTDScanner.java:1498)
      	at 	at org.apache.xerces.framework.XMLDTDScanner.scanDoctypeDecl(XMLDTDScanner.java:1123)
      	at 	at org.apache.xerces.framework.XMLDocumentScanner.scanDoctypeDecl(XMLDocumentScanner.java:2145)
      	at 	at org.apache.xerces.framework.XMLDocumentScanner.access$0(XMLDocumentScanner.java:2100)
      	at 	at org.apache.xerces.framework.XMLDocumentScanner$PrologDispatcher.dispatch(XMLDocumentScanner.java:831)
      	at 	at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      	at 	at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
      	at 	at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
      	at 	at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:61)
      	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:134)
      	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
      	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
      	at 	at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77)
      	at 	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:152)
      	at 	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
      	at 	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
      	at 	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:141)
      	at 	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
      	at 	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
      	at 	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
      	at 	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
      	at 	at com.kingland.independence.Test.main(Test.java:9)
      

      -----------------------------------------------------------------------------------------

      My test code:

      package com.kingland.independence;
      
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      
      import org.w3c.dom.Document;
      import org.w3c.dom.Node;
      import org.w3c.dom.NodeList;
      
      public class Test {
      
      	public static void main(String[] args) throws Exception {
      		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      		DocumentBuilder builder = factory.newDocumentBuilder();
      		Document doc = builder.parse("C:\\Development\\Hub\\Master\\Independence\\Independence\\webApplication\\WEB-INF\\classes\\logback.xml");
      		NodeList nodes = doc.getElementsByTagName("pattern");
      		for (int i = 0; i < nodes.getLength(); i++){
      			Node node = nodes.item(i);
      			System.out.println(node.getFirstChild().getNodeValue());
      		}
      	}
      }
      

      -----------------------------------------------------------------------------------------

      My logback.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE configuration[
      <!ENTITY % common SYSTEM "common.ent"> %common;
      ]>
      <!-- used for BVT/UAT/PROD environment, will not include debug information 
      	and print in console -->
      <configuration scan="true">
      	<conversionRule conversionWord="crlf"
      		converterClass="org.owasp.security.logging.mask.CRLFConverter" />
      	<include resource="logback-common.xml" />
          <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">    
      	   <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                  <level>ERROR</level>
              </filter>
              <layout class="ch.qos.logback.classic.PatternLayout">
                  <pattern>%d{&LOGGING_DATE_PATTERN; &LOGGING_TIME_PATTERN;}{&LOGGING_TIME_ZONE;} [%thread] [%marker] %-5level %logger{36} throwable{full} - %crlf(%msg) %n</pattern>
              </layout>
          </appender>
      	<root level="INFO">
      		<appender-ref ref="Console" />
      		<appender-ref ref="IndyLogFile" />
      	</root>
      </configuration>
      

      Attachments

        1. common.body.ent
          0.1 kB
        2. common.ent
          1 kB
        3. logback.xml
          1.0 kB

        Activity

          People

            ceki Ceki Gülcü
            danielwang daniel.ruiqing.wang
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: