AssertCondition-Richtlinie

Diese Seite gilt für Apigee und Apigee Hybrid.

Apigee Edge-Dokumentation aufrufen

Richtliniensymbol

Übersicht

Die AssertCondition-Richtlinie wertet zur Laufzeit eine bedingte Anweisung in den Anfrage- oder Antwortabläufen aus. Sie können eine Bedingung anhand der Ablaufvariablen definieren und sie mit dieser Richtlinie festlegen. Eine Bedingung wird immer als boolescher Wert ausgewertet, entweder als wahr (true) oder falsch (false). Weitere Informationen zum Schreiben einer bedingten Anweisung finden Sie in der Referenz für Bedingungen.

Nach Auswertung der Bedingung speichert die AssertCondition-Richtlinie das Ergebnis der Auswertung in der Ablaufvariable assertcondition.policy-name.truthValue. Sie können die sich daraus ergebende Ablaufvariable in Ihren nachfolgenden Callouts oder in der orchestrierten Logik verwenden. Wird eine Bedingung als wahr ausgewertet, wird für den Wert der Variablen true festgelegt, andernfalls false. Wenn Sie mehrere AssertCondition-Richtlinien definiert haben, können Sie die Variable anhand des policy-name im Variablennamen eindeutig ermitteln.

Diese Richtlinie ist eine Standardrichtlinie, die in jeder Umgebung bereitgestellt werden kann. Informationen zu Richtlinientypen und zur Verfügbarkeit bei jedem Umgebungstyp finden Sie unter Richtlinientypen.

<AssertCondition>

Definiert eine <AssertCondition>-Richtlinie. Mit dieser Richtlinie können Sie eine bedingte Anweisung auswerten, die eine Bedingung oder mehrere Bedingungen enthält, die durch einen logischen Operator verknüpft sind. Informationen zu allen für eine Bedingung unterstützten Operatoren finden Sie unter Operatoren.

Das Ergebnis einer bedingten Anweisung ist ein boolescher Wert, der entweder true oder false sein kann.
Standardwert
Erforderlich? Erforderlich
Typ Komplexer Typ
Übergeordnetes Element
Untergeordnete Elemente <Condition>
<DisplayName>

Die folgende Tabelle enthält eine allgemeine Beschreibung der untergeordneten Elemente von <AssertCondition>:

Untergeordnetes Element Erforderlich? Beschreibung
<Condition> Ja Legt die Bedingung fest, die ausgewertet werden soll.
<DisplayName> Optional Ein benutzerdefinierter Name für die Richtlinie.

Das <AssertCondition>-Element verwendet die folgende Syntax:

Syntax

<?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>

Beispiel

Im folgenden Beispiel wird geprüft, ob die Variable google.dialogflow.my-prefix.claimAmount größer als 0 und kleiner als 1.000 ist.

<?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>

In diesem Beispiel:

  • Wenn der Wert der google.dialogflow.my-prefix.claimAmount-Variablen 500 ist, wird die Bedingung als wahr ausgewertet und die Variable assertcondition.MyAssertCondition.truthValue auf true gesetzt.
  • Wenn der Wert der Variablen google.dialogflow.my-prefix.claimAmount aber 1.200 ist, wird die Variable assertcondition.MyAssertCondition.truthValue auf false gesetzt.

This element has the following attributes that are common to all policies:

Attribute Default Required? Description
name N/A Required

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

continueOnError false Optional Set to false to return an error when a policy fails. This is expected behavior for most policies. Set to true to have flow execution continue even after a policy fails. See also:
enabled true Optional Set to true to enforce the policy. Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.
async   false Deprecated This attribute is deprecated.

Verweis auf untergeordnetes Element

In diesem Abschnitt werden die untergeordneten Elemente von <AssertCondition> beschrieben.

<Condition>

Legt die Bedingung fest, die ausgewertet werden soll. Weitere Informationen zum Schreiben einer bedingten Anweisung in Apigee finden Sie in der Referenz für Bedingungen.

Standardwert
Erforderlich? Erforderlich
Typ String
Übergeordnetes Element <AssertCondition>
Untergeordnete Elemente Keine

<DisplayName>

Wird zusätzlich zum Attribut name verwendet, um die Richtlinie im Proxy-Editor der Verwaltungs-UI mit einem anderen, natürlicher klingenden Namen zu versehen.

Das Element <DisplayName> ist für alle Richtlinien gleich.

Standardwert
Erforderlich? Optional. Wenn Sie <DisplayName> weglassen, wird der Wert des Attributs name der Richtlinie verwendet.
Typ String
Übergeordnetes Element <PolicyElement>
Untergeordnete Elemente Keine

Das <DisplayName>-Element verwendet die folgende Syntax:

Syntax

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

Beispiel

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

Das <DisplayName>-Element hat keine Attribute oder untergeordneten Elemente.

Fehlercodes

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.