89.10. 使用标头作为输入
默认情况下,JSONPath 使用消息正文作为输入源。但是,您还可以通过指定 headerName
选项来将标头用作输入。
例如,要计算存储在名为 scalability 的标头中的 JSON 文档中的 过期
数:
from("direct:start") .setHeader("numberOfBooks") .jsonpath("$..store.book.length()", false, int.class, "books") .to("mock:result");
在上面的 jsonpath
表达式中,我们将标头的 名称指定为
分号,并告知我们希望将结果转换为 int.class
的整数。
XML DSL 中的同一示例为:
<route> <from uri="direct:start"/> <setHeader name="numberOfBooks"> <jsonpath headerName="books" resultType="int">$..store.book.length()</jsonpath> </setHeader> <to uri="mock:result"/> </route>