Using the XPath Filter

此组件定义了一个基于 XPath 的消息过滤器。内部,这些组件使用一个包装 AbstractXPathMessageSelector 实例的 MessageFilter

This component defines an XPath-based message filter. Internally, these components uses a MessageFilter that wraps an instance of AbstractXPathMessageSelector.

有关详细信息,请参阅 Filter

See Filter for further details.

要使用 XPath 过滤器,您至少必须通过声明 xpath-expression 元素或在 xpath-expression-ref 属性中引用 XPath 表达式来提供一个 XPath 表达式。

to use the XPath filter you must, at a minimum, provide an XPath expression either by declaring the xpath-expression element or by referencing an XPath Expression in the xpath-expression-ref attribute.

如果提供的 XPath 表达式计算得出一个 boolean 值,则不需要其他配置参数。然而,如果 XPath 表达式计算得出一个 String,您应设置 match-value 属性,对其比对计算结果。

If the provided XPath expression evaluates to a boolean value, no further configuration parameters are necessary. However, if the XPath expression evaluates to a String, you should set the match-value attribute, against which the evaluation result is matched.

match-type 有三个选项:

match-type has three options:

  • exact: Correspond to equals on java.lang.String. The underlying implementation uses a StringValueTestXPathMessageSelector

  • case-insensitive: Correspond to equals-ignore-case on java.lang.String. The underlying implementation uses a StringValueTestXPathMessageSelector

  • regex: Matches operations one java.lang.String. The underlying implementation uses a RegexTestXPathMessageSelector

当提供 regex 的 'match-type' 值时,随 match-value 属性一起提供的 value 必须是一个有效的正则表达式。

When providing a 'match-type' value of 'regex', the value provided with the match-value attribute must be a valid regular expression.

以下示例显示了 xpath-filter 元素的所有可用属性:

The following example shows all the available attributes for the xpath-filter element:

<int-xml:xpath-filter discard-channel=""                      1
                      id=""                                   2
                      input-channel=""                        3
                      match-type="exact"                      4
                      match-value=""                          5
                      output-channel=""                       6
                      throw-exception-on-rejection="false"    7
                      xpath-expression-ref="">                8
    <int-xml:xpath-expression ... />                          9
    <int:poller ... />                                        10
</int-xml:xpath-filter>
1 Message channel where you want rejected messages to be sent. Optional.
2 ID for the underlying bean definition. Optional.
3 The receiving message channel of this endpoint. Optional.
4 Type of match to apply between the XPath evaluation result and the match-value. The default is exact. Optional.
5 String value to be matched against the XPath evaluation result. If you do not set this attribute, the XPath evaluation must produce a boolean result. Optional.
6 The channel to which messages that matched the filter criteria are dispatched. Optional.
7 By default, this property is set to false and rejected messages (those did not match the filter criteria) are silently dropped. However, if set to true, message rejection results in an error condition and an exception being propagated upstream to the caller. Optional.
8 Reference to an XPath expression instance to evaluate.
9 This child element sets the XPath expression to be evaluated. If you do not include this element, you must set the xpath-expression-ref attribute. Also, you can include only one xpath-expression element.
10 A poller to use with the XPath filter. Optional.