Hi,

From the first view your code seems to be OK.

Could you please ensure two things in debugger:
1) in your CustomPolicyInterceptor : your policy was successfully parsed and 
set into message
2) in CXF PolicyOutInterceptor following code recognizes your policy and adds 
corresponded interceptors in chain:
        // 1. Check overridden policy
        Policy p = 
(Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
        if (p != null) {
            EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
            EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
            effectivePolicy.initialise(endpi, (PolicyEngineImpl)pe, false);
            msg.put(EffectivePolicy.class, effectivePolicy);
            PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: 
", 
                                  effectivePolicy.getPolicy());
            
            interceptors.addAll(effectivePolicy.getInterceptors());
            assertions.addAll(effectivePolicy.getChosenAlternative());
   }
?

Cheers,
Andrei.
   
> -----Original Message-----
> From: ankur [mailto:ankur.agarw...@yahoo.com]
> Sent: Donnerstag, 17. Januar 2013 05:28
> To: users@cxf.apache.org
> Subject: RE: Dynamicall​y define WS-Policy in CXF
> 
> Hi Andrei,
> 
> I am trying to add username token  policy from a policy server using  a custom
> policy interceptor for my webservice. the code for interceptor is
> 
> 
> public class CustomPolicyInterceptor extends
> AbstractPhaseInterceptor<SoapMessage> {
>        public CustomPolicyInterceptor(){
>                super(Phase.SETUP);
>               getBefore().add(PolicyOutInterceptor.class.getName());
> 
>       }
> 
> 
>       private static final long serialVersionUID = -5248428637449096540L;
> 
>        public void handleMessage(SoapMessage message)
>        {
> 
>                try{
> 
>                       PolicyBuilder builder =
> message.getExchange().getBus().getExtension(PolicyBuilder.class);
>                       InputStream is = new
> URL("http://localhost:8880/policy/policy.xml";).openStream();
>                        Policy effectivePolicy = builder.getPolicy(is) ;
>                          message.put(PolicyConstants.POLICY_OVERRIDE,
> effectivePolicy);
>                          }
>                catch(Exception e) {
>                               System.out.println("error");
>                       }
>        }
>        }
> 
> 
> and my bean.xml is
> 
> <beans xmlns="http://www.springframework.org/schema/beans";
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>     xmlns:jaxws="http://cxf.apache.org/jaxws";
>     xsi:schemaLocation="
>     http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd";>
> 
>     <import resource="classpath:META-INF/cxf/cxf.xml" />
>     <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml"
> />
> 
>  <bean id="myPasswordCallback" class="service.ServerPasswordCallback" />
> 
>      <jaxws:endpoint id="doubleit"
>         implementor="service.DoubleItPortTypeImpl"
>               wsdlLocation="wsdl/DoubleIt.wsdl"
>        address="/doubleitexternal">
>         <jaxws:outInterceptors>
>          <bean class="service.CustomPolicyInterceptor">
>          </bean>
>       </jaxws:outInterceptors>
>        <jaxws:properties>
>          <entry key="ws-security.callback-handler"
> value-ref="myPasswordCallback"/>
>       </jaxws:properties>
>     </jaxws:endpoint>
> 
> </beans>
> 
> 
> 
> But policy is not getting applied to my webservice. can you please tell me
> what changes I need to make.
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Dynamicall-
> y-define-WS-Policy-in-CXF-tp5713085p5721747.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to