cxf2.7.15-做爲webService客戶端遇到的問題

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

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

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

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

    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) ui

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

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

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

    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

 

 

二、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網站下載下來的壓縮包裏面的版本。

三、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包,以下:

相關文章
相關標籤/搜索