Page 1 of 1

DocumentBuilderFactoryImpl not found

PostPosted: Mon Sep 24, 2012 2:41 am
by halius
Hello, this is my first post to the forum, please excuse me if I miss any etiquette rules.

We've been employing the use of docx4j (2.8.0) in our project for quite some time (fantastic tool by the way). Up until now, we've been deploying our application on a Tomcat7 server running OpenJDK 1.6. Everything has worked perfectly.

Recently, we've been trying to move our application to a Weblogic 10.3.6 server running Oracle JDK 1.6. The rest of the application deploys and runs fine, until we try to use some of our routines that invoke docx4j classes. The application invokes docx4j and it runs fine, giving us an appropriate document. However, after that point, if we try to navigate to a page within the site that hasn't been compiled yet, we receive this error:

Code: Select all
javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:129)
at weblogic.jsp.internal.jsp.JspTagLibraryFeature.parseTldFromWebXML(JspTagLibraryFeature.java:892)
at weblogic.jsp.internal.jsp.JspTagLibraryFeature.initFromWebXML(JspTagLibraryFeature.java:866)
at weblogic.jsp.internal.jsp.JspTagLibraryFeature.init(JspTagLibraryFeature.java:454)
at weblogic.jsp.internal.jsp.JspTagLibraryFeature.init(JspTagLibraryFeature.java:253)
at weblogic.jsp.internal.jsp.JspTagLibraryFeature.setCPL(JspTagLibraryFeature.java:44)
at weblogic.jsp.internal.CPL.getFeature(CPL.java:712)
at weblogic.jsp.internal.jsp.JspParser.getTagLibraryFeature(JspParser.java:4549)
at weblogic.jsp.internal.jsp.JspParser.getTagLibInfo(JspParser.java:2955)
at weblogic.jsp.internal.jsp.JspParser.jspParse(JspParser.java:624)
at weblogic.jsp.internal.jsp.JspParser._parse(JspParser.java:535)
at weblogic.jsp.internal.jsp.JspParser.parse(JspParser.java:528)
at weblogic.jsp.internal.jsp.JspAnalyzer.parseFile(JspAnalyzer.java:104)
at weblogic.jsp.internal.jsp.JspAnalyzer.parse(JspAnalyzer.java:92)
at weblogic.jsp.internal.ProxySourceFile.parse(ProxySourceFile.java:106)
at weblogic.jsp.internal.SourceFile.getAst(SourceFile.java:559)
at weblogic.jsp.internal.SourceFile.getAst(SourceFile.java:533)
at weblogic.jsp.internal.SourceFile.check(SourceFile.java:335)
at weblogic.jsp.internal.ProxySourceFile.codeGen(ProxySourceFile.java:224)
at weblogic.jsp.internal.SourceFile.codeGen(SourceFile.java:327)
at weblogic.jsp.internal.client.ClientUtilsImpl$CodeGenJob.run(ClientUtilsImpl.java:599)
at weblogic.jsp.internal.client.Job.performJob(Job.java:83)
at weblogic.jsp.internal.client.ThreadPool$WorkerThread.run(ThreadPool.java:217)


We've tried many different things including:
- Setting prefer-application-packages in weblogic-application.xml as follows:
Code: Select all
<prefer-application-packages>
   <package-name>org.apache.log4j.*</package-name>
   <package-name>javax.xml.parsers.*</package-name>
   <package-name>org.apache.xerces.*</package-name>   
   <package-name>org.apache.xalan.*</package-name>   
   <package-name>com.sun.org.apache.xerces.internal.jaxp.*</package-name>
</prefer-application-packages>


- Setting saxparser-factory, document-builder-factory, and transformer-factory in weblogic-application.xml as follows:

Code: Select all
<xml>
   <parser-factory>
      <saxparser-factory>org.apache.xerces.jaxp.SAXParserFactoryImpl</saxparser-factory>
      <document-builder-factory>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl</document-builder-factory>
      <transformer-factory>org.apache.xalan.processor.TransformerFactoryImpl</transformer-factory>
   </parser-factory>
</xml>


- Setting the factory implementations in docx4j.properties as follows:

Code: Select all
javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
javax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
javax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl



I have a suspicion that the docx4j classes we are using might be setting a system property that causes issues with the rest of the application. For now, we have implemented a "band-aid" solution which was to tell weblogic to precompile all the jsp pages. That seems to work but it's not solving the root of the problem and I have a feeling this will rear it's head again.

Another point of note that may or may not be releated is that we employ the use of xercesImpl.jar. We are using this because it's a hard dependency for AntiSamy.

I've scoured the docx4j forums, these two related topics are probably the best I've found and helped us find the cause of the problem:
- http://www.docx4java.org/forums/docx-java-f6/weblogic-javax-xml-transform-transformerfactory-issue-t1119.html
- http://www.docx4java.org/forums/docx-java-f6/problems-with-wordprocessingmlpackage-t1085.html

We also experience the same deploy/undeploy problems described in the first post above. We have to restart our severs each time. (This is still occurring with the precompile jsp hack in place).

Re: DocumentBuilderFactoryImpl not found

PostPosted: Mon Sep 24, 2012 3:41 am
by halius
As an addition, I tried the checkparsers.jsp file that was recommended in one of the other posts. Here are the results:

BEFORE RUNNING docx4j:

Code: Select all
JAXP Test.
•   SAXParserFactory: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
•   SAXParser: com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl
•   DocumentBuilderFactory: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
•   DocumentBuilder: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl
•   Xml-Apis version (if used): XmlCommonsExternal 1.4.01
•   Xalan version (if used): Xalan Java 2.7.1
•   Xerces version (if used): Xerces-J 2.11.0



AFTER RUNNING docx4j:

Code: Select all
JAXP Test.
•   SAXParserFactory: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
•   SAXParser: com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl
•   DocumentBuilderFactory: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
•   DocumentBuilder: org.apache.xerces.jaxp.DocumentBuilderImpl
•   Xml-Apis version (if used): XmlCommonsExternal 1.4.01
•   Xalan version (if used): Xalan Java 2.7.1
•   Xerces version (if used): Xerces-J 2.11.0


I tried this even setting the parser factories to the com.sun.org implementation in docx4j.properties. It's as though it's ignoring the properties file and setting it to the org.apache.xerces documentbuilder regardless.

Re: DocumentBuilderFactoryImpl not found

PostPosted: Mon Sep 24, 2012 12:48 pm
by halius
I've resolved this issue. I was previously using the latest binary release of docx4j (2.8.0) which does not include the docx4j.properties option for declaring your parser library. I downloaded the latest code from github and recompiled the jar (I guess this is being called 2.8.1 right now).

In my case, docx4j was changing the systems parser library to the org.apache.xerces implementation, rather than sticking with the com.sun.org.apache.xerces implementation, which Weblogic needed (or at least funcitoned properly with).

My docx4j.properties file ended up having this:

Code: Select all
javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl



I would vote to promote 2.8.1 as a binary release if possible. I think that allowing consumers to specify the parser libraries in their properties file alleviates hard dependencies and is a great improvement.