我正在通过给定的 3rd-party wsdl 实现 web 服务客户端,我想确保我能够直接发送 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 生成 web 服务客户端(链接如下: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 警告:没有注册类型 {http://www.xxxxx.com/module/throttle}ServiceThrottleAssertion 的断言生成器。 线程“主”javax.xml.ws.soap.SOAPFaultException 中的异常:无法满足任何备选策略。
我还能说的是我的开发环境:
操作系统SP3 Java 1.6.0_027 Apache-CXF 2.6.0 雄猫 6.0.35 日食靛蓝 SR1 动态网页模块 2.5
我将不胜感激任何线索和帮助。