cxf2.7.15-作为webService客户端遇到的问题

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包,如下:cxf2.7.15-作为webService客户端遇到的问题_第1张图片

你可能感兴趣的:(cxf2.7.15-作为webService客户端遇到的问题)