Contents

CBR (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 XPath expressions specified and the messages satisfying the particular XPath 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 XPath expressions will be sent out of this port. If more than one XPath condition is true, the message is sent on all the ports for which the XPath condition evaluates to true.

Configuration and Testing

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

Schema


Figure 1: Provide schema

The schema of the XML content that is used for routing should be provided using the Schema Editor in the Schema panel. The XML content that is used for routing is determined by the property Apply Xpath on context in Routing Rules panel.
Refer to Schema Editor section in Common Components Configurations for information about Schema Editor shown in Figure 1.

Namespaces


Figure 2: List of namespaces

List of namespace prefixes that are used in the XPath and the namespaces that they represent are provided in the Namespaces panel. The table in this panel is automatically populated with namespaces defined in XML schema provided in Schema panel.
To remove unnecessary namespaces, select the row containing namespace and click the Delete button.
To add a new namespace prefix and namespace, enter the details in the empty row and press Enter key.

Routing Rules


Figure 3: XPath(s) to be evaluated on the input messages

XPaths based on which the routing is done can be configured in Routing Rules panel. XPath editor can be used to configure XPaths. Click the ellipsis button in the XPath column to open XPath Editor. Alternatively, a valid XPath expression can be typed directly in the table.

An empty row is automatically added after closing the XPath Editor or after pressing Enter key after the XPath is manually provided.

Refer to XPath Editor section in Common Components Configurations for information about XPath Editor shown in Figure 1.

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

Icon
  • XPath in CBR should be configured to return a boolean value for routing messages.
  • XPath can also contain simply the path of any element, then CBR checks for the existence of the particular element in the input xml. If the input xml contains the element then it will be routed to the corresponding output port of that XPath, if the input xml does not contain the element then it will be routed to the output port OUT_FALSE.
  • XPath can be valid JMS Message selectors. If the JMS Message selector is used, the runtime argument useFioranoCBR (in Properties panel) should be set to 'true' as shown in Figure 4.


Figure 4: Setting runtime argument 'useFioranoCBR'.


Figure 5: XPath processor properties in Routing Rules page

Processor

Specifies the processor used to evaluate XPath conditions. If the number of XPath conditions are more (greater than 4), then XSLT processor is preferable for better performance. If the XPath conditions are less then both processors will give equal performance. XPath processor is preferable if the XPaths are complex. XSLT processor might not work for all XPaths.

XPath

Uses Saxon based XPath evaluator to evaluate XPaths. Values in column XPath should be valid XPath expressions. XPaths are validated if XPath processor is selected. The validation will be done for some simple XPath conditions only. So, if the XPath is validated, there is no guarantee that the XPath results a boolean value.

  • Use XPath 1.0: When this property is selected, XPath 1.0 is used for evaluation. Otherwise, XPath 2.0 is used. This checkbox is visible only when the Processor is selected as XPath.
  • ApplyXPathonContext: When this property is selected, the XPath is evaluated on the Application Context of the input message. Otherwise, XPath is evaluated on Body of the message.
    When XPath is evaluated on Context of the message, no schema is set on the ports of CBR. In case of evaluating text body of the message, schema provided earlier in the configuration (if present) will be set on the ports.

    Icon

    When this option is chosen, provide application context schema in the schema panel.

XSLT

Uses XSLT to evaluate condition. Values in column XPath can be any valid Boolean condition in XSLT. There is no validation check on XPath conditions if we select XSLT processor.

Icon

While using XSLT processor, if XPath contains any functions having namespace prefixes like saxon:parse(), then the appropriate prefix and namespace URL pair should add in the Namespace panel. For example, to use saxon functions namespace, URL http://saxon.sf.net/ should add saxon as prefix in the Namespace panel.

Example: For a value /ns1:Transaction/ns1:request/ns1:source = 'tserv' provided in column XPath, the following XSL is used:

Functional Demonstration

Scenario

CBR is configured to filter the messages on the basis of employee age in the input message. It is sent to one of the output ports depending on the XPath specified in the CBR.
Configure the CBR as described in Configuration and Testing section and use feeder and display component to send sample input and check the response respectively.


Figure 6: Demonstrating the Scenario with sample input and output

Sample Input

Sample Output

Use Case Scenario

In Purchasing System sample, a purchase request is sent by the user to a company through a web based interface. The purchase order consists of three inputs namely REQUEST, CREDENTIALS, and SYNC_PO_002. REQUEST is an identifier string for the request. The request identifier is verified by a CBR (Content Based Router) component to be the correct one for which this system is expected to service the request.


Figure 7: Purchasing System sample

Useful Tips

  • The order of the XPath conditions specified in the CPS does not matter.
  • The CBR component supports XPath version 1.0 and 2.0. The default is version 2.0. To use version 1.0, please select the checkbox Use XPath 1.0 in the CPS.
  • To monitor time taken for executing each request, set log level for logger com.fiorano.edbc.cbr.monitor to INFO.
  • When runtime argument for this component, useFioranoCBR is set to 'true', please make sure that the XPaths provided in the configuration are valid JMS Messages. More information on JMS Message Selectors can be found in the documentation for Message interface in JMS APIs. http://java.sun.com/products/jms/javadoc-102a/index.html.
  • To apply XPath on context, select ApplyXPathonContext in Routingrules panel and provide Application context schema in the schema panel. In this case, schema will not be set on output ports.
Icon

To understand the service better, refer the Content Based Routing (CBR) example which demonstrates CBR service features.

Adaptavist ThemeBuilder EngineAtlassian Confluence