Versions Compared

Key

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

...

In order for a client/server to communicate reliably with its target endpoint/its clients, the CXF WS-Reliable Messaging interceptors need to be in the interceptor chain for inbound and outbound messages and faults. Also, because WS-Reliable Messaging depends on WS-Addressing, the CXF WS-Addressing interceptors need to be on these interceptor chains also.
In the case of WS-Addressing, this means two interceptors on each of chains, see WS-Addressing Configuration.
The WS-Reliable Messaging implementation consists of 4 interceptors in total, but depending on which of the approaches oulined below you choose to enable the use of reliable messaging, you need not know what they are and which interceptor chain they should be added to.

It is important to note at this point that the presence of these interceptors alone will take care of exchanging the RM protocol messages when necessary. For example. upon processing the first application message on the outbound interceptor chain, and not all of them appear in all chain types. In a wsdl first approach however you need not be aware of these details if you use the WS-Policy Framework implementation and ensure that a the RM interceptors will ensure that a CreateSequence request is sent and not proceed with processing the original application message until the CreateSequenceResponse was received. Furthermore, the RM interceptors are responsible for adding the Sequence headers to the application messages and, on the destination side, extracting them from the message.
No changes to application code are required to make the message exchange reliable! And while by default, CXF attempts to maximize the lifetime of a sequence, thus reducing the overhead incurred by the RM protocol messages, you can control the behavior of these interceptors by setting their sequence termination policies (e.g. the maximum sequence length), and acknowledgment policies (e.g. send an out-of-band acknowledgment if no application messages was received in the last n seconds).

Using the RMAssertion and the CXF WS-Policy Framework

If

  1. A Policy with an RMAssertion element is attached to the wsdl:service element (or any other wsdl element that according to the rules for WS-Policy Attachment is an attachment point for Policy or PolicyReference elements)

...

...

  1. The CXF WS-

...

  1. Policy Framework

...

  1. is enabled

...


<bean id="org.apache.cxf.ws.policy.PolicyEngine" class="org.apache.cxf.ws.policy.spring.InitializingPolicyEngine">
<property name="bus" ref="cxf"/>
<property name="enabled" value="true"/>
</bean>

The attachment of a <wsp:Policy> element containing an <wsrmp:RMAssertion> element (or a <wsp:PolicyReference element referencing such an element) is then sufficient to enable the use of Reliable Messaging, i.e. it causes the Reliable Messaging interceptors to be added to the appropriate interceptor chains.
While an empty <RMAssertion> element is enough to trigger the use of reliable Messaging. Any child elements, such as an <wsrmp:BaseRetransmissionInterval> element, will take effect only for the endpoint to which the enclosing <wsp:Policy> od <wsp:PolicyReference> element applies.

Note that the <wsp:Policy> or <wsp:PolicyReference> elements need not be necessarily be attached to wsdl elements but can also appear in the form of external attachments, see WS-Policy - How it Works.
Enabling WS-Reliable Messaging using the WS-Policies Feature

  1. the RM interceptors will be added to their respective interceptor chains by the policy framework. The assertion attributes can be used configure the behaviour of the source/destination.

For example, to enable the WS-Policy Framework on the server side, you configuration file could look like thisThe PolicyEngine can also be enabled by using the WS-Policies Feature - that way you need not be aware of the policy engine's implementation class and its relation to the bus:

Code Block
xml
xml
<jaxws:endpoint ...>
    <jaxws:features>
    <p:policies/>
</jaxws:features>
</bean>

Also, <wsp:Policy> or <wsp:PolicyReference> element can appear as child elements of the policies feature, having the same effect as if they were attached to the wsdl:element representing the endpoint:

{code:xml}
    <jaxws:endpoint ...

and your wsdl:

Code Block
xml
xml

<wsp:Policy wsu:Id="="RM" xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata">
        <wsp:Policy/>
    </wsam:Addressing>
    <wsrmp:RMAssertion xmlns:wsrmp="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
        <jaxws<wsrmp:features>
  BaseRetransmissionInterval Milliseconds="10000"/> 
    </wsrmp:RMAssertion>
</wsp:Policy>
...
<wsdl:service name="ReliableGreeterService">
     <p:policies xmlns:p=<wsdl:port binding="tns:GreeterSOAPBinding" name="GreeterPort">
        <soap:address location="http://localhost:9020/SoapContext/GreeterPort"/>
        <wsp:PolicyPolicyReference URI="#RM" xmlns:wsp="http://www.w3.org/2006/07/ws-policy"/>
        
    </wsdl:port>
</wsdl:service>

Instead of having the PolicyReference attached to a wsdl element, you can also specify it as a child element of the policies features, e,g, for the server endpoint:

Code Block
xml
xml

<wsp:Policy wsu:Id="="RM"      <wsp:All>
 xmlns:wsp="http://www.w3.org/2006/07/ws-policy" ...>
</wsp:Policy>

<jaxws:endpoint ...>
    <jaxws:features>
    <p:policies>
             <wsam:Addressing xmlns:wsam<wsp:PolicyReference URI="#RM" xmlns:wsp="http://www.w3.org/20072006/07/ws-policy"/>
    </p:policies>
</jaxws:features>

Using the Reliable Messaging Feature

If you don't want to involve the WS-Policy Framework, or want to configure additional parameters such as the sequence termination policy or the persistent store, you can you can use the reliableMessaging feature. It is defined in namespace http://cxf.apache.org/ws/rm/managerImage Added and supports the following child elements:

Name

Value

RMAssertion

An element of type RMAssertion

deliveryAssurance

An element of type DeliveryAssuranceType that describes the delivery assurance that should apply (AtMostOnce, AtLeastOnce, InOrder)

sourcePolicy

An element of type SourcePolicyType that allows you to configure details of the RM source, such as whether an offer should always be included in a CreateSequence request, or the sequence termination policy.

destinationPolicy

An element of type DestinationPolicyType that allows you to configure details of the RM destination, such as whether inbould offers should be accepted.

store

The store to use (default: null). This must be an element of type jdbcStore (in the same namespace), or a bean or a reference to a bean that implements the RMStore interface.

For details about the element types used in this namespace please refer to the schemas for the http://cxf.apache.org/ws/rm/managerImage Added namespace (http://cxf.apache.org/schemas/wsrm-manager.xsdImage Added and http://cxf.apache.org/schemas/wsrm-manager-types.xsdImage Added). The jbdcStore element type is described below.

Example (feature applied at bus level):

Code Block
xml
xml

<cxf:bus>
    <cxf:features>
02/addressing/metadata">
            <wsa:addressing/>
        <wsrm-mgr:reliableMessaging>
          <wsp:Policy/>  <wsrm-policy:RMAssertion>
                <wsrm-policy:BaseRetransmissionInterval Milliseconds="4000"/>     </wsam:Addressing>
      
                <wsrmp<wsrm-policy:RMAssertionAcknowledgementInterval xmlns:wsrmpMilliseconds="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
2000"/>          
            </wsrm-policy:RMAssertion> 
            <wsrm-mgr:sourcePolicy>
                <wsrmp<wsrm-mgr:BaseRetransmissionIntervalsequenceTerminationPolicy MillisecondsmaxLength="300005"/>
                    
            </wsrmp:RMAssertion>wsrm-mgr:sourcePolicy>     
            <wsrm-mgr:destinationPolicy acceptOffers="false">        </wsp:All>
    
            </wsp:Policy><wsrm:store>
               <ref bean="myStore"/>
            <p:/policies></wsrm:store>
        </jaxwswsrm-mgr:features>reliableMessaging>
    </bean>

Enabling and Configuring WS-Reliable Messaging using the WS-Reliable Messaging Feature

TODO
Enabling and Configuring WS-Reliable Messaging using Beans

To ensure that the Reliable Messaging interceptors are added to the appropriate interceptor chains, e.g. for all client and server endpoints:

cxf:features>
</cxf:bus>

Configuring the Reliable Messaging Store

To enable persistence, you must specify the object implementing the persistent store for RM. You can develop your own, or use the JDBC based store that comes with CXF (class org.apache.cxf.ws.rm.persistence.jdbc.RMTxStore). You can configure the latter using a custom jdbcStore bean (namespace http://cxf.apache.org/ws/rm/managerImage Added). It supports the attributes:

Attribute Name

Type

Default

driverClassName

String

org.apache.derby.jdbc.EmbeddedDriver

userName

String

null

passWord

String

null

url

String

jdbc:derby:rmdb;create=true

Example:

Code Block
xml
xml

<wsrm-mgr:jdbStore id="myStore"
    driverClassName="org.apache.derby.jdbc.ClientDriver"/>
    url="jdbc:derby://localhost:1527/rmdb;create=true"/>
    password="password"/>

Adding the Reliable Messaging Interceptors Manually

To ensure that the Reliable Messaging interceptors are added to the appropriate interceptor chains, e.g. for all client and server endpoints:

Code Block
xml
xml

<bean id="rmLogicalOut" class="org.apache.cxf.ws.rm.RMOutInterceptor">
        <property name="bus" ref="cxf"/>
    </bean>
    <bean id="rmLogicalIn" class="org.apache.cxf.ws.rm.RMInInterceptor">
        <property name="bus" ref="cxf"/>
    </bean>
    <bean id="rmCodec" class="org.apache.cxf.ws.rm.soap.RMSoapInterceptor"/>

    <cxf:bus ...>
        <cxf:inInterceptors>
            <ref bean="rmLogicalIn"/>
            <ref bean="rmCodec"/>
        </cxf:inInterceptors>
        <cxf:inFaultInterceptors>
            <ref bean="rmLogicalIn"/>
            <ref bean="rmCodec"/>
        </cxf:inFaultInterceptors>
        <cxf:outInterceptors>
            <ref bean="rmLogicalOut"/>
            <ref bean="rmCodec"/>
        </cxf:outInterceptors>
        <cxf:outFaultInterceptors>
            <ref bean="rmLogicalOut"/>
            <ref bean="rmCodec"/>
        <cxf:outFaultInterceptors>
    </cxf:bus>

The

...

RetransmissionIntercepor

...

will

...

be

...

added

...

on

...

the

...

fly

...

by

...

the

...

RMOutInterceptor

...

so

...

need

...

not

...

appear

...

in

...

your

...

configuration

...

file.

...

Configuring the Reliable Messaging Manager Manually

To configure properties of the RM Manager, you can use the rmManager element from the http://cxf.apache.org/ws/rm/manager

...

Image Added namespace.

...

It

...

supports

...

the

...

same child

...

elements as the reliableMessaging feature element above.

<wsrm-mgr:rmManager

...

xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager">

...


<wsrm-mgr:sourcePolicy>
<wsrm-mgr:sequenceTerminationPolicy maxLength="5"/>
</wsrm-mgr:sourcePolicy>
</wsrm-mgr:rmManager>

Code Block