I want to develop a SOAP web service with TDD. The web service is build on Apache CXF and protected with basic authentication. My idea is to set up the unit tests with the help of a dynamic client to avoid the creation process of the proxy.
The documentation shows how to create a 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);
Ok, that looks promising. But how can I specify username and password for basic authentication? Both WSDL and the service itself are protected with basic authentication.
Bye,
Olaf
I have taken a look at the source code of Apache CXF. I think the current version of CXF (2.3.1) is not able to retrieve a WSDL from a URL which is protected with basic authentication. Usually you create a dynamic client in this way:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(
"http://localhost:8080/ws-auth/EchoService?wsdl");
Unfortunately you will get a ServiceConstructionException in return:
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)
...
I couldn't find any place to set the credentials for basic authentication. As a workaround I could download the WSDL with the help of a second tool (maybe httpclient) and store it in a temporary folder. CXF could consume this file and would go one with the creation of the client. I tried this way but I had no luck. Another exception came up. Which was not a surprise because I was not able to find out how to hand over the credentials to the dynamically created client. The documentation of Apache CXF could be more extensive.
Frankly speaking I'm not sure anymore whether Apache CXF is the best option for the task. Does anybody know a tool or framework which supports testing of SOAP webservices in an easy way? As I mentioned before it should create the service proxy dynamically by parsing the WSDL. Maybe there are working solutions outside of the java world. How do the Ruby- or the Python guys handle this problem? Maybe I can adopt their approaches by using JRuby or Jython in my unit tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With