Thursday, July 26, 2018

XML-20116: (Warning) Entity already defined, using the first definition.

I’ve been pulling my hair out seeing the following error message while trying to make a simple XSLT transformation in my spring application.
XML-20116: (Warning) Entity 'tablemodel' already defined, using the first definition.
 at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:425)
 at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
 at oracle.xml.parser.v2.XMLReader.scanNameChars(XMLReader.java:1306)
 at oracle.xml.parser.v2.XMLReader.scanQName(XMLReader.java:2204)
 at oracle.xml.parser.v2.XMLExternalReader.scanQName(XMLExternalReader.java:404)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttrDecl(NonValidatingParser.java:1024)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttlistDecl(NonValidatingParser.java:989)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:819)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:843)
 at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:644)
 at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:435)
 at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:393)
 at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:236)
Even though I’ve explicitly instructed my app to use Saxon library, obviously xml parser from oracle gets in the way, but why? It turns out that when you bring the oracle jdbc driver dependency via maven using Oracle's maven repo, it transitively gets other libraries which causes this problem when parsing the XMLs. I just excluded the transitive dependencies for the oracle driver and everything works just fine. I don't think those extra libs are necessary at all at runtime. If you have this in your pom:
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
</dependency>
Just exclude the transitive dependencies for the oracle driver and everything works just fine.
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
    <exclusions>
        <exclusion>
            <artifactid>xmlparserv2</artifactid>
            <groupid>com.oracle.jdbc</groupid>
        </exclusion>
    </exclusions>
</dependency>
This is the dependency tree by the way
  • ojdbc7 : 12.1.0.2
  • xdb6 : 12.1.0.2
  • orai18n : 12.1.0.2
  • xmlparserv2 : 12.1.0.2 -> obvious culprit
  • oraclepki : 12.1.0.2
  • osdt_cert : 12.1.0.2
  • osdt_core : 12.1.0.2

Happy coding!

Saturday, July 21, 2018

Maven error - Credentials cannot be used for NTLM authentication

I've been using CNTLM to access the resources on the internet through corporate proxy. Recently, I started getting the following error messages from maven.
  • WARNING: NEGOTIATE authentication error: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt))
  • WARNING: NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.maven.wagon.providers.http.httpclient.auth.UsernamePasswordCredentials
After some investigation, I found out that wagon-http-lightweight artifact has to be overridden in maven configuration. I was able to do this by placing wagon-http-lightweight-2.2.jar file into $M2_HOME\lib\ext folder I'm using maven version number 3.5.2. I haven't checked it with other versions. This artifact can be downloaded from here