Hi Ellen,

See the answers below:

> -----Original Message-----
> From: ellen [mailto:[email protected]]
> Sent: Dienstag, 8. Dezember 2015 13:15
> To: [email protected]
> Subject: Dynamically set policy via message property
> 
> Hi Dear all,
> 
> I'm using CXF and WS-Policy for my application.
> 
> And I want to dynamically set WS-Policy by uisng your way:
> http://cxf.apache.org/docs/how-to-define-policies.html
> 
> But I have some questions. could you please help me confirm? Appreciate it!
> :)
> 
> *1, Need I do in both Client and Server side?* Parse and Store result Policy
> object into PolicyConstants.POLICY_OVERRIDE message content property.
> Add an interceptor to do that.
> I can  easily add an interceptor in client side, but how can I do for server 
> side?

You can add interceptors on client as well as on the server side. There are 
some ways to do that:
a) Spring/blueprint configuration
b) programmatically through serverFactoryBean
c) using WS-Policy

Some ways are described in http://cxf.apache.org/docs/interceptors.html

> 
> 
> *2, Can I control which service or operation to use this policy?*
> 
> e.g. when using WSDL, we can add the policy into a service/operation, like:
> <wsdl:operation name="sayHelloToOther">
>         <wsp:PolicyReference URI="#myPolicy"
>                               wsdl:required="true" />
>       <soap:operation soapAction="" style="document" /> ......
> 
> So can I use this dynamic way and add policy to the fine-grained operation
> level?

Yes, basically you can determine service operation in your interceptor and 
decide (on the base of operation) which parsed policy should be applied.
For example this code extract operation name from the service model:

                   if ((message.getExchange() != null) &&
                        (message.getExchange().getBindingOperationInfo() != 
null) &&
                        
(message.getExchange().getBindingOperationInfo().getOperationInfo() != null)) {
                       QName operationName = 
message.getExchange().getBindingOperationInfo().getOperationInfo().getName();
                        }


> 
> Or every request will parse and use this policy?

The policy set using PolicyConstants.POLICY_OVERRIDE are valid only for current 
message.

> 
> 
> Thanks a lot! :)
> 
You welcome.

Regards,
Andrei.

> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Dynamically-
> set-policy-via-message-property-tp5763695.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to