header switch controller

Switch Case

Version: 17.07

Supported Since: 17.01

What is a Switch-Case processor?

A Switch processing element used in combination with several Case processing elements is considered as a Switch-Case processor. Theoretically the behaviour of this is similar to a switch block of a high level programming language such as Java, where this processor accepts message contexts and directs them to different processing branches based on a specific condition.

In order to use this processing element, you must first select the Flow Control dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Flow Control dependency.

switch outports

Out Ports

Switch Element

Case

All the Case elements should be connected to this outport and the message context will be sent to the first case element that evaluates to true

Default

The message context will be sent to this outport if none of the case values evaluated to true

On Exception

The message context will be sent to this outport if any exception occurred while processing

Case Element

On match

The message context will be sent to this outport if the value of this case element evaluates to true

On Exception

The message context will be sent to this outport if any exception occurred while processing

Parameters

Switch Element

Predicate Type *

Basic

The type of predicate to be used for the evaluation. The following predicate types are supported.

  • HEADER - A transport header value from the message will be used in the predicate

  • PROPERTY - A message property will be used in the predicate

  • CONTENT - An extracted XPath value from the message payload will be used in the predicate

  • VARIABLE - A scope variable from the message context will be used in the predicate

Variable Name *

Basic

The interpretation of this parameter’s value depends on the selected predicate type.

  • HEADER - Variable Name is the name of the transport header to be used in the predicate

  • PROPERTY - Variable Name is the key of the message property to be used in the predicate

  • CONTENT - The XPath to extract the value the from message payload

  • VARIABLE - Variable Name is the key of the scope variable to be used in the predicate

Variable Type *

Basic

The type of the variables used in the predicate. One of the following types can be selected as the value of this parameter.

  • Boolean

  • Integer

  • Long

  • Float

  • Double

  • String

It must be possible to cast/convert the value resolved (using the above predicate type and the variable name) as well as the case value in each connected case element, to this specified type.

Predicate Function *

Basic

The predicate function to be used to compare the value resolved (using the above predicate type and the variable name) and the case value in each connected case element. One of the following predicate functions can be selected as the value of this parameter.

  • EQUALS - Equivalent to Java’s Object.equals() method

  • MATCH - Only applicable to String variable type and equivalent to Java’s String.matches() method

  • CONTAINS - Only applicable to String variable type and equivalent to Java’s String.contains() method

Namespaces

Basic

If the predicate type is CONTENT (where an XPath value is used for the condition), and if any custom namespaces are being used inside XPath expression, those should be defined as a map with those namespaces as keys and the corresponding namespace URIs as values.

Case Element

Case Value *

Basic

The selected predicate of the switch element will be executed against the value of this parameter to evaluate whether this case branch matches the criteria.

It must be possible to cast/convert the value specified for this parameter to the variable type defined in the switch element.

Sample Use Case

In the following use case, the requirement is to read a message from a JMS queue and based on the value of the header X_HEADER, dispatch it to 3 different JMS queues. If the header value is foo, dispatch to queue 1, if the header value is bar, dispatch to queue 2 or if the header value is hello, dispatch to queue 3.

switch flow
switch flow config 1

To achieve this, the message context provided from JMS Ingress Connector is handed over to a Switch processing element. As shown in the above configuration, Switch element is configured to have a HEADER Predicate Type and the Variable Name is set to "X_HEADER". Then the Predicate Type is set to EQUALS.

switch flow config 2
switch flow config 3