我正在通过给定的第三方wsdl实现webservice客户端,我想确保我能够直接发送SOAP请求,所以我使用soapUI生成请求,发送了2个参数:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:alm="http://www.xxxxx.com/services/2011/10/Thirdparty" xmlns:ns="http://www.xxxxx.com/AlmedaDataDistribution/2011/10">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>dummyUsername</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">dummyPassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<alm:method>
<ns:param1>dummyParam1</ns:param1>
<ns:param1>dummyParam2</ns:param2>
</alm:method>
</soapenv:Body>
</soapenv:Envelope>
得到了如下响应,似乎没问题:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<methodResponse xmlns="http://www.xxxxx.com/services/2011/10/Thirdparty">
<theResponse xmlns="http://www.xxxxx.com/Thirdparty/2011/10">
<asdf>abc-1</asdf>
<qwer>123-1</qwer>
</theResponse>
<theResponse xmlns="http://www.xxxxx.com/Thirdparty/2011/10">
<asdf>abc-2</asdf>
<qwer>123-2</qwer>
</theResponse>
</methodResponse>
</soapenv:Body>
</soapenv:Envelope>
然后我开始从WSDL生成webservice客户端(像这样的链接:https://www.xxxxx.com/ThirdpartyService?wsdl)由于eclipse不支持直接从HTTPS链接生成,所以我下载了.wsdl和依赖的.xsd文件并生成客户本地。生成后,我修改了客户端,通过apache-cxf API添加了用户名和密码
ThirdpartyService ss = new ThirdpartyService();
ThirdpartyServicePortType port = ss.getThirdpartyServiceSOAP11PortHttps();
Client client = ClientProxy.getClient(port);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, "dummyusername");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
ss.method(param1,param2);
然而,当我开始运行客户端时,我得到了以下奇怪的异常(似乎与WS-Security的东西无关):
org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl handleNoRegisteredBuilder WARNING: No assertion builder for type {http://www.xxxxx.com/module/throttle}ServiceThrottleAssertion registered. Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: None of the policy alternatives can be satisfied.
我能说的是我的开发者:
WinXP SP3 Java 1.6.0_027 Apache-CXF 2.6.0 Tomcat 6.0.35 eclipse Indigo SR1 Dynamic Web Module 2.5
我会感激任何线索和帮助。
答案 0 :(得分:1)
我忘了告诉我在此期间意外使用axis1.4实现了客户端并暂时解决了我的问题。但我仍然不明白为什么这个webservice(似乎)框架依赖。