21.5.2. 配置标准 WS-RM 策略属性

概述

您可以使用以下方法之一配置标准 WS-RM 策略属性:

WS-Policy RMAssertion Children

表 21.3 “WS-Policy RMAsertion Element 的子项” 显示 http://schemas.xmlsoap.org/ws/2005/02/rm/policy 命名空间中定义的元素:

表 21.3. WS-Policy RMAsertion Element 的子项

名称描述

InactivityTimeout

指定在端点可以视为因为不活跃而终止的 RM 序列前必须收到消息前必须经过的时间长度。

BaseRetransmissionInterval

设置确认在 RM Source 中给定邮件必须接收的间隔。如果 BaseRetransmissionInterval 设定的时间内未收到确认,RM Source 将重新传输该消息。

ExponentialBackoff

表示将使用通常已知的 exponential backoff 算法(Tanenbaum)调整重新传输间隔。

如需更多信息,请参阅 Computer Networks, Andrew S. Tanenbaum, Prentice Hall PTR, 2003。

AcknowledgementInterval

在 WS-RM 中,确认会在返回信息上发送或发送独立消息。如果返回消息无法发送确认,则 RM Destination 可以在发送独立确认前等待确认间隔。如果没有未被确认的消息,则 RM Destination 不能被确认。

更详细的参考信息

如需更详细的参考信息,包括每个元素和属性的描述,请参阅 http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd

rmManager Spring bean 中的 RMAssertion

您可以通过在 Apache CXF rmManager Spring bean 中添加 RMAssertion 来配置标准 WS-RM 策略属性。如果您想在同一配置文件中保留所有 WS-RM 配置,这是最佳的方法。也就是说,如果要在同一文件中配置特定于 Apache CXF 的属性和标准 WS-RM 策略属性。

例如,例 21.5 “在 rmManager Spring Bean 中使用 RMAsertion 配置 WS-RM 属性” 中的配置会显示:

  • 使用 rmManager Spring bean 中的 RMAsertion 配置的标准 WS- RM 策略属性 BaseRetransmissionInterval
  • 同一配置文件中配置的 Apache CXF 特定 RM 属性 intraMessageThreshold

例 21.5. 在 rmManager Spring Bean 中使用 RMAsertion 配置 WS-RM 属性

<beans xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
       xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
...>
<wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
    <wsrm-policy:RMAssertion>
        <wsrm-policy:BaseRetransmissionInterval Milliseconds="4000"/>
    </wsrm-policy:RMAssertion>
    <wsrm-mgr:destinationPolicy>
        <wsrm-mgr:acksPolicy intraMessageThreshold="0" />
    </wsrm-mgr:destinationPolicy>
</wsrm-mgr:rmManager>
</beans>

功能中的策略

您可以在功能中配置标准 WS-RM 策略属性,如 例 21.6 “在功能中将 WS-RM 属性配置为策略” 所示。

例 21.6. 在功能中将 WS-RM 属性配置为策略

<xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:wsa="http://cxf.apache.org/ws/addressing"
        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"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="
http://www.w3.org/2006/07/ws-policy http://www.w3.org/2006/07/ws-policy.xsd
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schema/ws/addressing.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <jaxws:endpoint name="{http://cxf.apache.org/greeter_control}GreeterPort" createdFromAPI="true">
        <jaxws:features>
               <wsp:Policy>
                   <wsrm:RMAssertion xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
                     <wsrm:AcknowledgementInterval Milliseconds="200" />
                   </wsrm:RMAssertion>
                   <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata">
                       <wsp:Policy>
                            <wsam:NonAnonymousResponses/>
                       </wsp:Policy>
                   </wsam:Addressing>
              </wsp:Policy>
        </jaxws:features>
    </jaxws:endpoint>
</beans>

WSDL 文件

如果使用 WS-Policy 框架启用 WS-RM,您可以在 WSDL 文件中配置标准 WS-RM 策略属性。如果您希望服务进行互操作并使用 WS-RM 与部署到其他策略感知的 Web 服务堆栈的用户无缝使用,这是不错的方法。

例如,请参阅 “WS-Policy 框架:隐式添加拦截器”一节,其中基本重新传输间隔在 WSDL 文件中配置。

外部附加

您可以在外部附件文件中配置标准 WS-RM 策略属性。如果您无法或不想更改 WSDL 文件,这是不错的方法。

例 21.7 “在外部附加中配置 WS-RM” 显示为特定 EPR 启用 WS-A 和 WS-RM (基础重新传输间隔 30 秒)的外部附加。

例 21.7. 在外部附加中配置 WS-RM

<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsp:PolicyAttachment>
        <wsp:AppliesTo>
           <wsa:EndpointReference>
                <wsa:Address>http://localhost:9020/SoapContext/GreeterPort</wsa:Address>
            </wsa:EndpointReference>
        </wsp:AppliesTo>
        <wsp:Policy>
            <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">
                <wsrmp:BaseRetransmissionInterval Milliseconds="30000"/>
            </wsrmp:RMAssertion>
        </wsp:Policy>
    </wsp:PolicyAttachment>
</attachments>/