Later than never. :)
You must achieve this in two steps:
1) disassemble the user-informed WSDL to obtain available operations. Refer to this question to find out how to do this in a simple way.
2) Create a dynamic client to send a request using the selected operations. This can be done using the Dispatch API from Apache CXF .
Create a Dispatch object for a dynamic client (you can create it on the fly by telling the endpoint of the web service, port name, etc.):
package com.mycompany.demo; import javax.xml.namespace.QName; import javax.xml.ws.Service; public class Client { public static void main(String args[]) { QName serviceName = new QName("http://org.apache.cxf", "stockQuoteReporter"); Service s = Service.create(serviceName); QName portName = new QName("http://org.apache.cxf", "stockQuoteReporterPort"); Dispatch<DOMSource> dispatch = s.createDispatch(portName, DOMSource.class, Service.Mode.PAYLOAD); ... } }
Build a request message (In the example below, we use a DOMSource ):
// Creating a DOMSource Object for the request DocumentBuilder db = DocumentBuilderFactory.newDocumentBuilder(); Document requestDoc = db.newDocument(); Element root = requestDoc.createElementNS("http://org.apache.cxf/stockExample", "getStockPrice"); root.setNodeValue("DOW"); DOMSource request = new DOMSource(requestDoc);
Web service call
Recommendations:
- Use
((BindingProvider)dispatch).getRequestContext().put("thread.local.request.context", "true"); if you want the Dispatch object stream to be safe. - Download the
Dispatch object for later use, if so. The process of creating an object is not free.
Other methods
There are other methods for creating dynamic clients, for example, using the CXF dynamic-clients API. You can read on the project index page:
CXF supports several alternatives allowing the application to communicate with the service without SEI classes and data
I have not tried it myself, but it's worth a try.
source share