3 Replies Latest reply on Oct 30, 2009 8:04 AM by Tiago Scarton

    JBoss 5, Java 6, and DocumentBuilderFactory ClassCastExcepti

    Ben Dean Newbie

      So we have a war file that deploys fine on on JBoss 4.2.2.GA with Java 6. However, when I try to deploy the same thing with JBoss 5.0.0.GA (from the jboss-5.0.0.GA-jdk6.zip file), I get the following exception (edited a bit):

      00:00:00,000 ERROR [ContextLoader] Context initialization failed
      org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML
      document from class path resource [blah/some/package/spring-context.xml]; nested exception is
      java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to
      javax.xml.parsers.DocumentBuilderFactory
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions
       (XmlBeanDefinitionReader.java:420)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions
       (XmlBeanDefinitionReader.java:342)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions
       (XmlBeanDefinitionReader.java:310)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader
       .loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader
       .loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader
       .loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader
       .loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
       at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions
       (AbstractXmlApplicationContext.java:113)
       at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions
       (AbstractXmlApplicationContext.java:80)
       at org.springframework.context.support.AbstractRefreshableApplicationContext
       .refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
       at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory
       (AbstractApplicationContext.java:423)
       at org.springframework.context.support.AbstractApplicationContext.refresh
       (AbstractApplicationContext.java:353)
       at org.springframework.context.support.ClassPathXmlApplicationContext.<init>
       (ClassPathXmlApplicationContext.java:139)
       at org.springframework.context.support.ClassPathXmlApplicationContext.<init>
       (ClassPathXmlApplicationContext.java:83)
       ... skipping a bunch of lines
      Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot
      be cast to javax.xml.parsers.DocumentBuilderFactory
       at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
       at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory
       (DefaultDocumentLoader.java:89)
       at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument
       (DefaultDocumentLoader.java:70)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions
       (XmlBeanDefinitionReader.java:396)
       ... 77 more
      


      I'm not sure what to make of this other than that something about the way JBoss does jaxp stuff has changed and maybe the xercesImpl.jar isn't compatible with Java 6? (I really have no idea).

      Also it should be mentioned that we are building our war files with hibernate inside our wars rather than using the hibernate included with JBoss (in case we want to ever deploy to something else). With that in mind, when I deployed the same war file but using Hibernate 3.2.6 it works fine with no DocumentBuilderFactory exception. But switching to Hibernate 3.3.1, I get the above exception. (Both wars with both versions of Hibernate deploy fine on the old JBoss 4.2.2 server).

      I hope there's just some configuration file I didn't get set up quite right but I'm not sure. I've looked around a bit to see if other people have this problem and am not finding much of anything.

        • 1. Re: JBoss 5, Java 6, and DocumentBuilderFactory ClassCastExc
          Ben Dean Newbie

          Okay, I may have made this post a bit preemptively but hopefully someone else will do less searching because of my solution.

          Various hibernate libraries we use (hibernate-validator, hibernate-annotations, hibernate-search, etc), depend on dom4j. dom4j had been in our old hibernate 3.2.6 war as well but something must have changed.

          Now if I run mvn dependency:tree, there is another new jar being sucked in by dom4j, xml-apis. Looking at dom4j's pom file, it does not not directly depend on xml-apis, but it does depend on xerces which depends on xml-apis. This was really the only noticable xml related difference in the jar files that get included in our war.

          So I changed the dependencyManagement section of our pom file to have the following:

          <dependency>
           <groupId>dom4j</groupId>
           <artifactId>dom4j</artifactId>
           <version>1.6.1</version>
           <exclusions>
           <exclusion>
           <groupId>xml-apis</groupId>
           <artifactId>xml-apis</artifactId>
           </exclusion>
           </exclusions>
          </dependency>


          And now it works. I'm still not 100% sure why I needed to do this though. Seems like "maven magic" to some extent. I realize that it's not magic but I'm not sure what exactly is going on here.

          • 2. Re: JBoss 5, Java 6, and DocumentBuilderFactory ClassCastExc
            Ha Wa Newbie

            Thanks for your post. Super helpful, solved my problems too.

            • 3. Re: JBoss 5, Java 6, and DocumentBuilderFactory ClassCastExc
              Tiago Scarton Newbie

              Hi hwa,

              I tried this solution but didn't work for me, could you tell me exactly where I need to change in pom.xml?

              It'll be very helpfull if you show me your code.

              I get these exceptions when I try to access the index page.

              10:03:00,407 WARN [ClassLoaderManager] Unexpected error during load of:org.w3c.dom.Document
              java.lang.OutOfMemoryError
               at java.util.zip.Inflater.init(Native Method)
               at java.util.zip.Inflater.<init>(Unknown Source)
               at java.util.zip.ZipFile.getInflater(Unknown Source)
               at java.util.zip.ZipFile.getInputStream(Unknown Source)
               at java.util.zip.ZipFile.getInputStream(Unknown Source)
               at org.jboss.virtual.plugins.context.zip.ZipFileWrapper.openStream(ZipFileWrapper.java:214)
               at org.jboss.virtual.plugins.context.zip.ZipEntryContext.openStream(ZipEntryContext.java:1082)
               at org.jboss.virtual.plugins.context.zip.ZipEntryHandler.openStream(ZipEntryHandler.java:153)
               at org.jboss.virtual.VirtualFile.openStream(VirtualFile.java:230)
               at org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy.getResourceAsStream(VFSClassLoaderPolicy.java:483)
               at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:534)
               at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:532)
               at java.security.AccessController.doPrivileged(Native Method)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:530)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:507)
               at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
               at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
               at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
               at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:251)
               at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:150)
               at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:265)
               at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
               at java.lang.ClassLoader.loadClass(Unknown Source)
               at java.lang.ClassLoader.loadClassInternal(Unknown Source)
               at org.ajax4jsf.context.ResponseWriterContentHandler.<init>(ResponseWriterContentHandler.java:49)
               at org.ajax4jsf.context.ViewResources$HeadResponseWriter.<init>(ViewResources.java:259)
               at org.ajax4jsf.context.ViewResources.processHeadResources(ViewResources.java:444)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:193)
               at org.openfaces.ajax.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:62)
               at org.openfaces.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:412)
               at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
               at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
               at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at com.goPoints.web.Filter.SecurityFilter.doFilter(SecurityFilter.java:46)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
               at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
               at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
               at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
               at org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage(FormAuthenticator.java:316)
               at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:244)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Unknown Source)
              10:03:00,547 ERROR [BaseXMLFilter] Exception in the filter chain
              javax.servlet.ServletException: Servlet execution threw an exception
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at com.goPoints.web.Filter.SecurityFilter.doFilter(SecurityFilter.java:46)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
               at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
               at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
               at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
               at org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage(FormAuthenticator.java:316)
               at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:244)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Unknown Source)
              Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/Document
               at org.ajax4jsf.context.ResponseWriterContentHandler.<init>(ResponseWriterContentHandler.java:49)
               at org.ajax4jsf.context.ViewResources$HeadResponseWriter.<init>(ViewResources.java:259)
               at org.ajax4jsf.context.ViewResources.processHeadResources(ViewResources.java:444)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:193)
               at org.openfaces.ajax.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:62)
               at org.openfaces.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:412)
               at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
               at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
               at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               ... 29 more
              Caused by: java.lang.ClassNotFoundException: Unexpected error during load of: org.w3c.dom.Document, msg=null
               at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:165)
               at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:265)
               at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
               at java.lang.ClassLoader.loadClass(Unknown Source)
               at java.lang.ClassLoader.loadClassInternal(Unknown Source)
               ... 40 more
              Caused by: java.lang.OutOfMemoryError
               at java.util.zip.Inflater.init(Native Method)
               at java.util.zip.Inflater.<init>(Unknown Source)
               at java.util.zip.ZipFile.getInflater(Unknown Source)
               at java.util.zip.ZipFile.getInputStream(Unknown Source)
               at java.util.zip.ZipFile.getInputStream(Unknown Source)
               at org.jboss.virtual.plugins.context.zip.ZipFileWrapper.openStream(ZipFileWrapper.java:214)
               at org.jboss.virtual.plugins.context.zip.ZipEntryContext.openStream(ZipEntryContext.java:1082)
               at org.jboss.virtual.plugins.context.zip.ZipEntryHandler.openStream(ZipEntryHandler.java:153)
               at org.jboss.virtual.VirtualFile.openStream(VirtualFile.java:230)
               at org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy.getResourceAsStream(VFSClassLoaderPolicy.java:483)
               at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:534)
               at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:532)
               at java.security.AccessController.doPrivileged(Native Method)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:530)
               at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:507)
               at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
               at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
               at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
               at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:251)
               at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:150)
               ... 46 more


              Can you help me?

              Thanks