You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ellen <el...@163.com> on 2015/06/18 16:46:07 UTC

How can cxf know and get custom ws-policy?

Hi all,

I would like to use a new custom ws-policy, and would like to let cxf know
and check it, I see there is a link about that, but there is no E2E code so
that my development is not work for me, could you please help me double
check which step is wrong? Appreciate it! :)
http://cxf.apache.org/docs/developing-assertions.html

My custom policy like this:
<wsat:ATAssertion wsp:optional="true" />
    
</wsp:Policy>

Question 1:
Need I develop AssertionBuilder and Policy-Aware Interceptor to know this
custom policy?

Or I just need write an interceptor before PolicyInInterceptor, and then
run:
 public void handleMessage(Message message) {
 
      // get AssertionInfoMap
       org.apache.cxf.ws.policy.AssertionInfoMap aim = 
           message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
       Collection<AssertionInfo ais> = aim.get(assertionType );
 
       // extract Assertion information
       for (AssertionInfo ai : ais) {
           org.apache.neethi.Assertion a = ai.getAssertion();
           MyAssertionType ma = (MyAssertionType)a;
          // digest ....
       }
 
       // process message ...
            // express support
 
       for (AssertionInfo ai : ais) {
           ai.setAsserted(...);
       }          }
}
To set assertion?


Question 2:
If question 1 is not, I need complete full flow of policy development,
what's the correct step?

1, Implementing the AssertionBuilder, complete build and getKnownElements
method, and return my Assertion object in build method.

2, Implement Policy-Aware Interceptor and MyInterceptorProvider,
in the interceptor, what I should do is:
// get AssertionInfoMap
       org.apache.cxf.ws.policy.AssertionInfoMap aim = 
           message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
       Collection<AssertionInfo ais> = aim.get(assertionType );
 
       // extract Assertion information
       for (AssertionInfo ai : ais) {
           org.apache.neethi.Assertion a = ai.getAssertion();
           MyAssertionType ma = (MyAssertionType)a;
          // digest ....
       }
 
       // process message ...
            // express support
 
       for (AssertionInfo ai : ais) {
           ai.setAsserted(...);
       }          }
to set Assertion?


And in MyInterceptorProvider is add these interceptor?
 public MyInterceptorProvider() {
        super(ASSERTION_TYPES);
        getInInterceptors().add(IN_INTERCEPTOR);        
        getOutInterceptors().add(OUT_INTERCEPTOR);        
        getOutFaultInterceptors().add(OUT_FAULT_INTERCEPTOR);        
    }
But where to add them? before PolicyInInterceptor and PolicyOutInterceptor?

Then add these in META-INF/cxf/bus-extensions.txt
org.company.MyInterceptorProvider::true
org.company.MyAssertionBuilder::true


Question 3:
If I implement AssertionBuilder and Policy-Aware Interceptor, Need I
implement a Policy-Aware Conduit/Destination?


Question 4:

Do you have a full E2E document or link, so  that I can deeply study?
I cannot search detail article in Google....

Great thanks a lot!



--
View this message in context: http://cxf.547215.n5.nabble.com/How-can-cxf-know-and-get-custom-ws-policy-tp5758385.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: How can cxf know and get custom ws-policy?

Posted by ellen <el...@163.com>.
Hi Daniel and Andrei,

Great thanks for your help. After follow your info and instruction, my
custom policy assertion works in my code.

Thanks! :)



--
View this message in context: http://cxf.547215.n5.nabble.com/How-can-cxf-know-and-get-custom-ws-policy-tp5758385p5758508.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: How can cxf know and get custom ws-policy?

Posted by Andrei Shakirin <as...@talend.com>.
Hi Ellen,

Regarding 4: 
take a look into http://ashakirin.blogspot.de/2012/02/using-ws-policy-in-cxf-projects.html .
For code example you can take any assertion in CXF and see how it implemented: https://github.com/apache/cxf/tree/master/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/policy

Regards,
Andrei.

> -----Original Message-----
> From: ellen [mailto:ellenxiao0220@163.com]
> Sent: Donnerstag, 18. Juni 2015 16:46
> To: users@cxf.apache.org
> Subject: How can cxf know and get custom ws-policy?
> 
> Hi all,
> 
> I would like to use a new custom ws-policy, and would like to let cxf know and
> check it, I see there is a link about that, but there is no E2E code so that my
> development is not work for me, could you please help me double check which
> step is wrong? Appreciate it! :) http://cxf.apache.org/docs/developing-
> assertions.html
> 
> My custom policy like this:
> <wsat:ATAssertion wsp:optional="true" />
> 
> </wsp:Policy>
> 
> Question 1:
> Need I develop AssertionBuilder and Policy-Aware Interceptor to know this
> custom policy?
> 
> Or I just need write an interceptor before PolicyInInterceptor, and then
> run:
>  public void handleMessage(Message message) {
> 
>       // get AssertionInfoMap
>        org.apache.cxf.ws.policy.AssertionInfoMap aim =
>            message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
>        Collection<AssertionInfo ais> = aim.get(assertionType );
> 
>        // extract Assertion information
>        for (AssertionInfo ai : ais) {
>            org.apache.neethi.Assertion a = ai.getAssertion();
>            MyAssertionType ma = (MyAssertionType)a;
>           // digest ....
>        }
> 
>        // process message ...
>             // express support
> 
>        for (AssertionInfo ai : ais) {
>            ai.setAsserted(...);
>        }          }
> }
> To set assertion?
> 
> 
> Question 2:
> If question 1 is not, I need complete full flow of policy development, what's the
> correct step?
> 
> 1, Implementing the AssertionBuilder, complete build and getKnownElements
> method, and return my Assertion object in build method.
> 
> 2, Implement Policy-Aware Interceptor and MyInterceptorProvider, in the
> interceptor, what I should do is:
> // get AssertionInfoMap
>        org.apache.cxf.ws.policy.AssertionInfoMap aim =
>            message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
>        Collection<AssertionInfo ais> = aim.get(assertionType );
> 
>        // extract Assertion information
>        for (AssertionInfo ai : ais) {
>            org.apache.neethi.Assertion a = ai.getAssertion();
>            MyAssertionType ma = (MyAssertionType)a;
>           // digest ....
>        }
> 
>        // process message ...
>             // express support
> 
>        for (AssertionInfo ai : ais) {
>            ai.setAsserted(...);
>        }          }
> to set Assertion?
> 
> 
> And in MyInterceptorProvider is add these interceptor?
>  public MyInterceptorProvider() {
>         super(ASSERTION_TYPES);
>         getInInterceptors().add(IN_INTERCEPTOR);
>         getOutInterceptors().add(OUT_INTERCEPTOR);
>         getOutFaultInterceptors().add(OUT_FAULT_INTERCEPTOR);
>     }
> But where to add them? before PolicyInInterceptor and PolicyOutInterceptor?
> 
> Then add these in META-INF/cxf/bus-extensions.txt
> org.company.MyInterceptorProvider::true
> org.company.MyAssertionBuilder::true
> 
> 
> Question 3:
> If I implement AssertionBuilder and Policy-Aware Interceptor, Need I
> implement a Policy-Aware Conduit/Destination?
> 
> 
> Question 4:
> 
> Do you have a full E2E document or link, so  that I can deeply study?
> I cannot search detail article in Google....
> 
> Great thanks a lot!
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-can-cxf-
> know-and-get-custom-ws-policy-tp5758385.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: How can cxf know and get custom ws-policy?

