我想使用使用CXF保护的webservice。(http://host:port/test/ws?wsdl)。下面是我的密码。但它给出了以下的例外情况。在SoapUI中,我已经测试了webservice。我已经在"aut“选项卡下给出了SoapUI的凭据。它起作用了。您能告诉我如何使用CXF来使用安全的CXF服务吗?
ProcessService proxy = new ProcessService(wsdlURL, SERVICE_NAME);
try {
IProcessService port = proxy.getBinding1IProcessService();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getAuthorization().setUserName("username");
http.getAuthorization().setPassword("password");
System.out.println("Result=" + port.startReturnDDCStatusForAC(""));
} catch (Exception e) {
e.printStackTrace();
}例外:
Okt 09, 2012 7:23:50 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://tempuri.org/}ProcessService from WSDL: http://sn000333.tauri.ch:61527/WS/Process?wsdl
Okt 09, 2012 7:24:02 PM org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl handleNoRegisteredBuilder
WARNING: No assertion builder for type {http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered.
org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied.
at org.apache.cxf.ws.policy.EndpointPolicyImpl.chooseAlternative(EndpointPolicyImpl.java:165)
at org.apache.cxf.ws.policy.EndpointPolicyImpl.finalizeConfig(EndpointPolicyImpl.java:145)
at org.apache.cxf.ws.policy.EndpointPolicyImpl.initialize(EndpointPolicyImpl.java:141)
at org.apache.cxf.ws.policy.PolicyEngineImpl.createEndpointPolicyInfo(PolicyEngineImpl.java:549)
at org.apache.cxf.ws.policy.PolicyEngineImpl.getEndpointPolicy(PolicyEngineImpl.java:295)
at org.apache.cxf.ws.policy.PolicyEngineImpl.getClientEndpointPolicy(PolicyEngineImpl.java:278)
at org.apache.cxf.ws.policy.PolicyDataEngineImpl.getClientEndpointPolicy(PolicyDataEngineImpl.java:61)
at org.apache.cxf.transport.http.HTTPConduit.updateClientPolicy(HTTPConduit.java:318)
at org.apache.cxf.transport.http.HTTPConduit.<init>(HTTPConduit.java:303)
at org.apache.cxf.transport.http.HTTPTransportFactory.getConduit(HTTPTransportFactory.java:250)
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:228)
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:235)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:103)
at org.apache.cxf.endpoint.UpfrontConduitSelector.selectConduit(UpfrontConduitSelector.java:77)
at org.apache.cxf.endpoint.ClientImpl.getConduit(ClientImpl.java:842)
at com.test.TestWS.main(TestWS.java:66)SOAPUI测试:
在aut选项卡下,我已经给出了下面的说明,它正在起作用。授权类型:抢占用户名:用户名密码:密码
发布于 2012-10-10 08:08:18
也许您可以尝试通过扩展MyBasicAuthSupplier和重写getPreemptiveUserPass.来创建自己的getPreemptiveUserPass.。然后,可以使用setAuthSupplier方法将新类的实例设置为HTTPConduit。
这可能会更有用。
http://alvinalexander.com/java/jwarehouse/apache-cxf/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java.shtml
干杯。
https://stackoverflow.com/questions/12805427
复制相似问题