JSONPath前pression在Apache的骆驼XML字符串检查 [英] JSONPath expression for checking string in Apache Camel XML

查看:424
本文介绍了JSONPath前pression在Apache的骆驼XML字符串检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个简单的JSON文件,如以下

Let's say I have a simple json file such as the following

{
    "log": {
        "host": "blah",
        "severity": "INFO",
        "system": "1"
    }
}

我使用Apache的骆驼,它是春天的XML处理和路由JSON文件。我的路由code看起来是这样的:

I'm using Apache Camel, and it's Spring XML to process and route the json file. My routing code looks something like this:

<route>
    <from uri="file:/TESTFOLDER/input"/>
    <choice>
      <when>
        <jsonpath>$.log?(@.severity == 'WARNING')</jsonpath>
        <to uri="smtp://(smtpinfo...not important)"/>
      </when>
      <otherwise>
        <to uri="file:/TESTFOLDER/output"/>
      </otherwise>
    </choice>
</route>

这我真搞不清楚的部分是JSONPath前pression。这位前pression我上面竟然没有语法正确,因为它很难找到,你是不是想通过元素列表排序的案例。我的目标是如果日志的严重程度是警告,但我不能拿出前pression只发送电子邮件。

The part that I'm really confused about is the JSONPath expression. The expression I have above isn't even syntactically correct, because its hard to find examples for the case where you aren't trying to sort through a list of elements. My goal is to only send an email if the severity of the log is 'WARNING' but I can't come up with the expression.

推荐答案

本使用骆驼2.13.1(我检查信息为我工作作为你的JSON例子有这个严重性;你可以将此根据自己的需要改变):

This worked for me using Camel 2.13.1 (I checked for INFO as your JSON example has this severity; you may change this according to your needs):

<jsonpath>$..log[?(@.severity == 'INFO')]</jsonpath>

请注意在 .. [] 。然而,使用单点 在检索路径的开头失败:

Note the .. and the []. However, using a single dot . at the beginning of the search path failed:

<jsonpath>$.log[?(@.severity == 'INFO')]</jsonpath>

错误消息说:

java.lang.IllegalArgumentException: Invalid container object

这可能是一个错误。

根据JSON的路径文档 .. 表示递归下降。这可能不符合你的要求。然而,作为一个单一的点没有工作,这是唯一可能的工作围绕我想通了。否则,你可能会上升一个bug票。

According to the JSON Path doc, .. stands for "recursive descent". This may not meet your requirements. However, as a single dot . didn't work, this was the only possible work around I figured out. Otherwise, you may rise a bug ticket.

这篇关于JSONPath前pression在Apache的骆驼XML字符串检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