如何比较身体内容匹配(equals
或startWith
)的值
{"status":"OK"}
怎么样?
<camel:choice>
<camel:when>
<simple>${in.body} == '{"status":"OK"}'</simple>
...
</camel:when>
</camel:choice>
我尝试:
'{"status":"OK"}'
'{\x22status\x22:\x22OK\x22}'
'\{"status":"OK"\}'
'{"status":"OK"\}'
...
我可以做这个:
<simple>${in.body} contains '{"status":"OK"'</simple>
但我需要equals
或startWith
作为规则运营商。 :(
我正在使用版本apache-camel-2.20.1
Camel支持JsonPath,所以你应该更好地使用这个组件来比较json。
在pom中添加依赖项
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>x.x.x</version>
</dependency>
然后
<camel:choice>
<camel:when>
<jsonpath>$[?(@.status=='OK')]]</jsonpath>
...
</camel:when>
</camel:choice>