【发布时间】:2018-02-19 13:43:26
【问题描述】:
我有这个 Json:
{"request": {"cc": "000120000111SS000222M" }}
还有这个蓝图:
<route id="SGPIF-bonifico-dynamic-jetty">
<from uri="jetty:http://0.0.0.0:9100/ifom/esterno/bonifico/dynamic?matchOnUriPrefix=true"/>
<choice>
<when>
<jsonpath suppressExceptions="true">request.cc=~'0000111'</jsonpath>
<log message="Json choice equals "/>
<log message="SGPIF-bonifico-dynamic-jetty header: ${headers}"/>
<to uri="log:SGPIF-bonifico-dynamic-jetty" />
<wireTap uri="direct:requestEvent"/>
<to uri="jetty:http://127.0.0.1:8080/om/esterno/bonifico/dynamic?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<log message="SGPIF-bonifico-dynamic-jetty-done header: ${headers}"/>
<wireTap uri="direct:responseEvent"/>
<to uri="log:SGPIF-bonifico-dynamic-jetty-done" />
</when>
<otherwise>
<log message="Else choice"/>
<log message="SGPIF-bonifico-dynamic-jetty header: ${headers}"/>
<to uri="log:SGPIF-bonifico-dynamic-jetty" />
<wireTap uri="direct:requestEvent"/>
<to uri="jetty:http://127.0.0.1:8080/ifom/esterno/bonifico/dynamic?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<log message="SGPIF-bonifico-dynamic-jetty-done header: ${headers}"/>
<wireTap uri="direct:responseEvent"/>
<to uri="log:SGPIF-bonifico-dynamic-jetty-done" />
</otherwise>
</choice>
</route>
在这种情况下,如果 json 中存在这个值 0000111,我将进行过滤。我可以按职位筛选吗?我想在这个 000120000111SS000222M 上做一个子字符串。 有没有办法做到这一点?
好的,它可以与 contains 一起使用。但我需要这样的东西:
setHeader headerName="JsonValue">
<jsonpath>$.request.cc</jsonpath>
</setHeader>
<bean ref="parser" method="doSomething"/>
<choice>
<when>
<simple>${header.JsonValue} == '0000111'</simple>
并尝试做这样的事情:
public void doSomething(@Header("JsonValue") String jsonValue, @Body String body) {
jsonValue += jsonValue.substring(5,12);
}
【问题讨论】:
-
你可以省略 setHeader 部分并编写以下方法 public void doSomething(@JsonPath("$.request.cc") String jsonValue, @Headers Map
headers) { headers.put ("JsonValue", jsonValue.substring(5,12)); } -
工作的,非常感谢!