Hi techlearner123,
> Has somebody used this functionality
Yes, it works since CXF 5.2.1. You should parse your policy using Neethi and
set it into PolicyConstants.POLICY_OVERRIDE message property.
Important that it should happens before CXF PolicyInInterceptor or
PolicyOutInterceptor are invoked.
CXF Policy Interceptors will check POLICY_OVERRIDE property first, if property
contains WS-Policy, it will be used. Otherwise CXF will try to retrieve policy
from Service Model or configuration.
Code for outgoing chain looks like:
public class PolicyControlOutInterceptor extends
AbstractPhaseInterceptor<SoapMessage> {
public PolicyControlOutInterceptor() {
super(Phase.SETUP);
getBefore().add(PolicyOutInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) {
try {
// 1. Build effective policy for response
org.apache.cxf.ws.policy.PolicyBuilder builder =
message.getExchange().getBus()
.getExtension(org.apache.cxf.ws.policy.PolicyBuilder.class);
Policy effectivePolicy = builder.getPolicy(xmlGenericPolicy) ;
// 2. Apply effective policy
message.put(PolicyConstants.POLICY_OVERRIDE, effectivePolicy);
...
} catch (Exception e) {
throw new PolicyControlException("Cannot build request
policy: "
+ e.getMessage(), e);
}
}
}
-----Original Message-----
From: techlearner123 [mailto:[email protected]]
Sent: 24 August 2012 12:26
To: [email protected]
Subject: Dynamically define WS-Policy in CXF
My question is in reference to link:
http://cxf.apache.org/docs/how-to-define-policies.html
In reference to Apache CXF documention for WS-Policy following point is
mentioned. Can someone provide more information on this.
Has somebody used this functionality. Any help will be appreciated.
Basically I am trying to apply some run time policies on webservices.
Dynamically via message property
Sometimes policies cannot be configured statically, because they are obtained
or calculated dynamically for concrete message (for example using Policy Server
or Service Registry). For such cases CXF provide a possibility to load policy
dynamically and set it into the message context property. It can be done for
example in custom interceptor that fulfils the following:
Get policy from external location and build it for current message.
Parse WS-Policy XML using Neethi library.
Store result Policy object into PolicyConstants.POLICY_OVERRIDE message content
property.
Important is that this custom policy interceptor is called before CXF
PolicyInInterceptor or PolicyOutInterceptor. Than CXF will automatically
recognize Policy stored into this property and use it with highest priority.
--
View this message in context:
http://cxf.547215.n5.nabble.com/Dynamicall-y-define-WS-Policy-in-CXF-tp5713085.html
Sent from the cxf-user mailing list archive at Nabble.com.