You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Yadav, Yogendra (IT)" <Yo...@morganstanley.com> on 2008/07/08 16:46:22 UTC
Adding custom ws-policy assertions
Hi,
I want to add a custom ws-policy assertion to an operation like this
(note: I picked up the ws_addressing and ws_policy samples as examples):
(snippet from wsdl)
<wsdl:portType name="Greeter">
<wsdl:operation name="sayHi">
<wsdl:input message="tns:sayHiRequest" name="sayHiRequest"
wswa:Action="urn:getQuote">
<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy">
<wsp:All>
<app:Caller
xmlns:app="http://xml.ns.ms.com/app">cc</app:Caller>
</wsp:All>
</wsp:Policy>
</wsdl:input>
<wsdl:output message="tns:sayHiResponse"
name="sayHiResponse" wswa:Action="urn:getQuote" />
</wsdl:operation>
I added this to client.xml and cxf-servlet.xml
<cxf:bus>
<cxf:features>
<wsa:addressing/>
<p:policies/>
</cxf:features>
</cxf:bus>
<bean id="CallerAssertionBuilder"
class="org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuil
der">
<property name="knownElements">
<set>
<bean class="javax.xml.namespace.QName">
<constructor-arg value="http://xml.ns.ms.com/app"/>
<constructor-arg value="Caller"/>
</bean>
</set>
</property>
</bean>
When I call the service from Client.java, I get this error ?
Implicit MessageAddressingProperties propagation
------------------------------------------------
Invoking sayHi...
javax.xml.ws.soap.SOAPFaultException: None of the policy alternatives
can be satisfied.
at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
at
msjava.cxfutils.jaxws.internal.MSJaxWsClientProxy.invoke(MSJaxWsClientPr
oxy.java:39)
at $Proxy41.sayHi(Unknown Source)
at
demo.ws_addressing.client.Client.implicitPropagation(Client.java:96)
at demo.ws_addressing.client.Client.main(Client.java:71)
Caused by: org.apache.cxf.interceptor.Fault: None of the policy
alternatives can be satisfied.
at
org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(Abstrac
tPolicyInterceptor.java:58)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:221)
at
org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
at
org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
at
org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
... 4 more
Caused by: org.apache.cxf.ws.policy.PolicyException: None of the policy
alternatives can be satisfied.
at
org.apache.cxf.ws.policy.EffectivePolicyImpl.chooseAlternative(Effective
PolicyImpl.java:124)
at
org.apache.cxf.ws.policy.EffectivePolicyImpl.initialise(EffectivePolicyI
mpl.java:80)
at
org.apache.cxf.ws.policy.PolicyEngineImpl.getEffectiveClientRequestPolic
y(PolicyEngineImpl.java:148)
at
org.apache.cxf.ws.policy.ClientPolicyOutInterceptor.handle(ClientPolicyO
utInterceptor.java:80)
at
org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(Abstrac
tPolicyInterceptor.java:56)
... 9 more
Would appreciate any help in this regard.
thanx
-yogen
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.
Re: Adding custom ws-policy assertions
Posted by Daniel Kulp <dk...@apache.org>.
I'm kind of beginning to dig into this as well as I'm starting to
implement the ws-securitypolicy stuff. It's a new area for me as I
haven't looked at the policy stuff at all. I'd appreciate it if one
of the folks would verify what I'm about to say.
Since you have wsp:All specified, some interceptor on the chain has to
"assert" that your app:Caller policy has been asserted. You would
need to provide a PolicyInterceptorProvider that would provide an
interceptor that would do the assertion. Something like:
public void handleMessage(Message msg) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
Collection<AssertionInfo> ais = aim.get(.... qname for
"app:Caller" ....);
if (null == ais || ais.size() == 0) {
return;
}
for (AssertionInfo ai : ais) {
ai.setAsserted(true);
}
}
Basically, the policy engine assumes the policies are NOT met. You
need to explicitely tell it that whatever policy that your trying to
assert is actually met (or turned on or whatever).
Dan
On Jul 8, 2008, at 10:46 AM, Yadav, Yogendra (IT) wrote:
> Hi,
> I want to add a custom ws-policy assertion to an operation like this
> (note: I picked up the ws_addressing and ws_policy samples as
> examples):
> (snippet from wsdl)
> <wsdl:portType name="Greeter">
> <wsdl:operation name="sayHi">
> <wsdl:input message="tns:sayHiRequest" name="sayHiRequest"
> wswa:Action="urn:getQuote">
> <wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy">
> <wsp:All>
> <app:Caller
> xmlns:app="http://xml.ns.ms.com/app">cc</app:Caller>
> </wsp:All>
> </wsp:Policy>
> </wsdl:input>
> <wsdl:output message="tns:sayHiResponse"
> name="sayHiResponse" wswa:Action="urn:getQuote" />
> </wsdl:operation>
>
>
> I added this to client.xml and cxf-servlet.xml
> <cxf:bus>
> <cxf:features>
> <wsa:addressing/>
> <p:policies/>
> </cxf:features>
> </cxf:bus>
>
> <bean id="CallerAssertionBuilder"
>
> class
> ="org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuil
> der">
> <property name="knownElements">
> <set>
> <bean class="javax.xml.namespace.QName">
> <constructor-arg value="http://xml.ns.ms.com/app"/>
> <constructor-arg value="Caller"/>
> </bean>
> </set>
> </property>
> </bean>
>
> When I call the service from Client.java, I get this error ?
>
> Implicit MessageAddressingProperties propagation
> ------------------------------------------------
> Invoking sayHi...
> javax.xml.ws.soap.SOAPFaultException: None of the policy alternatives
> can be satisfied.
> at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
> 199)
> at
> msjava
> .cxfutils.jaxws.internal.MSJaxWsClientProxy.invoke(MSJaxWsClientPr
> oxy.java:39)
> at $Proxy41.sayHi(Unknown Source)
> at
> demo.ws_addressing.client.Client.implicitPropagation(Client.java:96)
> at demo.ws_addressing.client.Client.main(Client.java:71)
> Caused by: org.apache.cxf.interceptor.Fault: None of the policy
> alternatives can be satisfied.
> at
> org
> .apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(Abstrac
> tPolicyInterceptor.java:58)
> at
> org
> .apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
> hain.java:221)
> at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
> at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
> at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
> at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
> 178)
> ... 4 more
> Caused by: org.apache.cxf.ws.policy.PolicyException: None of the
> policy
> alternatives can be satisfied.
> at
> org
> .apache.cxf.ws.policy.EffectivePolicyImpl.chooseAlternative(Effective
> PolicyImpl.java:124)
> at
> org
> .apache.cxf.ws.policy.EffectivePolicyImpl.initialise(EffectivePolicyI
> mpl.java:80)
> at
> org
> .apache.cxf.ws.policy.PolicyEngineImpl.getEffectiveClientRequestPolic
> y(PolicyEngineImpl.java:148)
> at
> org
> .apache.cxf.ws.policy.ClientPolicyOutInterceptor.handle(ClientPolicyO
> utInterceptor.java:80)
> at
> org
> .apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(Abstrac
> tPolicyInterceptor.java:56)
> ... 9 more
>
> Would appreciate any help in this regard.
>
> thanx
> -yogen
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender.
> Sender does not intend to waive confidentiality or privilege. Use of
> this email is prohibited when received in error.
---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog