cxf2.7.15-作为webService客户端遇到的问题
cxf2.7.15-作为webService客户端遇到的问题
johnny_chen 发表于3年前
cxf2.7.15-作为webService客户端遇到的问题
  • 发表于 3年前
  • 阅读 2410
  • 收藏 2
  • 点赞 0
  • 评论 0

【腾讯云】新注册用户域名抢购1元起>>>   

摘要: 与webservice服务端联动,报异常,需要的jar包尽量从Apache下载之后解压的目录\apache-cxf-2.7.15\lib中,找你需要依赖的jar包,不然会引起冲突。原来客户端使用的是cxf2.3.7,使用jdk1.6访问是没有问题的,但是我这边服务器是用的jdk1.7;使用jdk1.7搭配cxf2.3.7去访问服务端时,会报异常,javacTask:目标编译时1.5与源1.7冲突。为了解决冲突选择cxf2.7.15如Apache所述此版本与java7结合的更好。但这时候又会遇到新的问题。

1、Exception in thread "main" java.lang.NoSuchFieldError: QUALIFIED

    at org.apache.cxf.service.model.SchemaInfo.setSchema(SchemaInfo.java:146)

    at org.apache.cxf.wsdl11.SchemaUtil.extractSchema(SchemaUtil.java:143)

    at org.apache.cxf.wsdl11.SchemaUtil.getSchemas(SchemaUtil.java:73)

    at org.apache.cxf.wsdl11.SchemaUtil.getSchemas(SchemaUtil.java:65)

    at org.apache.cxf.wsdl11.SchemaUtil.getSchemas(SchemaUtil.java:60)

    at org.apache.cxf.wsdl11.WSDLServiceBuilder.getSchemas(WSDLServiceBuilder.java:372)

    at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:339)

    at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:196)

    at org.apache.cxf.wsdl11.WSDLServiceBuilder.buildServices(WSDLServiceBuilder.java:172)

    at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:125)

    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:298)

    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:240)

    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:233)

    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:188)

    at com.ruijie.test.WebServiceTest.testService(WebServiceTest.java:170)

    at com.ruijie.test.WebServiceTest.main(WebServiceTest.java:66)

以上的异常是由于采用的jar包与cxf版本不匹配导致的。原来使用的是XmlSchema-1.4.7.jar,将其删除修改为:xmlschema-core-2.1.0.jar

 

 

2、Exception in thread "main" java.lang.NoSuchMethodError: org.apache.ws.security.util.WSSecurityUtil.decodeAction(Ljava/lang/String;Ljava/util/List;Lorg/apache/ws/security/WSSConfig;)I

    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:200)

    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:141)

    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)

    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572)

    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481)

    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)

    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)

    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)

    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:341)

    at com.ruijie.test.WebServiceTest.testService(WebServiceTest.java:190)

    at com.ruijie.test.WebServiceTest.main(WebServiceTest.java:65)

以上的原因是由于(CXF 2.3.3 needs WSS4J 1.5.x. CXF 2.4.x uses WSS4J 1.6.x.(转)),cxf2.7.15使用的wss4j应该是用从Apache网站下载下来的压缩包里面的版本。

3、Exception in thread "main" org.apache.cxf.binding.soap.SoapFault: An error was discovered processing the <wsse:Security> header
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:849)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1626)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1515)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1317)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632)
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:572)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:341)
at com.ruijie.test.WebServiceTest.testService(WebServiceTest.java:180)
at com.ruijie.test.WebServiceTest.main(WebServiceTest.java:65)

以上异常引起的原因,我所调用的服务端加了security控制,在使用client.invoke()之前,应该进行安全处理,安全处理要用到wss4j(WebServiceSecurityForJava)这个jar了。

WSS4J实现了WS-Security,是AXIS的安全模块,但也可以用于其他Web Services框架(例如XFIRE,CXF)。
WSS4J在Web Services框架中以handler方式工作,在发送SOAP消息前进行签名、加入认证凭据和加密,在收到SOAP消息后进行解密、认证和验证签名等安全工作。使用者可以自己编写handler处理SOAP消息以保证安全。以下是客户端调用的部分代码


JaxWsDynamicClientFactory dynamicClient = JaxWsDynamicClientFactory.newInstance();
        Client client = dynamicClient.createClient("your wsdl");
        Map<String, Object> props = new HashMap<String, Object>();  
        props.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);        
        props.put(WSHandlerConstants.PASSWORD_TYPE,WSConstants.PW_TEXT);  
        props.put(WSHandlerConstants.USER, "server");  
        props.put(WSHandlerConstants.PW_CALLBACK_CLASS, TestPasswordHandler.class.getName());  
        WSS4JOutInterceptor outintercept = new WSS4JOutInterceptor(props);
        client.getOutInterceptors().add(outintercept);
        client.getOutInterceptors().add(new SAAJOutInterceptor());
        Object[] rets = client.invoke("your server mehtod","params");



 客户端依赖的jar包,如下:

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 0
博文 7
码字总数 48422
×
johnny_chen
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: