我们正在尝试使用 Camel CXf 组件调用 Secured Webservice。WSDL 中定义了 wsp:Policy,我可以通过传递用户名/密码成功地从soapUI 调用服务,但是如果我尝试使用 Camel-Cxf 组件调用服务或使用生成的存根调用服务,则会面临很多问题。任何帮助表示赞赏。
WSDL 中定义了以下策略。
<wsp:Policy wsu:Id="WSHttpBinding_ReferenceLookupLists_policy">
<wsp:ExactlyOne>
<wsp:All>
<http:BasicAuthentication
xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http"/>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
蓝图文件中的 Cxf 端点:
<camel-cxf:cxfEndpoint id="abclookupEndpoint"
wsdlURL="wsdl/abclookupLists.wsdl"
endpointName="tns:WSHttpBinding_abclookup"
serviceName="tns:abclookup"
address="http://abc.abc/2013/12/6/abclookup.svc"
xmlns:tns="http://abc.abc/2013/12/6/ServiceContracts/">
<camel-cxf:outInterceptors>
<ref component-id="abcOutInterceptor"/>
</camel-cxf:outInterceptors>
<camel-cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</camel-cxf:properties>
</camel-cxf:cxfEndpoint>
Route Builder 类使用上面定义的 cxf 端点 @Override public void configure() throws Exception {
from("direct:retrieveData").routeId(getRouteId().concat("svc.refLookupList"))
.log(LoggingLevel.DEBUG, "Entered into direct:retrieveData route")
.setHeader("operationName", constant("GetCustomFieldDropdownList"))
.setHeader("SOAPAction",constant(getSoapActionHeader()))
.bean("soapRequestBean","constructRequest")
.to("cxf:bean:abclookupEndpoint?username=aaaaaaaa&password=bbbbbbbb")
.log(LoggingLevel.INFO, "Service Response : ${body}")
.end();
尝试像下面一样添加 AuthorizationPolicy 但没有帮助 Map properties = new HashMap();
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
authPolicy.setUserName("aaaaaaaa");
authPolicy.setPassword("bbbbbbbb");
authPolicy.setAuthorization("true");
properties.put("org.apache.cxf.configuration.security.AuthorizationPolicy",authPolicy);
CxfEndpoint myCxfEp = (CxfEndpoint)getContext().getEndpoint("cxf:bean:abclookupEndpoint");
myCxfEp.setProperties(properties);*/
尝试调用服务时日志中的异常消息:
"No assertion builder for type http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered. Exception in thread "main" org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives"