Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is the easiest way of providing runtime support for an Assertion. Steps 1. and 2. listed in Interaction with the Framework can usually be coded as follows:

Code Block
java
java
package mycompany.com.interceptors;
import org.apache.cxf.ws.policy.AssertionInfoMap;

class MyPolicyAwareInterceptor {
   static final QName assertionType = new QName("http://mycompany.com}", "MyType"});
   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(...);
       }          }
}

Sometimes, it may be more convenient to spead the above functionality accross several interceptors, possibly according to chain (in, in fault, out, outfault). In any case, you need to also provide a PolicyInterceptorProvider, and declare a corresponding bean. Either implement one from scratch or use the PolicyInterceptorProviderImpl in the api package and customise it as follows (assuming that one and the same interceptor is used for all paths):

Code Block
xml
xml


<bean name="MyPolicyAwareInterceptor" "class="mycompany.com.interceptors.MyPolicyAwareInterceptor"/>
<bean class="org.apache.cxf.ws.policy.PolicyInterceptorProviderImpl">
        <constructor-arg>
            <!-- the list of assertion types supported by this PolicyInterceptorProvider -->
            <list>
                <bean class="javax.xml.namespace.QName">
                    <constructor-arg value="http://mycompany.com}"/>
                    <constructor-arg value="MyType"/>
                </bean>
            </list>
        </constructor-arg>
        <property name="inInterceptors">
            <list>
                <ref bean="MyPolicyAwareInterceptor"/>
            </list>
        </property>
        <property name="inFaultInterceptors">
            <list>
                <ref bean="MyPolicyAwareInterceptor"/>
            </list>
        </property>
        <property name="outInterceptors">
            <list>
                <ref bean="MyPolicyAwareInterceptor"/>
            </list>
        </property>
        <property name="outFaultInterceptors">
            <list>
                <ref bean="MyPolicyAwareInterceptor"/>
            </list>
        </property>
    </bean>

All beans of type PolicyInterceptorProvider are automatically registered with the framework's PolicyInterceptorProviderRegistry.

Implementing a Policy-Aware Conduit/Destination

...