You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sam <j2...@gmail.com> on 2013/08/26 12:35:34 UTC
Apply WS-Policy to XML string representing soap request?
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
Re: Apply WS-Policy to XML string representing soap request?
Posted by Sam <j2...@gmail.com>.
Thanks Dennis. Will try that in next few days.
Regards,
Sam
On 27/08/2013 12:21 a.m., Dennis Sosnoski wrote:
> 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
>>
>
>
Re: Apply WS-Policy to XML string representing soap request?
Posted by Dennis Sosnoski <dm...@sosnoski.com>.
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
>
RE: Apply WS-Policy to XML string representing soap request?
Posted by Andrei Shakirin <as...@talend.com>.
Hi Dennis,
Yes, it should be possible to use policies from WSDL in case of Dispatch client:
Service service = new Service(wsdl, SERVICE_NAME);
Dispatch<Source> dispatch = service.createDispatch(PORT_NAME, Source.class, Service.Mode.PAYLOAD);
Of course, implementing own interceptor, parse policy using Neethy and applying to message property PolicyConstants.POLICY_OVERRIDE is also possible way, but requires more implementation efforts.
Regards,
Andrei.
> -----Original Message-----
> From: Dennis Sosnoski [mailto:dms@sosnoski.com]
> Sent: Dienstag, 27. August 2013 01:05
> To: users@cxf.apache.org
> Subject: Re: Apply WS-Policy to XML string representing soap request?
>
> Hi Andrei,
>
> Do you know if the policy would be picked up from the WSDL in this case,
> with a Dispatch client? If not, what's the easiest way to set it in the client
> code? I mentioned using an interceptor, but that seems more complex than
> necessary.
>
> Thanks,
>
> - Dennis
>
> On 08/27/2013 12:27 AM, Andrei Shakirin wrote:
> > Hi,
> >
> > You can specify policy using jaxws.features in this case, example of spring
> configuration:
> >
> > <jaxws:client id="CRMServiceClient"
> name="{http://services.talend.org/CRMService}CRMServiceProvider"
> > xmlns:serviceNamespace="http://services.talend.org/CRMService"
> > serviceClass="org.talend.services.crmservice.CRMService"
> > serviceName="serviceNamespace:CRMServiceProvider"
> > endpointName="serviceNamespace:CRMServicePort"
> > address="${endpoint.prefix}/CRMServiceProvider">
> > <jaxws:features>
> > <p:policies>
> > <wsp:PolicyReference URI="classpath:/saml.policy"/>
> > </p:policies>
> > </jaxws:features>
> > </jaxws:client>
> >
> > See http://cxf.apache.org/docs/how-to-define-policies.html for details.
> >
> > Regards,
> > Andrei.
> >
> >> -----Original Message-----
> >> From: Sam [mailto:j2eedodo@gmail.com]
> >> Sent: Montag, 26. August 2013 12:36
> >> To: users@cxf.apache.org
> >> Subject: Apply WS-Policy to XML string representing soap request?
> >>
> >> 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
Re: Apply WS-Policy to XML string representing soap request?
Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Hi Andrei,
Do you know if the policy would be picked up from the WSDL in this case,
with a Dispatch client? If not, what's the easiest way to set it in the
client code? I mentioned using an interceptor, but that seems more
complex than necessary.
Thanks,
- Dennis
On 08/27/2013 12:27 AM, Andrei Shakirin wrote:
> Hi,
>
> You can specify policy using jaxws.features in this case, example of spring configuration:
>
> <jaxws:client id="CRMServiceClient" name="{http://services.talend.org/CRMService}CRMServiceProvider"
> xmlns:serviceNamespace="http://services.talend.org/CRMService"
> serviceClass="org.talend.services.crmservice.CRMService"
> serviceName="serviceNamespace:CRMServiceProvider"
> endpointName="serviceNamespace:CRMServicePort"
> address="${endpoint.prefix}/CRMServiceProvider">
> <jaxws:features>
> <p:policies>
> <wsp:PolicyReference URI="classpath:/saml.policy"/>
> </p:policies>
> </jaxws:features>
> </jaxws:client>
>
> See http://cxf.apache.org/docs/how-to-define-policies.html for details.
>
> Regards,
> Andrei.
>
>> -----Original Message-----
>> From: Sam [mailto:j2eedodo@gmail.com]
>> Sent: Montag, 26. August 2013 12:36
>> To: users@cxf.apache.org
>> Subject: Apply WS-Policy to XML string representing soap request?
>>
>> 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
Re: Apply WS-Policy to XML string representing soap request?
Posted by Sam <j2...@gmail.com>.
Thanks Andrei,
Sam
On 27/08/2013 12:27 a.m., Andrei Shakirin wrote:
> Hi,
>
> You can specify policy using jaxws.features in this case, example of spring configuration:
>
> <jaxws:client id="CRMServiceClient" name="{http://services.talend.org/CRMService}CRMServiceProvider"
> xmlns:serviceNamespace="http://services.talend.org/CRMService"
> serviceClass="org.talend.services.crmservice.CRMService"
> serviceName="serviceNamespace:CRMServiceProvider"
> endpointName="serviceNamespace:CRMServicePort"
> address="${endpoint.prefix}/CRMServiceProvider">
> <jaxws:features>
> <p:policies>
> <wsp:PolicyReference URI="classpath:/saml.policy"/>
> </p:policies>
> </jaxws:features>
> </jaxws:client>
>
> See http://cxf.apache.org/docs/how-to-define-policies.html for details.
>
> Regards,
> Andrei.
>
>> -----Original Message-----
>> From: Sam [mailto:j2eedodo@gmail.com]
>> Sent: Montag, 26. August 2013 12:36
>> To: users@cxf.apache.org
>> Subject: Apply WS-Policy to XML string representing soap request?
>>
>> 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
RE: Apply WS-Policy to XML string representing soap request?
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
You can specify policy using jaxws.features in this case, example of spring configuration:
<jaxws:client id="CRMServiceClient" name="{http://services.talend.org/CRMService}CRMServiceProvider"
xmlns:serviceNamespace="http://services.talend.org/CRMService"
serviceClass="org.talend.services.crmservice.CRMService"
serviceName="serviceNamespace:CRMServiceProvider"
endpointName="serviceNamespace:CRMServicePort"
address="${endpoint.prefix}/CRMServiceProvider">
<jaxws:features>
<p:policies>
<wsp:PolicyReference URI="classpath:/saml.policy"/>
</p:policies>
</jaxws:features>
</jaxws:client>
See http://cxf.apache.org/docs/how-to-define-policies.html for details.
Regards,
Andrei.
> -----Original Message-----
> From: Sam [mailto:j2eedodo@gmail.com]
> Sent: Montag, 26. August 2013 12:36
> To: users@cxf.apache.org
> Subject: Apply WS-Policy to XML string representing soap request?
>
> 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