You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Dobri Kitipov <kd...@googlemail.com> on 2008/10/30 13:59:37 UTC

Problem to retrieve the effective policy from MessageContext when we have into the services.xml

Hi,
I have a problem when I try to get the effective policy from a
MessageContext when I have a policy attached at the binding level of a Web
Service. I am using Axis2 1.4.0
Let me explain a little bit the scenario I have. I am using an AAR that has
into its services.xml:

<parameter name="useOriginalwsdl">true</parameter>

and a PolicyAttachment at its service level:

<wsp:PolicyAttachment xmlns:wsp="
http://schemas.xmlsoap.org/ws/2004/09/policy">
            <wsp:AppliesTo>
                <policy-subject identifier="binding:soap11"/>
                <policy-subject identifier="binding:soap12"/>
            </wsp:AppliesTo>
            <wsp:Policy wsu:Id="User" xmlns:wsp="
http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">...

</wsp:PolicyAttachment>

As a result the WSDL generated has the policy specified and policy reference
at the binding subject level. Here is an excerpt from the wsdl for the
SOAP11Binding:

<wsdl:binding name="MTOMServiceSOAP11Binding"
type="tns:MTOMServicePortType">
<soap:binding style="document" transport="
http://schemas.xmlsoap.org/soap/http"/>
<wsp:PolicyReference URI="#User"/>

At client side I have a dynamic client. So the issue is that when I invoke
the service and the WSDL is read and the corresponding AxisService object is
crated at the client side I have some modules' handlers that take palce. One
of them is a custom one in which I have the following invocation:

Policy policy = msgCtx.getEffectivePolicy();

The problem is that this returns "null"! I debugged this and it came out
that msgCtx is not null. When the method is invoked it tries to calculate
the effective policy as given below.

         AxisBindingMessage bindingMessage =
             (AxisBindingMessage)
 getProperty(Constants.AXIS_BINDING_MESSAGE);

         if (bindingMessage != null) {
             return bindingMessage.getEffectivePolicy();
         } else {
             if (axisMessage != null) {
                 return axisMessage.getEffectivePolicy();
             } else {
                 return null;
             }
         }

where bindingMessage  is null and axisMessage.getEffectivePolicy(); returns
null, too. When I dig through the AxisService -> AxisEndpoint -> AxisBinding
-> here the PolicySubject is in fact a PolicyReference to the Policy that is
set into the AxisService policyMap. So as a result
axisMessage.getEffectivePolicy() returns null and I can not get the Policy I
need.
I saw that I need something like the AxisDescription.getApplicablePolicy in
order to locate the real Policy of a given PolicyReference.
Is that the correct behavior?

Can you please give me some more information how should I get the policy
attached at the binding level in my handler?


Thank you in advance,
Dobri

Re: Problem to retrieve the effective policy from MessageContext when we have into the services.xml

Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi Dobri,
        Yes, I think there is a logic error of the getEffectivePolicy()
method. There can scenarios where binding message is null, but binding is
set. So when calculating the effective policy we should try the higher level
of the hierarchy when the lower level one fails. So I think we should fix
the getEffectivePolicy() method of the MessageContext. If we consider the
higher level of the higher, this problem will be solved. Please create a
JIRA .

thanks,
nandana

On Thu, Oct 30, 2008 at 6:29 PM, Dobri Kitipov <kdobrik.axis2@googlemail.com
> wrote:

> Hi,
> I have a problem when I try to get the effective policy from a
> MessageContext when I have a policy attached at the binding level of a Web
> Service. I am using Axis2 1.4.0
> Let me explain a little bit the scenario I have. I am using an AAR that has
> into its services.xml:
>
> <parameter name="useOriginalwsdl">true</parameter>
>
> and a PolicyAttachment at its service level:
>
> <wsp:PolicyAttachment xmlns:wsp="
> http://schemas.xmlsoap.org/ws/2004/09/policy">
>             <wsp:AppliesTo>
>                 <policy-subject identifier="binding:soap11"/>
>                 <policy-subject identifier="binding:soap12"/>
>             </wsp:AppliesTo>
>             <wsp:Policy wsu:Id="User" xmlns:wsp="
> http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="
> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">...
>
> </wsp:PolicyAttachment>
>
> As a result the WSDL generated has the policy specified and policy
> reference at the binding subject level. Here is an excerpt from the wsdl for
> the SOAP11Binding:
>
> <wsdl:binding name="MTOMServiceSOAP11Binding"
> type="tns:MTOMServicePortType">
> <soap:binding style="document" transport="
> http://schemas.xmlsoap.org/soap/http"/>
> <wsp:PolicyReference URI="#User"/>
>
> At client side I have a dynamic client. So the issue is that when I invoke
> the service and the WSDL is read and the corresponding AxisService object is
> crated at the client side I have some modules' handlers that take palce. One
> of them is a custom one in which I have the following invocation:
>
> Policy policy = msgCtx.getEffectivePolicy();
>
> The problem is that this returns "null"! I debugged this and it came out
> that msgCtx is not null. When the method is invoked it tries to calculate
> the effective policy as given below.
>
>          AxisBindingMessage bindingMessage =
>              (AxisBindingMessage)
>  getProperty(Constants.AXIS_BINDING_MESSAGE);
>
>          if (bindingMessage != null) {
>              return bindingMessage.getEffectivePolicy();
>          } else {
>              if (axisMessage != null) {
>                  return axisMessage.getEffectivePolicy();
>              } else {
>                  return null;
>              }
>          }
>
> where bindingMessage  is null and axisMessage.getEffectivePolicy(); returns
> null, too. When I dig through the AxisService -> AxisEndpoint -> AxisBinding
> -> here the PolicySubject is in fact a PolicyReference to the Policy that is
> set into the AxisService policyMap. So as a result
> axisMessage.getEffectivePolicy() returns null and I can not get the Policy I
> need.
> I saw that I need something like the AxisDescription.getApplicablePolicy in
> order to locate the real Policy of a given PolicyReference.
> Is that the correct behavior?
>
> Can you please give me some more information how should I get the policy
> attached at the binding level in my handler?
>
>
> Thank you in advance,
> Dobri
>



-- 
Nandana Mihindukulasooriya
WSO2 inc.

http://nandana83.blogspot.com/
http://www.wso2.org