7 Replies Latest reply: Dec 18, 2013 11:52 PM by ravi r RSS

__redirected.__DocumentBuilderFactory ClassCastException

Rodrigo Oliveira Newbie

Hello everyone,

 

I am migrating some web systems that use third party libraries. One of them use its own DocumentBuilderFactory class.

 

I created a module for the libraries, and the classes in that module are being accessed fine by the applications.

 

When I try to use DocumentBuilderFactory it gives a classCastException.

 

I tryed to exclude DocumentBuilderFactory from javaee.api with both ways indicated at this post  https://community.jboss.org/message/637818#637818.

 

Neither worked and I still keep recieving the error:

java.lang.ClassCastException: __redirected.__DocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

 

Is it because __redirected.__DocumentBuilderFactory is not on javax.xml.parsers? so I guess the configuration to exclude <exclude path="javax/xml/parsers" /> would not work, right?

If so, how can I resolve this issue? Where is __redirect.__DocumentBuilderFactory? Why is Jboss trying to use it instead of my own class.

 

Thanks in advance and follows the 2 configurations I had tryed according to the answer in that post: (I also tryed many variations trying to exclude javax/xml/parsers from javaee.api)

 

<?xml version="1.0" encoding="UTF-8"?>

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

    <ear-subdeployments-isolated>true</ear-subdeployments-isolated>

    <deployment>

        <dependencies>

            <module name="deployment.javaee.api" />

        </dependencies>

 

        <exclusions>

            <module name="javaee.api" />

        </exclusions>

    </deployment>

    <module name="deployment.javaee.api">

        <dependencies>

            <module name="javaee.api" export="true">

                <imports>

                    <exclude path="javax/xml/parsers" />

                </imports>

            </module>

        </dependencies>

    </module>

</jboss-deployment-structure>

 

or

 

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

  <deployment>

    <exclusions>

      <module name="javaee.api" />

    </exclusions>

    <dependencies>

        <module name="org.apache.commons.logging" />

    </dependencies>

  </deployment>

  <sub-deployment name="viabilidade.war">

    <exclusions>

      <module name="javaee.api" />

    </exclusions>   

    <dependencies>

        <module name="javaee.api" >

            <imports>

                <exclude-set>

                    <path name="javax/xml/parsers"/>

                </exclude-set>

            </imports>

        </module>

    </dependencies>

  </sub-deployment>

