switch
Use the switch component to execute one of a number of sections of the assembly based on which specified condition is fulfilled.
Gateway support
Gateway | Policy version |
---|---|
DataPower® Gateway (v5 compatible) | 1.0.0 |
DataPower API Gateway | 2.0.0 |
This topic describes how to configure the policy in the assembly user interface; for details on how to configure the policy in your OpenAPI source, see switch.
A switch construct provides a way to branch an assembly based on multiple conditions. Each switch component contains multiple cases, each corresponding to a section of the assembly that is only executed when the condition or operation specified by the case is met or used. Additionally, an otherwise case executes when no other case is fulfilled.
Add new cases by clicking + Case and add an otherwise
case by
clicking + Otherwise.
If multiple cases are fulfilled, the highest priority case will be executed. Change the priority of cases by clicking the Move up and Move down icons.
To configure a case to be executed if a specific operation is called, use the search operations field and select your operation from the list. You can refine the results of the search by typing in the search operations field.
To configure a case to be executed based on a GatewayScript condition, click edit condition and enter your script in the Condition editor
window. When you have supplied a script, you can edit your script either in the Condition field or by clicking edit condition.
If you are using the DataPower Gateway (v5 compatible), you enter your condition as GatewayScript directly in a code area in the Condition editor. If you are using DataPower API Gateway, the Condition editor provides a script builder to help you construct your condition script; for more information, see Using the switch policy condition editor.
To delete a case, click the Remove case icon .
If you want one or more policies or constructs to be executed when the condition of a case is fulfilled, drag the new policy or construct onto one of the dashed boxes that are displayed within the case's section of the switch construct.
Construct property details
You can configure a construct's properties in the property sheet in the assemble view.
Property | Required | Description |
---|---|---|
Title | No | A custom title for your construct when it is displayed in the canvas. If a title is not
specified, switch is used by default. |
Description | No | A description of your construct, it is not displayed on the canvas. |
case | Yes (one or more) |
Specify one or more operations or write a script for a condition. Use the Condition editor to construct your condition script. See Using the switch policy condition editor. Use GatewayScript to provide conditions. You
can reference variables by using the form
|
otherwise | No | Add an otherwise case if you want to execute a section of the assembly when no other cases are fulfilled. |