stax conflict between weblogic 9.2 and xfire 1.2.4

As described in the reply of my previous post, an exception occurred after weblogic cache was cleared.

java 代码
  1. weblogic.application.ModuleException:    
  2.     at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:295)   
  3.     at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)   
  4.     at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:93)   
  5.     at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:360)   
  6.     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)   
  7.     Truncated. see log file for complete stacktrace   
  8. java.lang.ClassCastException: com.ctc.wstx.stax.WstxInputFactory   
  9.     at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)   
  10.     at weblogic.servlet.internal.WebAppHelper.addListenerElements(WebAppHelper.java:244)   
  11.     at weblogic.servlet.internal.WebAppHelper$IOHelperImpl.parseXML(WebAppHelper.java:224)   
  12.     at weblogic.descriptor.DescriptorCache.parseXML(DescriptorCache.java:324)   
  13.     at weblogic.servlet.internal.WebAppHelper.registerTagLibListeners(WebAppHelper.java:174)   
  14.     Truncated. see log file for complete stacktrace   
  15. >   

After consulting google, I was suggested to overwrite weblogic's default stax parser by setting the Djavax.xml.stream.XMLInputFactory property to com.ctc.wstx.stax.WstxInputFactory. However, jvm quickly complained of not being able to find WstxInputFactory class.

java 代码
  1. weblogic.management.ManagementException: [Management:141266]Parsing Failure in config.xml: Provider com.ctc.wstx.stax.WstxInputFactory not found   
  2.     at weblogic.management.provider.internal.RuntimeAccessImpl.<init>(RuntimeAccessImpl.java:122)   
  3.     at weblogic.management.provider.internal.RuntimeAccessService.start(RuntimeAccessService.java:38)   
  4.     at weblogic.t3.srvr.ServerServicesManager.startService(ServerServicesManager.java:374)   
  5.     at weblogic.t3.srvr.ServerServicesManager.startInStandbyState(ServerServicesManager.java:125)   
  6.     at weblogic.t3.srvr.T3Srvr.initializeStandby(T3Srvr.java:630)   
  7.     at weblogic.t3.srvr.T3Srvr.startup(T3Srvr.java:402)   
  8.     at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:361)   
  9.     at weblogic.Server.main(Server.java:67)  

This is easy. Adding the lib into classpath will do. Sadly, another shock  bursted right after wstx.jar was included.

