解决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中

<dependency>
	<groupId>org.apache.neethi</groupId>
	<artifactId>neethi</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.codehaus.woodstox</groupId>
			<artifactId>wstx-asl</artifactId>
		</exclusion>
		<exclusion>
			<groupId>wsdl4j</groupId>
			<artifactId>wsdl4j</artifactId>
		</exclusion>
	</exclusions>
</dependency>

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值