How to create a dynamic webservice client with basic authentication using Apache CXF?

I want to create a SOAP web service with TDD. The web service is built on Apache CXF and is protected by basic authentication. My idea is to configure unit tests using a dynamic client to avoid the proxy creation process.

The documentation shows how to create dynamic client 1 :

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/OrderProcess?wsdl");
Object order = Thread.currentThread().getContextClassLoader()
    .loadClass("demo.order.Order").newInstance();
Method m1 = order.getClass().getMethod("setCustomerID", String.class);
m1.invoke(order, "C001");
Object[] response = client.invoke("processOrder", order);

Well, that looks promising. But how can I provide a username and password for basic authentication? Both the WSDL and the service itself are protected by basic authentication.

Bye,
Olaf

+3
source share
1 answer

Apache CXF. , CXF (2.3.1) WSDL URL-, . :

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(
    "http://localhost:8080/ws-auth/EchoService?wsdl");

, ServiceConstructionException:

org.apache.cxf.service.factory.ServiceConstructionException: 
Could not resolve URL "http://localhost:8080/ws-auth/EchoService?wsdl".
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.composeUrl(DynamicClientFactory.java:6)
...

. WSDL (, httpclient) . CXF . , . . , , . Apache CXF .

, , - Apache CXF. - , - SOAP ? , , WSDL. , java-. Ruby Python ? , , JRuby Jython .

+2

Source: https://habr.com/ru/post/1779665/


All Articles