</jboss-deployment-structure>

  • 1. Re: __redirected.__DocumentBuilderFactory ClassCastException
    Rodrigo Oliveira Newbie

    Where is this classs __redirected.__DocumentBuilderFactory, and how can I remove it from the classpath of my application?

  • 2. Re: __redirected.__DocumentBuilderFactory ClassCastException
    Cheng Fang Newbie

    This class is part of jboss as and may not be removed.

     

    Your error looks like a classloader mismatch.  Can you post the full stacktrace?  AS7 does some jaxp factory redirecting, e.g., DocumentBuilderFactory, but the DocumentBuilder should still be whatever you specified.

     

    How did you specify your jaxp factory settings?  via -D sysprops in server JVM?  I suppose so since you would need to override the JDK defaults.

     

    javax.xml.parsers are part of JDK, maybe falls under javax.api module in as7, why you reference javaee.api for that?

     

    I would focus on how to add the necessary dependency to your app, not removing/excluding certain things, under the assumption that anything else not used by your app should never interfere with your app in as7.

     

    Have you  tried packaged the custom xml library inside your app (EAR/lib/x.jar, or WEB-INF/lib/x.jar)? 

  • 3. Re: __redirected.__DocumentBuilderFactory ClassCastException
    Rodrigo Oliveira Newbie

    Right, it is javax.api, I don't know why I wrote javaee.api. Anyway, using javax.api instead of javaee.api I still get the same error. I also tried to put my jar in either, WEB-INF/lib and EAR/lib but without sucess. The classload mismatch continues.

     

    The jboss-deployement-structure.xml I am using is:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

      <deployment>

        <exclusions>

          <module name="javax.api" />

        </exclusions>

      </deployment>

      <sub-deployment name="viabilidade.war">

        <exclusions>

          <module name="javax.api" />

        </exclusions>  

        <dependencies>

            <module name="javax.api" >

                <imports>

                    <exclude-set>

                        <path name="javax/xml/parsers"/>

                    </exclude-set>

                </imports>

            </module>

        </dependencies>

      </sub-deployment>

    </jboss-deployment-structure>

     

    and the full stack trace is:

     

    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/viabilidade]] (MSC service thread 1-4) Exception starting filter JOSSOGenericServletFilter: javax.servlet.ServletException: Error starting SSO Agent : Unexpected exception parsing XML document from class path resource [josso-agent-config.xml]; nested exception is java.lang.ClassCastException: __redirected.__DocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

        at org.josso.servlet.agent.GenericServletSSOAgentFilter.startup(GenericServletSSOAgentFilter.java:103) [josso-servlet-agent-1.8.6.jar:1.8.6]

        at org.josso.servlet.agent.GenericServletSSOAgentFilter.init(GenericServletSSOAgentFilter.java:118) [josso-servlet-agent-1.8.6.jar:1.8.6]

        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.10.Final.jar:]

        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.10.Final.jar:]

        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.10.Final.jar:]

        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_20]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_20]

        at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_20]

    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [josso-agent-config.xml]; nested exception is java.lang.ClassCastException: __redirected.__DocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) [spring-beans-2.5.5.jar:2.5.5]

        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113) [spring-context-2.5.5.jar:2.5.5]

        at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.loadBeanDefinitions(ClassPathXmlApplicationContext.java:180) [xbean-spring-3.4.3.jar:3.4.3]

        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123) [spring-context-2.5.5.jar:2.5.5]

        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423) [spring-context-2.5.5.jar:2.5.5]

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353) [spring-context-2.5.5.jar:2.5.5]

        at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161) [xbean-spring-3.4.3.jar:3.4.3]

        at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51) [xbean-spring-3.4.3.jar:3.4.3]

        at org.josso.agent.config.SpringComponentKeeperImpl.<init>(SpringComponentKeeperImpl.java:51) [josso-agent-1.8.6.jar:1.8.6]

        at org.josso.agent.config.SpringComponentKeeperFactoryImpl.newComponentKeeper(SpringComponentKeeperFactoryImpl.java:33) [josso-agent-1.8.6.jar:1.8.6]

        at org.josso.agent.Lookup.getComponentKeeper(Lookup.java:125) [josso-agent-1.8.6.jar:1.8.6]

        at org.josso.agent.Lookup.lookupSSOAgent(Lookup.java:102) [josso-agent-1.8.6.jar:1.8.6]

        at org.josso.servlet.agent.GenericServletSSOAgentFilter.startup(GenericServletSSOAgentFilter.java:93) [josso-servlet-agent-1.8.6.jar:1.8.6]

        ... 10 more

  • 4. Re: __redirected.__DocumentBuilderFactory ClassCastException
    Cheng Fang Newbie

    Can you post a test app to reproduce it?  You could also debug the springframework code to check the actual classloader for DocumentBuilderFactory and __redirected.__DocumentBuilderFactory.

     

    Normally DocumentBuilderFactory should be loaded by java bootstrap loader, and __redirected.__DocumentBuilderFactory by as system loader, and so are assignable.

  • 5. Re: __redirected.__DocumentBuilderFactory ClassCastException
    Nicolas Nicolas Newbie

    I've got the same problem. Did you resolve it?

    Can you expose your solution?

  • 6. Re: __redirected.__DocumentBuilderFactory ClassCastException
    ravi r Newbie

    Has any one solved this issue, i am still getting following exception

     

    JBWEB000289: Servlet InitializationServlet threw load() exception: java.lang.ClassCastException: __redirected.__DocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

        at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source) [DocumentBuilderFactory.class:]

        at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:849) [DOMConfigurator.class:]

        at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:755) [DOMConfigurator.class:]

        at org.apache.log4j.xml.XMLWatchdog.doOnChange(DOMConfigurator.java:1120) [XMLWatchdog.class:]

        at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:89) [FileWatchdog.class:]

        at org.apache.log4j.helpers.FileWatchdog.<init>(FileWatchdog.java:58) [FileWatchdog.class:]

        at org.apache.log4j.xml.XMLWatchdog.<init>(DOMConfigurator.java:1112) [XMLWatchdog.class:]

        at org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:735) [DOMConfigurator.class:]

        at org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:718) [DOMConfigurator.class:]

     

     

    Background:

     

    I have deployed osgi bundle on jboss-eap-6.1.0, before that i have started jboss server as follows

     

    #standalone.bat -c standalone-osgi.xml

     

    I have created osgi bundle from "war"  by updating MANIFEST.MF with osgi headers.

    I have no issue with deployment.

     

    My OSGi bundle has xml-apis.jar in WEB-INF/lib which i have added as part of Bundle-ClassPath:

     

    any help is appreciated

  • 7. Re: __redirected.__DocumentBuilderFactory ClassCastException
    ravi r Newbie

    Got resolved by removing xml-apis and xercesImpl from Bundle-ClassPath:

    Looks like these jars are conflicting with JBOSS modules .

     

    I don't understand why if jars in war don't conflict with JBoss ,

    but in OSGi  (in WEB-INF\lib) they conflict with JBoss jars