188.8. 内联简单例外

可从 Camel 2.18 开始

现在,使用简单语法 ${xxx},它可以在 JSonPath 表达式中内联简单语言表达式。下面是一个示例:

from("direct:start")
  .choice()
    .when().jsonpath("$.store.book[?(@.price < ${header.cheap})]")
      .to("mock:cheap")
    .when().jsonpath("$.store.book[?(@.price < ${header.average})]")
      .to("mock:average")
    .otherwise()
      .to("mock:expensive");

在 XML DSL 中:

<route>
  <from uri="direct:start"/>
  <choice>
    <when>
      <jsonpath>$.store.book[?(@.price < ${header.cheap})]</jsonpath>
      <to uri="mock:cheap"/>
    </when>
    <when>
      <jsonpath>$.store.book[?(@.price < ${header.average})]</jsonpath>
      <to uri="mock:average"/>
    </when>
    <otherwise>
      <to uri="mock:expensive"/>
    </otherwise>
  </choice>
</route>

您可以通过将选项 allowSimple 设置为 false 来关闭对内联简单表达式的支持,如下所示:

.when().jsonpath("$.store.book[?(@.price < 10)]", false, false)

在 XML DSL 中:

<jsonpath allowSimple="false">$.store.book[?(@.price < 10)]</jsonpath>