解决CXF webService 调用报错: “Cannot create a secure XMLInputFactory”

Nov 20, 2013 8:05:26 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://webservices.server/}ExampleWebServiceService from class server.webservices.ExampleWebService
Done creating client
javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157)
    at $Proxy38.printString(Unknown Source)
    at ExampleNmsWebServiceClient.printString(ExampleNmsWebServiceClient.java:29)
    at ExampleNmsWebServiceClient.main(ExampleNmsWebServiceClient.java:40)
Caused by: org.apache.cxf.binding.soap.SoapFault: Cannot create a secure XMLInputFactory
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:40)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:835)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1606)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1502)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:627)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:565)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
    ... 3 more

鸣谢:
https://blog.csdn.net/u014644574/article/details/80024882

https://blog.csdn.net/Apachezp/article/details/79590178
https://www.codeleading.com/article/88993181106/

原因:缺少woodstox-core-asl-4.4.1.jar和stax2-api-3.1.4.jar包。引入以后还报错说明这个jar包可能没有被有效加载,也许跟其他jar包有冲突。

如果还是有报错,看项目中是否存在冲突包,并删除之。

删除项目中的冲突的wstx-asl-3.2.1.jar包
1:到JAVA_OPTIONS的-Dorg.apache.cxf.stax.allowInsecureParser=1

2:重命名woodstox-core-asl-4.4.1.jar -> awoodstox-core-asl-4.4.1.jar

在系统参数中 “org.apache.cxf.stax.allowInsecureParser” 不是 1 或者 true
。找到临时解决方式,在接口类加载钱设置系统参数;

@PostConstruct public void init() { //设置 cxf 转换为安全的 不然会报 错误 Cannot
create a secure XMLInputFactory
System.setProperty(StaxUtils.ALLOW_INSECURE_PARSER,Constant.STR_TRUE);
}。
原文链接:https://blog.csdn.net/Swear_fling/article/details/45232875

https://blog.csdn.net/fan1989800/article/details/103181585
通过intellij ide强大的Diagrams功能,查看依赖关系

解决1 :尝试着添加排除项,如下到pom.xml中


	org.apache.neethi
	neethi
	
		
			org.codehaus.woodstox
			wstx-asl
		
		
			wsdl4j
			wsdl4j
		
	

这次确实是解决了问题
————————————————

https://cloud.tencent.com/developer/ask/sof/61623

解决2 :

1:到JAVA_OPTIONS的-Dorg.apache.cxf.stax.allowInsecureParser=1

2:重命名woodstox-core-asl-4.4.1.jar -> awoodstox-core-asl-4.4.1.jar

 

你可能感兴趣的:(Java,java,前端,开发语言)