You should be able to use a Dispatch client to do something close to
this. Create a Dispatch client from the WSDL with policy attached like this:
Service service = Service.create(wsdlURL, new
QName(WSDL_NAMESPACE, SERVICE_LOCALNAME));
Dispatch<Source> disp = service.createDispatch(new
QName(WSDL_NAMESPACE, PORT_LOCALNAME),
Source.class, Service.Mode.PAYLOAD);
Then you can pass a StreamSource for the request body content to the
service, and get back the response body content:
Source request = new StreamSource(new FileInputStream(new
File(args[1])));
Source response = disp.invoke(request);
Transformer tran =
TransformerFactory.newInstance().newTransformer();
File outfile = new File("output.xml");
FileOutputStream fos = new FileOutputStream(outfile);
Result result = new StreamResult(fos);
tran.transform(response, result);
fos.close();
I don't know if the Policy will be picked up from the WSDL when you do
this. If not, you should be able to set the policy directly in a custom
interceptor, by parsing the Policy document using Apache Neethi and then
storing the resulting Policy object into
/PolicyConstants.POLICY_OVERRIDE/ message content property. Do a search
on this and you should see some examples.
- Dennis
Dennis M. Sosnoski
Java SOA and Web Services Consulting <http://www.sosnoski.com/consult.html>
CXF and Web Services Security Training
<http://www.sosnoski.com/training.html>
Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
On 08/26/2013 10:35 PM, Sam wrote:
Hi all,
Is it possible for CXF to apply WS-Policy to xml string representing
soap request directly?
I looked at all the demo client code I run for WSDL first web service
with WS-Policy and the client code is always generated by the maven
plugin cxf-codegen-plugin.
Nothing wrong with that. But looking at SoapUI makes me wander if it's
possible to simply feed XML string as soap request to CXF, then CXF
will do all the hard work of applying WS-Policy, just like SoapUI.
Thanks
Sam