Contents

JsonCBR (Json Content Based Routing) is used to route the incoming messages on to different destinations based on the content of the messages. The component creates a port for each of the JsonPath expressions specified and the messages satisfying the particular JsonPath  is sent onto the respective port. In addition to these ports an output port OUT_FALSE is created and messages whose content does not satisfy any of the JsonPath expressions will be sent out of this port. If more than one JsonPath condition is true, the message is sent on all the ports for which the JsonPath condition evaluates to true.

Configuration and Testing

The JsonCBR component can be configured using its Custom Property Sheet wizard.

Figure 1: JsonPath(s) to be evaluated on the input messages

JsonPaths based on which the routing is done can be configured in JsonCBR Configuration Page.A valid JsonPath expression can be typed directly in the table.

An empty row is automatically added after pressing Enter key after the JsonPath is manually provided.

 For each configured JsonPath expression, an output port is created with the name provided in OutPort_Name column, messages satisfying the given Json Objects condition are routed onto this port. Port names ON_EXCEPTION and OUT_FALSE  are reserved and cannot be set in OutPort_Name column.

  • JsonPath contains the path of any element, then JsonCBR checks for the existence of the particular element in the input Json Object. If the input JsonObject contains the element then it will be routed to the corresponding output port of that JsonPath, if the input JsonObject does not contain the element then it will be routed to the output port OUT_FALSE.

  •  Json values which are  passsed in input Json object  should only be any of these types : Long, Integer, Double, String, Boolean, BigInteger, BigDecimal

Comparison of the JSONPath syntax elements with its XPath counterparts.

XPathJSONPathDescription
/$the root object/element
.@the current object/element
/. or []child operator
..n/aparent operator
//..recursive descent. JSONPath borrows this syntax from E4X.
**wildcard. All objects/elements regardless their names.
@n/aattribute access. JSON structures don't have attributes.
[][]subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.
|[,]Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
n/a[start:end:step]array slice operator borrowed from ES4.
[]?()applies a filter (script) expression.
n/a()script expression, using the underlying script engine.
()n/agrouping in Xpath

 

 

Functional Demonstration

Scenario

JsonCBR is configured to filter the messages on the basis of book price in the input message. It is sent to one of the output ports depending on the JsonPath specified in the  JsonCBR CPS.

Configure the JsonCBR as described in Configuration and Testing section and use feeder and display component to send sample input and check the response respectively. 

Figure2: Demonstrating the Scenario with sample input and output

Sample Input

{ "store": {

"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "ayush",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}

       }

 

Sample Output

{ "store": {

"book": [ 
{ "category": "reference",
"author": "Nigel Rees",
"title": "ayush",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}

       }

 

 

Adaptavist ThemeBuilder EngineAtlassian Confluence