java 代码
  1. <error> <j2ee> <bea-< span="">160197> <unable to load descriptor d:\bea\weblogic92\server\lib\consoleapp meta-inf="" application.xml of module consoleapp. the error is weblogic.descriptor.descriptorexception: unmarshaller failed=""   <="" span="">
  2.     at weblogic.descriptor.internal.MarshallerFactory$1.createDescriptor(MarshallerFactory.java:147)   
  3.     at weblogic.descriptor.DescriptorManager.createDescriptor(DescriptorManager.java:280)   
  4.     at weblogic.descriptor.DescriptorManager.createDescriptor(DescriptorManager.java:248)   
  5.     at weblogic.application.descriptor.AbstractDescriptorLoader2.getDescriptorBeanFromReader(AbstractDescriptorLoader2.java:749)   
  6.     at weblogic.application.descriptor.AbstractDescriptorLoader2.createDescriptorBean(AbstractDescriptorLoader2.java:376)   
  7.     at weblogic.application.descriptor.AbstractDescriptorLoader2.loadDescriptorBeanWithoutPlan(AbstractDescriptorLoader2.java:720)   
  8.     at weblogic.application.descriptor.AbstractDescriptorLoader2.loadDescriptorBean(AbstractDescriptorLoader2.java:729)   
  9.     at weblogic.application.ApplicationDescriptor.getApplicationDescriptor(ApplicationDescriptor.java:277)   
  10.     at weblogic.application.internal.EarDeploymentFactory.findOrCreateComponentMBeans(EarDeploymentFactory.java:174)   
  11.     at weblogic.application.internal.MBeanFactoryImpl.findOrCreateComponentMBeans(MBeanFactoryImpl.java:48)   
  12.     at weblogic.application.internal.MBeanFactoryImpl.createComponentMBeans(MBeanFactoryImpl.java:110)   
  13.     at weblogic.application.internal.MBeanFactoryImpl.initializeMBeans(MBeanFactoryImpl.java:76)   
  14.     at weblogic.deploy.internal.InternalAppProcessor.createBeansForInternalApp(InternalAppProcessor.java:396)   
  15.     at weblogic.deploy.internal.InternalAppProcessor.stageFilesAndCreateBeansForInternalApp(InternalAppProcessor.java:250)   
  16.     at weblogic.deploy.internal.InternalAppProcessor.updateConfiguration(InternalAppProcessor.java:196)   
  17.     at weblogic.management.deploy.internal.DeploymentServerService.init(DeploymentServerService.java:144)   
  18.     at weblogic.management.deploy.internal.DeploymentPreStandbyServerService.start(DeploymentPreStandbyServerService.java:32)   
  19.     at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)   
  20.     at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)   
  21.     at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)   
  22. Caused by: com.bea.xml.XmlException: weblogic.descriptor.BeanAlreadyExistsException: Bean already exists: "weblogic.j2ee.descriptor.ModuleBeanImpl@8120252(/Modules[weblogic.descriptor.internal.DescriptorBeanKey@8426316])"  
  23.     at com.bea.staxb.runtime.internal.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:54)   
  24.     at com.bea.staxb.runtime.internal.RuntimeBindingType$BeanRuntimeProperty.setValue(RuntimeBindingType.java:483)   
  25.     at com.bea.staxb.runtime.internal.AttributeRuntimeBindingType$QNameRuntimeProperty.fillCollection(AttributeRuntimeBindingType.java:385)   
  26.     at com.bea.staxb.runtime.internal.MultiIntermediary.getFinalValue(MultiIntermediary.java:52)   
  27.     at com.bea.staxb.runtime.internal.AttributeRuntimeBindingType.getFinalObjectFromIntermediary(AttributeRuntimeBindingType.java:145)   
  28.     at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalBindingType(UnmarshalResult.java:185)   
  29.     at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalDocument(UnmarshalResult.java:154)   
  30.     at com.bea.staxb.runtime.internal.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:65)   
  31.     at weblogic.descriptor.internal.MarshallerFactory$1.createDescriptor(MarshallerFactory.java:136)  

What the hell...

Seems like wstx parser can't read weblogic descriptors... Now what? Think hard...

The default consoleapp will be loaded before my application. Why not delay the introduction of wstx libraries? Insteadof setting propeties inside jvm arguments, I put them in a static block of the codes. This guarantees a late loading.

java 代码
  1. static {   
  2.     System.setProperty("javax.xml.stream.XMLInputFactory",   
  3.       "com.ctc.wstx.stax.WstxInputFactory");   
  4.     System.setProperty("javax.xml.stream.XMLOutputFactory",   
  5.       "com.ctc.wstx.stax.WstxOutputFactory");   
  6.     System.setProperty("javax.xml.stream.XMLEventFactory",   
  7.       "com.ctc.wstx.stax.evt.WstxEventFactory");   
  8. }   

Keep wstx.jar inside classpath to avoid the exception below during server start.

java 代码
  1. javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxInputFactory not found   
  2.     at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)   
  3.     at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:120)   
  4.     at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)   
  5.     at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)   
  6.     at weblogic.descriptor.internal.MarshallerFactory$1.createDescriptor(MarshallerFactory.java:79)   
  7.     Truncated. see log file for complete stacktrace  

Now clear the cache and test again...

Yes, it's working! Finally!

你可能感兴趣的:(java,xml,servlet,weblogic,360)