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/07/01 15:45:52 UTC

Cannot get ws-policy assertion when wsp:Optional set true?

Hi dear all,

I'm developing a custom ws-policy by using cxf. Everything works fine,
except I see when I add wsp:Optional=true in my custom policy in wsdl, I can
get assertion in my client out interceptor, but cannot get in the server
side in interceptor, The AssertionMap is null, I see there is also some
question about the Optional setting problem in ws-addressing in forum. Not
sure anyone can help me take a look if there is something wrong in my config
or some is some issue in cxf? Appreciate it! :)

My Assertion is very sample, just need to check isOptioanl and isIgnorable.
no need any other element check.

Here is my step:
*1, Create a my AssertionBuilder, in check Optional and Ignorable value in
build method and generate a new Assertion:*
public class MyAssertionBuilder implements AssertionBuilder<Element>{
    public Assertion build(Element element, AssertionBuilderFactory factory)
                    throws IllegalArgumentException {
Dummy code:
Assertion assertion = new Assertion();
assertion.setOptional(PolicyConstants.isOptional(element));
assertion.setIgnorable(PolicyConstants.isIgnorable(element));
return assertion
.....


*2, Create an Interceptor to assert my Assertion:*
    public void handleMessage(SoapMessage message) throws Fault
    {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (null == aim)
        {
            return;
        }

        Collection<AssertionInfo> ais = aim.get(My.ASSERTION_QNAME);
        if (null == ais || ais.size() == 0)
        {
            return;
        }
        for (AssertionInfo ai : ais)
        {
            ai.setAsserted(true);
        }
    }


3, Create my PolicyBuilder to add Interceptor in in and out for my
ASSERTION_TYPES:
    public MyAssertionPolicyProvider() {
        super(ASSERTION_TYPES);
        getInInterceptors().add(IN_INTERCEPTOR);
        getOutInterceptors().add(OUT_INTERCEPTOR);
...

Add InInterceptor in phase PRE_PROTOCOL and also outInterceptor in phase
PRE_PROTOCOL


4, Add them in cxf-extensions.txt file.


Then I verify my policy, when debug in out MyPolicyInterceptor in client
side, AssertionInfoMap is not null, I can get my Assertion successfully.

But when running in server side in in MyPolicyInterceptor, the
AssertionInfoMap is null, I cannot get Assertion, its' null....


So I'm confuse why after set wsp:Optional=true everything works in out
Interceptor in client side and not work in in Interceptor in server side.
But if set wsp:Optional=false or doesn't set Optional parameter, everything
works fine in both side.


Not sure if there is issue in cxf for Optional=true situation?

Or could you please let me know if there is any way to debug or narrow down
my problem?

Great thanks a lot! :)



--
View this message in context: http://cxf.547215.n5.nabble.com/Cannot-get-ws-policy-assertion-when-wsp-Optional-set-true-tp5758740.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Cannot get ws-policy assertion when wsp:Optional set true?

Posted by Colm O hEigeartaigh <co...@apache.org>.
Hi Ellen,

The issue appears to be that CXF does not register optional policies on the
server side. As you have only one policy, this means that no valid policy
is registered and hence the AssertionInfoMap Object is null. This looks
like a bug in CXF to me, but I'm not sure what the impact of changing this
would be.

Colm.

On Wed, Jul 1, 2015 at 2:45 PM, ellen <el...@163.com> wrote:

> Hi dear all,
>
> I'm developing a custom ws-policy by using cxf. Everything works fine,
> except I see when I add wsp:Optional=true in my custom policy in wsdl, I
> can
> get assertion in my client out interceptor, but cannot get in the server
> side in interceptor, The AssertionMap is null, I see there is also some
> question about the Optional setting problem in ws-addressing in forum. Not
> sure anyone can help me take a look if there is something wrong in my
> config
> or some is some issue in cxf? Appreciate it! :)
>
> My Assertion is very sample, just need to check isOptioanl and isIgnorable.
> no need any other element check.
>
> Here is my step:
> *1, Create a my AssertionBuilder, in check Optional and Ignorable value in
> build method and generate a new Assertion:*
> public class MyAssertionBuilder implements AssertionBuilder<Element>{
>     public Assertion build(Element element, AssertionBuilderFactory
> factory)
>                     throws IllegalArgumentException {
> Dummy code:
> Assertion assertion = new Assertion();
> assertion.setOptional(PolicyConstants.isOptional(element));
> assertion.setIgnorable(PolicyConstants.isIgnorable(element));
> return assertion
> .....
>
>
> *2, Create an Interceptor to assert my Assertion:*
>     public void handleMessage(SoapMessage message) throws Fault
>     {
>         AssertionInfoMap aim = message.get(AssertionInfoMap.class);
>         if (null == aim)
>         {
>             return;
>         }
>
>         Collection<AssertionInfo> ais = aim.get(My.ASSERTION_QNAME);
>         if (null == ais || ais.size() == 0)
>         {
>             return;
>         }
>         for (AssertionInfo ai : ais)
>         {
>             ai.setAsserted(true);
>         }
>     }
>
>
> 3, Create my PolicyBuilder to add Interceptor in in and out for my
> ASSERTION_TYPES:
>     public MyAssertionPolicyProvider() {
>         super(ASSERTION_TYPES);
>         getInInterceptors().add(IN_INTERCEPTOR);
>         getOutInterceptors().add(OUT_INTERCEPTOR);
> ...
>
> Add InInterceptor in phase PRE_PROTOCOL and also outInterceptor in phase
> PRE_PROTOCOL
>
>
> 4, Add them in cxf-extensions.txt file.
>
>
> Then I verify my policy, when debug in out MyPolicyInterceptor in client
> side, AssertionInfoMap is not null, I can get my Assertion successfully.
>
> But when running in server side in in MyPolicyInterceptor, the
> AssertionInfoMap is null, I cannot get Assertion, its' null....
>
>
> So I'm confuse why after set wsp:Optional=true everything works in out
> Interceptor in client side and not work in in Interceptor in server side.
> But if set wsp:Optional=false or doesn't set Optional parameter, everything
> works fine in both side.
>
>
> Not sure if there is issue in cxf for Optional=true situation?
>
> Or could you please let me know if there is any way to debug or narrow down
> my problem?
>
> Great thanks a lot! :)
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Cannot-get-ws-policy-assertion-when-wsp-Optional-set-true-tp5758740.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



-- 
Colm O hEigeartaigh

Talend Community Coder
http://coders.talend.com