1 2 Previous Next 22 Replies Latest reply on Sep 19, 2010 12:58 AM by mhvenkat Go to original post
      • 15. Re: ClassCastException due to Xerces conflict during app dep
        rodos77

         

        "jaikiran" wrote:
        So it really needs to be a question asked in the xerces-J forums whether there is any practical way to overriding the xercesImpl jars in a application server environment where multiple classloaders are involved.


        I really think the only way around this problem is by ensuring the right classloader is involved in xerces initialization by correctly setting the context classloader. The article you mention in your previous post confirms this approach.

        I have created a post on the JBossXB forum:
        http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249957#4249957

        • 16. Re: ClassCastException due to Xerces conflict during app dep
          rodos77

          Ok, I've created 2 patches for swapping out the context classloader. One for a class in the jbossweb project and one for a class in the JBossXB project. Either patch, when applied to the corresponding project, resolves the issue. You can now decide in which project it is more appropriate to fix this issue and apply the patch to the corresponding source repository to resolve this once and for all.

          JBossXB patch:

          *** orig\org\jboss\xb\binding\UnmarshallerFactory.java 2009-04-19 20:18:06.000000000 -0400
          --- new\org\jboss\xb\binding\UnmarshallerFactory.java 2009-08-19 12:13:34.345631600 -0400
          ***************
          *** 90,95 ****
          --- 90,98 ----
           {
           public Unmarshaller newUnmarshaller()
           {
          + ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
          + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
          +
           UnmarshallerImpl unmarshaller;
           try
           {
          ***************
          *** 99,104 ****
          --- 102,111 ----
           {
           throw new JBossXBRuntimeException(e.getMessage(), e);
           }
          + finally
          + {
          + Thread.currentThread().setContextClassLoader(oldCl);
          + }
          
           JBossXBParser parser = unmarshaller.getParser();
           if(validation != null)
          


          jbossweb patch:
          *** orig\org\jboss\web\tomcat\service\deployers\JBossContextConfig.java 2009-05-22 09:10:46.00000000
          0 -0400
          --- new\org\jboss\web\tomcat\service\deployers\JBossContextConfig.java 2009-08-19 12:32:46.517506600
           -0400
          ***************
          *** 542,547 ****
          --- 542,550 ----
          
           protected void processContextConfig(String resourceName, boolean local)
           {
          + ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
          + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
          +
           ContextMetaData contextMetaData = null;
           try
           {
          ***************
          *** 593,598 ****
          --- 596,605 ----
           ok = false;
           return;
           }
          + finally
          + {
          + Thread.currentThread().setContextClassLoader(oldCl);
          + }
          
           if (contextMetaData != null)
           {
          


          • 17. Re: ClassCastException due to Xerces conflict during app dep
            jaikiran

            Thank you for your efforts on patching this :) And good to know that it fixes the issue (although out of curiosity, i will try out a sample application and see why xerces is now happy this workaround).

            You can now decide in which project it is more appropriate to fix this issue and apply the patch to the corresponding source repository to resolve this once and for all.


            I am really not an expert on JBossXB, so its really the JBossXB guys who need to decide about this. The design forum thread that you opened is the right place to discuss this patch.


            • 18. Re: ClassCastException due to Xerces conflict during app dep
              jimball

              I cannot believe a user has had to respond with a fix for this.

              Are they any long term plans to fix JBoss 5 of this issue.

              • 19. Re: ClassCastException due to Xerces conflict during app dep
                jaikiran
                • 20. Re: ClassCastException due to Xerces conflict during app dep

                  Hi,
                  I've run into the same problem and tried to fix it with a jboss-classloading.xml. But, unfortunately, it didn't work for me. The curiosity is that another WAR file is working. And, additionally, a third WAR file without jboss-classloading.xml works perfectly. Here is my scenario:

                  - First.war (this works fine)
                  +--- jboss-classloading.xml

                  <classloading xmlns="urn:jboss:classloading:1.0"
                   name="first.war"
                   domain="IsolatedWithParentDomain"
                   parent-domain="DefaultDomain"
                   export-all="NON_EMPTY"
                   import-all="true"
                   parent-first="false"/>
                  


                  - Second.war (doesn't work)
                  +--- jboss-classloading.xml
                  <classloading xmlns="urn:jboss:classloading:1.0"
                   name="second.war"
                   domain="secondDomain"
                   export-all="NON_EMPTY"
                   import-all="true"
                   parent-first="false"/>
                  


                  - Third.war (works)
                  (no jboss-classloading.xml included)

                  The exception I get is as follows:

                  11:23:55,424 INFO [[/second]] Initializing log4j from [classpath:log4j.properties]
                  11:23:55,450 ERROR [[/second]] Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
                  java.lang.ExceptionInInitializerError
                   at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:336)
                   at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:73)
                   at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:152)
                   at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:47)
                   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
                   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
                   at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:312)
                   at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:144)
                   at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
                   at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
                   at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:597)
                   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
                   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
                   at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                   at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
                   at $Proxy36.start(Unknown Source)
                   at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
                   at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
                   at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
                   at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
                   at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
                   at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                   at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
                   at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                   at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                   at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                   at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                   at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                   at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                   at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
                   at org.jboss.system.ServiceController.start(ServiceController.java:460)
                   at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
                   at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
                   at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
                   at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                   at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                   at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                   at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                   at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                   at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
                   at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                   at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                   at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                   at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                   at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                   at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                   at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                   at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                   at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                   at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:698)
                   at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:290)
                   at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
                   at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
                   at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
                   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                   at java.lang.Thread.run(Thread.java:619)
                  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.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:694)
                   at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
                   at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
                   at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
                  


                  Is there another way to solve this issue? I've read through a bunch of articles which stated that jboss-classloading.xml is the solution for all the problems, but it didn't help. Or is there another point which I've overseen?

                  TIA,
                  Ralf.

                  • 21. Re: ClassCastException due to Xerces conflict during app dep
                    rodos77

                    This doesn't look like the same problem to me. The Exception is quite different. I could be wrong though.

                    If it is the same problem, as stated in the post, using jboss-classloading.xml doesn't resolve the underlying issue. Although it is possible to use a jboss-classloading.xm configuration that results in suppressing the Exception, it is equivalent to just removing the xerces jar(s) from your war so you may as well just do that.

                    The underlying issue has been resolved in the source code as can be seen in the corresponding JIRA, however it is unclear as to when it will actually be released.

                    If you can't wait for the fix release, you can always apply the patch included in this post, compile that class and drop it in the appropriate jboss jar (all info is contained in the patch). This is what I did.

                    • 22. Re: ClassCastException due to Xerces conflict during app deploym
                      mhvenkat

                      Hi,  Thanks for finally identifying the root cause analysis on this issue and providing a patch.  Great analysis.

                      Where can I download this patch?

                       

                      I jsut started using JBoss 5.1 and I face this issue.

                      1 2 Previous Next