AssertCondition ポリシー

このページは ApigeeApigee ハイブリッドに適用されます。

Apigee Edge のドキュメントを表示する。

ポリシー アイコン

概要

AssertCondition ポリシーは、リクエスト フローまたはレスポンス フローのランタイムで条件文を評価します。フロー変数に基づいて条件を定義し、このポリシーを使用して条件を表明できます。条件は常にブール値(true または false)に評価されます。条件文を記述する方法の詳細については、条件のリファレンスをご覧ください。

条件を評価した後、AssertCondition ポリシーでは、評価の結果を assertcondition.policy-name.truthValue フロー変数に保存します。結果として生成されるフロー変数は、後続のコールアウトまたはオーケストレーションされたロジックで使用できます。条件が true と評価された場合、変数の値は true に設定されます。それ以外の場合は false に設定されます。複数の AssertCondition ポリシーを定義している場合は、変数名の policy-name が変数を一意に識別するために役立ちます。

このポリシーは、標準ポリシーであり、任意の環境タイプにデプロイできます。ポリシータイプと各環境タイプで使用可能かどうかは、ポリシータイプをご覧ください。

<AssertCondition>

<AssertCondition> ポリシーを定義します。このポリシーを使用すると、1 つまたは複数の条件が論理演算子で結合されている条件文を評価できます。条件でサポートされるすべての演算子については、演算子をご覧ください。

条件文の結果は、true または false のいずれかのブール値です。
デフォルト値 なし
必須かどうか 必須
複合型
親要素 なし
子要素 <Condition>
<DisplayName>

次の表は、<AssertCondition> の子要素の概要をまとめたものです。

子要素 必須かどうか 説明
<Condition> 評価する条件を指定します。
<DisplayName> 省略可 ポリシーのカスタム名。

<AssertCondition> 要素の構文は次のとおりです。

構文

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition">
    <!-- Display name for this policy -->
    <DisplayName>DISPLAY_NAME</DisplayName>
    <!-- Assertion's condition where operators are defined -->
    <Condition>CONDITIONAL_STATEMENT</Condition>
</AssertCondition>

次の例では、google.dialogflow.my-prefix.claimAmount 変数が 0 より大きく 1,000 より小さいかどうかをチェックします。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition continueOnError="false" enabled="true"
        name="MyAssertCondition">
    <DisplayName>Assert My Condition</DisplayName>
    <Condition>(google.dialogflow.my-prefix.claimAmount > 0)
                and
               (google.dialogflow.my-prefix.claimAmount LesserThan 1000)</Condition>
</AssertCondition>

この例では、次のようになります。

  • google.dialogflow.my-prefix.claimAmount 変数の値が 500 の場合、条件は true と評価されるため、assertcondition.MyAssertCondition.truthValue 変数は true に設定されます。
  • ただし、google.dialogflow.my-prefix.claimAmount 変数の値が 1,200 の場合、assertcondition.MyAssertCondition.truthValue 変数は false に設定されます。

この要素には、すべてのポリシーに共通する次の属性があります。

属性 デフォルト 必須かどうか 説明
name なし 必須

ポリシーの内部名。name 属性の値には、英字、数字、スペース、ハイフン、アンダースコア、ピリオドを使用できます。この値は 255 文字を超えることはできません。

管理 UI プロキシ エディタで <DisplayName> 要素を追加して、ポリシーのラベルに使用する別の自然言語名を指定することもできます。

continueOnError false 省略可 ポリシーが失敗したときにエラーを返す場合は、false に設定します。これは、ほとんどのポリシーで想定される動作です。ポリシーが失敗した後もフローの実行を続行する場合は、true に設定します。関連情報:
enabled true 省略可 ポリシーを適用するには、true に設定します。ポリシーを無効にするには、false に設定します。ポリシーがフローに接続されている場合でも適用されません。
async   false 非推奨 この属性は非推奨となりました。

子要素のリファレンス

このセクションでは、<AssertCondition> の子要素について説明します。

<Condition>

評価する条件を指定します。Apigee で条件文を記述する方法の詳細については、条件のリファレンスをご覧ください。

デフォルト値 なし
必須かどうか 必須
文字列
親要素 <AssertCondition>
子要素 なし

<DisplayName>

name 属性に加えて、管理 UI プロキシ エディタでポリシーを別の、より自然な響きの名前でラベル付けするために使います。

<DisplayName> 要素はすべてのポリシーに共通です。

デフォルト値 なし
必須かどうか 省略可。<DisplayName> を省略した場合、ポリシーの name 属性の値が使用されます。
文字列
親要素 <PolicyElement>
子要素 なし

<DisplayName> 要素の構文は次のとおりです。

構文

<PolicyElement>
  <DisplayName>POLICY_DISPLAY_NAME</DisplayName>
  ...
</PolicyElement>

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

<DisplayName> 要素に属性や子要素はありません。

エラーコード

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause
steps.assertcondition.ConditionEvaluationFailed 500 Failed to evaluate the conditional statement. There can be many reasons for this error, including incorrect values in the variables at run time.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause
InvalidCondition The policy was not able to validate the conditional statement. There can be many reasons for this error, including malformed conditions or use of unsupported operators.

Fault variables

Whenever there are execution errors in a policy, Apigee generates error messages. You can view these error messages in the error response. Many a time, system generated error messages might not be relevant in the context of your product. You might want to customize the error messages based on the type of error to make the messages more meaningful.

To customize the error messages, you can use either fault rules or the RaiseFault policy. For information about differences between fault rules and the RaiseFault policy, see FaultRules vs. the RaiseFault policy. You must check for conditions using the Condition element in both the fault rules and the RaiseFault policy. Apigee provides fault variables unique to each policy and the values of the fault variables are set when a policy triggers runtime errors. By using these variables, you can check for specific error conditions and take appropriate actions. For more information about checking error conditions, see Building conditions.

The following table describes the fault variables specific to this policy.

Variables Where Example
fault.name="FAULT_NAME" FAULT_NAME is the name of the fault, as listed in the Runtime errors table. The fault name is the last part of the fault code. fault.name Matches "ConditionEvaluationFailed"
AssertCondition.POLICY_NAME.failed POLICY_NAME is the user-specified name of the policy that threw the fault. AssertCondition.My-AssertCondition.failed = true
For more information about policy errors, see What you need to know about policy errors.