Posted by Daniel Kulp <dk...@apache.org>.
1)  Depends.  If you actually need to act on the policy (and fail/fault if the policy is not met) in one way or another, then yes.  If the policy is more informational and not something you need to really assert, then no.  You can use the IgnorablePolicyInterceptorProvider to have the policy “asserted” without really doing anything.

2) Looks correct.  All interceptors you add should be AFTER the Policy*Interceptors as the effective policy is computed there, then subsequence interceptors would have to assert true/false the assertions that have been met.

3) No

4) None that I’m aware of.

Dan



> On Jun 18, 2015, at 10:46 AM, ellen <el...@163.com> wrote:
> 
> Hi all,
> 
> I would like to use a new custom ws-policy, and would like to let cxf know
> and check it, I see there is a link about that, but there is no E2E code so
> that my development is not work for me, could you please help me double
> check which step is wrong? Appreciate it! :)
> http://cxf.apache.org/docs/developing-assertions.html
> 
> My custom policy like this:
> <wsat:ATAssertion wsp:optional="true" />
> 
> </wsp:Policy>
> 
> Question 1:
> Need I develop AssertionBuilder and Policy-Aware Interceptor to know this
> custom policy?
> 
> Or I just need write an interceptor before PolicyInInterceptor, and then
> run:
> public void handleMessage(Message message) {
> 
>      // get AssertionInfoMap
>       org.apache.cxf.ws.policy.AssertionInfoMap aim = 
>           message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
>       Collection<AssertionInfo ais> = aim.get(assertionType );
> 
>       // extract Assertion information
>       for (AssertionInfo ai : ais) {
>           org.apache.neethi.Assertion a = ai.getAssertion();
>           MyAssertionType ma = (MyAssertionType)a;
>          // digest ....
>       }
> 
>       // process message ...
>            // express support
> 
>       for (AssertionInfo ai : ais) {
>           ai.setAsserted(...);
>       }          }
> }
> To set assertion?
> 
> 
> Question 2:
> If question 1 is not, I need complete full flow of policy development,
> what's the correct step?
> 
> 1, Implementing the AssertionBuilder, complete build and getKnownElements
> method, and return my Assertion object in build method.
> 
> 2, Implement Policy-Aware Interceptor and MyInterceptorProvider,
> in the interceptor, what I should do is:
> // get AssertionInfoMap
>       org.apache.cxf.ws.policy.AssertionInfoMap aim = 
>           message.get(org.apache.cxf.ws.policy.AssertionInfoMap.class);
>       Collection<AssertionInfo ais> = aim.get(assertionType );
> 
>       // extract Assertion information
>       for (AssertionInfo ai : ais) {
>           org.apache.neethi.Assertion a = ai.getAssertion();
>           MyAssertionType ma = (MyAssertionType)a;
>          // digest ....
>       }
> 
>       // process message ...
>            // express support
> 
>       for (AssertionInfo ai : ais) {
>           ai.setAsserted(...);
>       }          }
> to set Assertion?
> 
> 
> And in MyInterceptorProvider is add these interceptor?
> public MyInterceptorProvider() {
>        super(ASSERTION_TYPES);
>        getInInterceptors().add(IN_INTERCEPTOR);        
>        getOutInterceptors().add(OUT_INTERCEPTOR);        
>        getOutFaultInterceptors().add(OUT_FAULT_INTERCEPTOR);        
>    }
> But where to add them? before PolicyInInterceptor and PolicyOutInterceptor?
> 
> Then add these in META-INF/cxf/bus-extensions.txt
> org.company.MyInterceptorProvider::true
> org.company.MyAssertionBuilder::true
> 
> 
> Question 3:
> If I implement AssertionBuilder and Policy-Aware Interceptor, Need I
> implement a Policy-Aware Conduit/Destination?
> 
> 
> Question 4:
> 
> Do you have a full E2E document or link, so  that I can deeply study?
> I cannot search detail article in Google....
> 
> Great thanks a lot!
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-can-cxf-know-and-get-custom-ws-policy-tp5758385.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com