Reputation: 51
I would like to consume a webservice which is secured using CXF. (http://host:port/test/ws?wsdl). Below is my code. but it is giving the exception given below. In SoapUI i have tested the webservice. I have given credentials in SoapUI under "aut" tab. It was working. Could you please tell how to consume secured webservice using 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();
}
Exception:
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 test:
Under aut tab , i have given below deatils and it is working. Authorisation type: preemptive username: username password: password
Upvotes: 4
Views: 3245
Reputation: 649
Maybe you can try to make your own MyBasicAuthSupplier by extending HttpBasicAuthSupplier and overriding getPreemptiveUserPass. Then you can set instance of new class to HTTPConduit using setAuthSupplier method.
This will probably be more useful.
Cheers.
Upvotes: 0