I am trying to implement Camel CBR based on JSONPath filter expressions.
Body (JSON structure) is as follows :
{
"orderId": "315973",
"status": "Complete",
"entity": {
...
}
}
My route is as follows :
// Unimportant part
from("direct:in")
.streamCaching()
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("Authorization", simple(AUTH_TOKEN))
.to(SOME_HTTP_ENDPOINT_1).bean(ResultIDExtractorBean.class)
.to(SOME_HTTP_ENDPOINT_2).bean(OrderIDExtractorBean.class)
.to(SOME_HTTP_ENDPOINT_3)
.choice()
// Important part
.when().jsonpath("$[?(@.status == 'Complete')]" , false)
.to("mock:complete")
.when().jsonpath("$[?(@.status == 'In Progress')]" , false)
.to("mock:in_progress")
.otherwise()
.to("mock:error").stop()
.end();
Two issues I am facing :
1) If am getting exception :org.apache.camel.ExpressionEvaluationException: com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to primitives.
I can surpress this exception, but the second (more crucial) issue is not solved.
2) Message is not routed based on "status".
This predicate expression works however:
.when(PredicateBuilder.isEqualTo(
ExpressionBuilder.languageExpression("jsonpath", "$.status"),
ExpressionBuilder.constantExpression("In Progress")))
I'd like to know how to leverage JSON path filter expressions in Camel CBR. Thanks.
P.S. camel/camel-jsonpath versions are 2.17.0