无法创建安全的XMLInputFactory

时间:2016-06-02 11:39:06

标签: java tomcat web-applications junit cxf

大家好,
    我的应用程序基于PTV xServer模块,用于计算最佳路线和行程计划。     它是一个Web应用程序,我正在使用tomcat。     因此,在使用tomcat运行我的应用程序时,它可以找到,但是当我使用“main”方法执行此应用程序时,我在调用xServer模块服务/方法时遇到错误。

    com.ptvag.jabba.core.exception.UnexpectedException: Cannot create a secure XMLInputFactory
    at com.ptvag.jabba.core.exception.ExceptionAnalyzer.mapExternalException(ExceptionAnalyzer.java:43)
    at com.ptvag.xserver.xlocate.XLocateCXFClient.findLocation(Unknown Source)
    at com.ilume.ptv.adapter.xmodule.XLocateAdapter.findLocations(XLocateAdapter.java:278)
    at com.ilume.ptv.adapter.xmodule.XLocateAdapter.findLocations(XLocateAdapter.java:248)
    at com.ilume.jti.logic.controller.models.rerouting.DepotsBO.isDepotValid(DepotsBO.java:182)
    at com.ilume.jti.logic.controller.models.rerouting.DepotsBO.<init>(DepotsBO.java:96)
    at com.ilume.jti.service.mapper.ReRouteMapper.mapJaxbJavaToBO(ReRouteMapper.java:155)
    at com.ilume.jti.service.mapper.ReRouteMapper.mapJaxbJavaToBO(ReRouteMapper.java:134)
    at com.ilume.jti.test.help.InputHelper.getCycleFromXMLResource(InputHelper.java:78)
    at com.ilume.jti.test.controller.russia.RussiaReRoutingControllerTest.getCycle(RussiaReRoutingControllerTest.java:58)
    at com.ilume.jti.test.controller.russia.RussiaReRoutingControllerTest.testTestReRouting(RussiaReRoutingControllerTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.RuntimeException: Cannot create a secure XMLInputFactory
    at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:314)
    at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:264)
    at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1516)
    at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1415)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:206)
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:101)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at com.ptvag.xserver.xlocate.jwsdp.XLocateWSService.<init>(Unknown Source)
    at com.ptvag.xserver.xlocate.XLocateCXFClient.getWebService(Unknown Source)  

1 个答案:

答案 0 :(得分:1)

请参阅CXF web service client: "Cannot create a secure XMLInputFactory"

问题是应用程序服务器类加载器和本地为XML库提供了不同的优先级

解决方案1 ​​ - 包含CXF XML库(CXF2.7)

Add stax2-api and woodstox-core-asl jars from the 2.7.x CXF distribution 

解决方案2 - 升级到CXF 3.0.0

Then woodstock is not needed

解决方案3 - 允许不安全的解析器不太安全

 add `-Dorg.apache.cxf.stax.allowInsecureParser=1` to the command line to execute your programa