I've been searching for SOAP client libraries for Java and have found a plethora of libraries based on the idea of building stub and proxy classes based on a WSDL. I'm interested in allowing the user to enter a WSDL at runtime, parsing the WSDL, then allowing the user to perform operations on the Web Service.
Does anyone know of a good SOAP client library which will allow this runtime use? Or is there a way I can use the axis2 wsdl2java functionality to build stubs into the classloader and use them at runtime?
Best Answer
Later than never. :)
You should achieve that in two steps:
1) parse the WSDL informed by the user to retrieve the available operations. Refer to this question to know how to do this in a simple way.
2) Create a dynamic client to send a request using the selected operations. It can be done by using the Dispatch API from Apache CXF.
Build the
Dispatch
object for the dynamic client (It can be created on the fly by informing web service endpoint, port name, etc):Construct the request message (In the example below we are using DOMSource):
Invoke the web service
Recommendations:
((BindingProvider)dispatch).getRequestContext().put("thread.local.request.context", "true");
if you want to make the Dispatch object thread safe.Dispatch
object for using later, if it is the case. The process o building the object is not for free.Other Methods
There are other methods for creating dynamic clients, like using CXF dynamic-clients API. You can read in project's index page:
I haven't tried that myself but should worth giving it a try.