In a lot of cases, we can cover our requirement with the filter mediator, but we can sometimes have more than two different parameters to compare. In this case, we need the switch mediator, which works similar to the filter mediator, but can handle N alternative cases.
We need to filter the payload by an XPath or JSONPath expression, and the string response will be checked against all the regex expressions of every case tag. When none of these cases match the condition, the mediator inside the default tag will be processed.
Let's look at the syntax:
<switch source="[XPath|json-eval(JSON Path)]"> <case regex="string"> mediator+ </case>+ <default> mediator+ </default>? </switch>
In the following example, we have a service that receives, among other information, the name of...