SetIntegrationRequest 政策

本页面适用于 ApigeeApigee Hybrid

查看 Apigee Edge 文档。

政策图标

概览

SetIntegrationRequest 政策允许您为要运行的集成创建请求对象。在该政策中,您必须配置 API 触发器的详细信息以及运行集成所需的输入参数。当您运行 SetIntegrationRequest 政策时,它会创建一个请求对象并将其保存在流变量中。该请求对象包含运行集成所需的所有信息。在此阶段,集成尚未运行。要运行集成,您必须调用 IntegrationCallout 政策或设置 IntegrationEndpoint。IntegrationCallout 政策和 IntegrationEndpoint 都需要请求对象才能运行集成。

此政策是一项可扩展政策,使用此政策可能会影响费用或使用情况,具体取决于您的 Apigee 许可。如需了解政策类型和使用情况影响,请参阅政策类型

<SetIntegrationRequest>

指定 SetIntegrationRequest 政策。

默认值 不适用
是否必需? 必需
类型 复杂类型
父元素 不适用
子元素 <ApiTrigger>
<DisplayName>
<IntegrationName>
<IntegrationRegion>
<Parameters>
<ProjectId>
<Request>
<ScheduleTime>

下表简要介绍了 <SetIntegrationRequest> 元素的子元素:

子元素 是否必需? 说明
<ApiTrigger> 必需 要在集成中调用的 API 触发器的名称。
<DisplayName> 可选 政策的自定义名称。
<IntegrationName> 可选 要运行的集成的名称。
<IntegrationRegion> 必需 集成所在的区域的名称。
<Parameters> 可选 集成的输入参数。
<ProjectId> 可选 具有您要运行的集成的 Google Cloud 项目的名称。
<Request> 可选 用于保存请求对象的流变量的名称。
<ScheduleTime> 可选 集成必须运行的时间。

SetIntegrationRequest 政策使用以下语法:

语法

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SetIntegrationRequest continueOnError="[true|false]" enabled="[true|false]" name="Set-Integration-Request">
  <DisplayName>POLICY_DISPLAY_NAME</DisplayName>
  <ProjectId ref="FLOW_VARIABLE_NAME">GOOGLE_CLOUD_PROJECT_ID</ProjectId>
  <IntegrationName ref="FLOW_VARIABLE_NAME">INTEGRATION_NAME</IntegrationName>
  <IntegrationRegion ref="FLOW_VARIABLE_NAME">INTEGRATION_REGION</IntegrationRegion>
  <ApiTrigger ref="FLOW_VARIABLE_NAME">API_TRIGGER_NAME</ApiTrigger>
  <ScheduleTime>PARAMETER_VALUE</ScheduleTime>
  <Parameters>
    <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE" ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Parameter>
    <ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE" ref="FLOW_VARIABLE_NAME>
      <Value ref="FLOW_VARIABLE_NAME>PARAMETER_VALUE</Value>
      <Value ref="FLOW_VARIABLE_NAME>PARAMETER_VALUE</Value>
      <Value ref="FLOW_VARIABLE_NAME>PARAMETER_VALUE</Value>
    </ParameterArray>
  </Parameters>
  <Request>FLOW_VARIABLE_NAME</Request>
</SetIntegrationRequest>

示例

以下示例展示了 SetIntegrationRequest 政策定义:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SetIntegrationRequest continueOnError="false" enabled="true" name="Set-Integration-Request">
  <DisplayName>Set Integration Request Policy</DisplayName>
  <ProjectId ref="my_projectid_var">apigee_staging_1</ProjectId>
  <IntegrationName ref="my_integration_ref">integration_1</IntegrationName>
  <IntegrationRegion ref="my_integration_ref">asia-east1</IntegrationRegion>
  <ApiTrigger ref="my_api_trigger_ref">API-Trigger-2</ApiTrigger>
  <ScheduleTime>2022-01-15T01:30:15Z</ScheduleTime>
  <Parameters>
    <Parameter name="my_str_param" type="string" ref="flow_var_1">someText</Parameter>
    <ParameterArray name="my_array_param" type="integer" ref="flow_var_2">
      <Value ref="flow_var_3">1</Value>
      <Value ref="flow_var_4">2</Value>
      <Value ref="flow_var_5">3</Value>
    </ParameterArray>
  </Parameters>
  <Request>my_request_var</Request>
</SetIntegrationRequest>

此元素具有所有政策中常见的以下属性:

属性 默认 是否必需? 说明
name 必需

政策的内部名称。name 属性的值可以包含字母、数字、空格、连字符、下划线和英文句点。此值不能超过 255 个字符。

(可选)使用 <DisplayName> 元素在管理界面代理编辑器中给政策添加不同的自然语言名称标签。

continueOnError false 可选 设置为 false 可在政策失败时返回错误。这是大多数政策的预期行为。设置为 true,即使在政策失败后,仍可以继续执行流。另请参阅:
enabled true 可选 设置为 true 可实施政策。 设为 false 可关闭政策。即使政策仍附加到某个流,也不会强制执行该政策。
async   false 已弃用 此属性已弃用。

子元素参考

本部分介绍 <SetIntegrationRequest> 的子元素。

<DisplayName>

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, more natural-sounding name.

The <DisplayName> element is common to all policies.

Default Value N/A
Required? Optional. If you omit <DisplayName>, the value of the policy's name attribute is used.
Type String
Parent Element <PolicyElement>
Child Elements None

The <DisplayName> element uses the following syntax:

Syntax

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

Example

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

The <DisplayName> element has no attributes or child elements.

<ProjectId>

指定 Google Cloud 项目的名称。

Apigee 会将您为此元素指定的值分配给 integration.project.id 流变量。

默认值 不适用
是否必需? 可选
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<ProjectId> 元素使用以下语法:

语法

<ProjectId ref="FLOW_VARIABLE_NAME">GOOGLE_CLOUD_PROJECT_ID</ProjectId>

示例

以下示例将政策配置为使用 my_projectid_var 流变量来提取项目 ID,如果流变量在运行时无法解析,请使用 apigee_staging_1 作为项目 ID:

<ProjectId ref="my_projectid_var">apigee_staging_1</ProjectId>

下表介绍 <ProjectId> 的特性:

属性 是否必需? 类型 说明
ref 可选 字符串 指定 Apigee 应从中读取 Google Cloud 项目 ID 的流变量。您可以通过以下任一方式设置 <ProjectId> 元素:
  • <ProjectId>val</ProjectId>:使用 val 作为项目 ID。
  • <ProjectId ref="refval"/>:动态解析 refval 以确定项目 ID。如果已解析的项目 ID 无效或未解析 refval,Apigee 将报告异常。
  • <ProjectId ref="refval">val</ProjectId>:动态解析 refval 以确定项目 ID。如果解析的项目 ID 无效,Apigee 将报告异常。如果 refval 无法解析,请使用 val 作为项目 ID。

<IntegrationName>

指定要运行的集成。

Apigee 会将您为此元素指定的值分配给 integration.name 流变量。

集成名称必须符合以下命名要求:

  • 必须以字母或数字开头和结尾。
  • 不能包含空格。
  • 不能包含两个连续的短划线或下划线字符。
默认值 不适用
是否必需? 可选
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<IntegrationName> 元素使用以下语法:

语法

<IntegrationName ref="FLOW_VARIABLE_NAME">INTEGRATION_NAME</IntegrationName>

示例

以下示例将政策配置为使用 my_integration_ref 流变量来提取集成名称,如果流变量在运行时无法解析,请使用 integration_1 作为集成名称:

<IntegrationName ref="my_integration_ref">integration_1</IntegrationName>

下表介绍 <IntegrationName> 的特性:

属性 是否必需? 类型 说明
ref 可选 字符串 指定 Apigee 应从中读取集成名称的流变量。您可以通过以下任一方式设置 <IntegrationName> 元素:
  • <IntegrationName>val</IntegrationName>:使用 val 作为集成名称。
  • <IntegrationName ref="refval"/>:动态解析 refval 以确定集成名称。如果已解析的集成名称无效或未解析 refval,Apigee 将报告异常。
  • <IntegrationName ref="refval">val</IntegrationName>:动态解析 refval 以确定集成名称。如果解析的集成名称无效,Apigee 将报告异常。如果 refval 无法解析,请使用 val 作为集成名称。

<IntegrationRegion>

指定存在集成的区域。

在运行时,Apigee 会将该元素的值分配给 integration.region 流变量,创建基于区域的目标网址,并将网址存储在 integration.target.url 流变量中。

基于区域的目标网址采用以下格式:https://integration.region-integrations.googleapis.com

Apigee Integration 必须支持集成区域。如需了解 Application Integration 支持的区域,请参阅支持的区域

默认值 不适用
是否必需? 必需
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<IntegrationRegion> 元素使用以下语法:

语法

<IntegrationRegion ref="FLOW_VARIABLE_NAME">INTEGRATION_REGION</IntegrationRegion>

示例

以下示例将政策配置为使用 my_integration_region_ref 流变量提取集成区域,而且如果流变量在运行时无法解析,则使用 asia-east1 作为集成区域:

<IntegrationRegion ref="my_integration_region_ref">asia-east1</IntegrationRegion>

下表介绍 <IntegrationRegion> 的特性:

属性 是否必需? 类型 说明
ref 可选 字符串 指定 Apigee 应从中读取集成区域的流变量。您可以通过以下任一方式设置 <IntegrationRegion> 元素:
  • <IntegrationRegion>val</IntegrationRegion>:使用 val 作为集成区域。
  • <IntegrationRegion ref="refval"/>:动态解析 refval 以确定集成区域。如果已解析的集成区域无效或未解析 refval,Apigee 将报告异常。
  • <IntegrationRegion ref="refval">val</IntegrationRegion>:动态解析 refval 以确定集成区域。如果解析的集成区域无效,Apigee 将报告异常。如果 refval 无法解析,请使用 val 作为集成区域。

<ApiTrigger>

指定要运行的 API 触发器。

您必须按 api_trigger/API_TRIGGER_NAME 格式指定 API 触发器名称。

Apigee 会将您为此元素指定的值分配给 integration.api.trigger 流变量。

如果您指定了 <IntegrationName>,则系统仅会运行集成的 API 触发器。但是,如果您未指定 <IntegrationName>,则系统会运行具有指定 API 触发器的所有集成。

默认值 不适用
是否必需? 必需
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<ApiTrigger> 元素使用以下语法:

语法

<ApiTrigger ref="FLOW_VARIABLE_NAME">API_TRIGGER_NAME</ApiTrigger>

示例

以下示例将政策配置为使用 my_api_trigger_ref 流变量来提取 API 触发器名称,如果流变量在运行时无法解析,请使用 api_trigger/API-Trigger-2 作为 API 触发器名称:

<ApiTrigger ref="my_api_trigger_ref">api_trigger/API-Trigger-2</ApiTrigger>

下表介绍 <ApiTrigger> 的特性:

属性 是否必需? 类型 说明
ref 可选 字符串 指定 Apigee 应从中读取 API 触发器名称的流变量。您可以通过以下任一方式设置 <ApiTrigger> 元素:
  • <ApiTrigger>val</ApiTrigger>:使用 val 作为 API 触发器名称。
  • <ApiTrigger ref="refval"/>:动态解析 refval 以确定触发器名称。如果已解析的 API 触发器名称无效或未解析 refval,Apigee 将报告异常。
  • <ApiTrigger ref="refval">val</ApiTrigger>:动态解析 refval 以确定触发器名称。如果解析的 API 触发器名称无效,Apigee 将报告异常。如果 refval 无法解析,请使用 val 作为触发器名称。

<ScheduleTime>

指定集成必须运行的时间。

如果时间早于或等于当前时间,则集成会立即运行。您必须以 yyyy-mm-ddThh:mm:ssZ 格式指定时间,其中 Z 是 UTC 时区。例如,如果您指定 2022-01-15T01:30:15Z,则集成安排在世界协调时间 (UTC) 2022 年 1 月 15 日 1 点 30 分 15 秒运行。您还可以使用与世界协调时间 (UTC) 有所偏差的其他标准时来指定时区。例如,如果您指定 2022-01-15T01:30:15-08:00,则集成安排在太平洋标准时间 2022 年 1 月 15 日 1 点 30 分 15 秒运行。如需详细了解时间格式,请参阅日期和时间的组合表示法

默认值 不适用
是否必需? 可选
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<ScheduleTime> 元素使用以下语法:

语法

<ScheduleTime>PARAMETER_VALUE</ScheduleTime>

示例

以下示例将集成安排在 2022-01-15T01:30:15Z 运行:

<ScheduleTime>2022-01-15T01:30:15Z</ScheduleTime>

<Parameters>

指定运行集成所需的输入参数。

您可以指定单个参数或参数数组。

默认值 不适用
是否必需? 可选
类型 复杂类型
父元素 <SetIntegrationRequest>
子元素 <Parameter>
<ParameterArray>

下表介绍 <Parameters> 的特性:

属性 是否必需? 类型 说明
substitutionVariableChar 可选 Char 允许您设置自定义分隔符,以将流变量值作为 <Parameter> 子元素中的模板参数传递。

<Parameters> 元素使用以下语法:

语法

<Parameters substitutionVariableChar="SUBSTITUTION_CHAR">
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE" ref="FLOW_VARIABLE_NAME" >PARAMETER_VALUE</Parameter>
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE">SUBSTITUTION_CHAR FLOW_VARIABLE_NAME SUBSTITUTION_CHAR</Parameter>
  <ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE ref="FLOW_VARIABLE_NAME"">
    <Value>PARAMETER_VALUE</Value>
    <Value ref="FLOW_VARIABLE_NAME"/>
    <Value ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Value>
  </ParameterArray>
</Parameters>

示例

以下示例将初始化 my_str_param 参数和 my_array_param 参数数组:

<Parameters substitutionVariableChar="#">
  <Parameter name="my_str_param" type="string" ref="flow_var_1">someText</Parameter>
  <Parameter name="strVar" type="string">#flowvar1#</Parameter>
  <ParameterArray name="my_array_param" type="integer" ref="flow_var_2">
    <Value>1</Value>
    <Value ref="flow_var_3"/>
    <Value ref="flow_var_4">3</Value>
  </ParameterArray>
</Parameters>

Apigee 将空的 <Parameter><ParameterArray> 元素视为 null 值。例如,<Parameter></Parameter><ParameterArray></ParameterArray> 等声明被视为 null 值。

<Parameter>

指定输入参数。

默认值 不适用
是否必需? 可选
类型 字符串
父元素 <Parameters>
子元素

您可以通过以下方式指定参数值:

  • <Parameter name="my_param" type="string">val</Parameter>:使用 val 作为参数值。如果 val 无效,Apigee 会报告异常。
  • <Parameter name="my_param" type="string" ref="refval"/>:解析 refval 流变量并使用其值。如果解析后的 refval 值无效或 refval 无法解析,则 Apigee 会报告异常。
  • <Parameter name="my_param" type="string" ref="refval">val</Parameter>:在运行时解析 refval 流变量并使用其值。如果解析的 refval 值无效,Apigee 将报告异常。如果 refval 无法解析,则 Apigee 会使用 val 作为参数值。
  • <Parameter name="my_param" type="json">{"name":"$#flowval#$"}</Parameter>:使用 $#FLOW_VARIABLE_NAME#$ 将流变量值作为 Parameter 中的模板参数。Apigee 会在运行时解析 flowval 流变量并使用其值。如果解析的 flowval 值无效,则会报告异常。
  • <Parameter name="my_param" type="json">{"name":"SUBSTITUTION_CHAR flowval SUBSTITUTION_CHAR"}</Parameter>:其中 SUBSTITUTION_CHAR 表示为 <Parameters> 父元素的 substitutionVariableChar 属性指定的值。Apigee 会在运行时解析 flowval 流变量并使用其值。如果解析的 flowval 值无效,则会报告异常。

<Parameter> 元素使用以下语法:

语法
<Parameters substitutionVariableChar="SUBSTITUTION_CHAR">
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE">PARAMETER_VALUE</Parameter>
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE" ref="FLOW_VARIABLE_NAME"/>
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE" ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Parameter>
  <Parameter name="PARAMETER_NAME" type="json">$#FLOW_VARIABLE_NAME#$</Parameter>
  <Parameter name="PARAMETER_NAME" type="PARAMETER_DATATYPE">SUBSTITUTION_CHAR FLOW_VARIABLE_NAME SUBSTITUTION_CHAR</Parameter>
</Parameters>
示例 1

以下示例将 my_str_param 参数声明为字符串,并将值设置为 someText

<Parameters>
  <Parameter name="my_str_param" type="string">someText</Parameter>
</Parameters>
示例 2

以下示例将 my_double_param 参数声明为双精度型参数,并将 flow_var 流变量的值分配给该参数。

<Parameters>
  <Parameter name="my_double_param" type="double" ref="flow_var"/>
</Parameters>
示例 3

以下示例将值设置为 my_int_param_1 整数参数。

<Parameters>
  <Parameter name="my_int_param_1" type="integer" ref="flow_var_1">96</Parameter>
</Parameters>

在此示例中,如果 flow_var_1 流变量成功解析,则 my_int_param_1 设置为流变量的值。但是,如果 flow_var_1 无法解析,则 my_int_param_1 设置为 96

示例 4

以下示例设置 my_json_param_1my_json_param_2 JSON 参数的值。

<Parameters>
  <Parameter name="my_json_param_1" type="json" ref="flow_var_1">{name:"Apple", color:"Red"}</Parameter>
  <Parameter name="my_json_param_2" type="json">{name:"Banana", color:"Yellow"}</Parameter>
</Parameters>

在此示例中,如果 flow_var_1 流变量成功解析,则 my_json_param_1 设置为 flow_var_1 流变量的值。但是,如果 flow_var_1 无法解析,则 my_json_param_1 设置为 {name:"Apple", color:"Red"}。由于未指定 ref 特性,因此 my_json_param_2 参数设置为 {name:"Banana", color:"Yellow"}

示例 5

以下示例使用默认模板中传递的流变量值设置 template_json_param JSON 参数的值。

  <Parameters>
    <Parameter name="template_json_param" type="json">{"name":"$#flow_var_1#$"}</Parameter>
</Parameters>
  

在此示例中,如果 flow_var_1 流变量成功解析,则 template_json_param 设置为 flow_var_1 流变量的值。但是,如果 flow_var_1 无法解析,则 Apigee 会抛出异常。

示例 6

以下示例使用 substitutionVariableChar 属性设置 template_json_param JSON 参数的值。

<Parameters substitutionVariableChar="#">
    <Parameter name="template_json_param" type="json">{"name":"#flow_var_1#"}</Parameter>
</Parameters>
  

在此示例中,如果 flow_var_1 流变量成功解析,则 template_json_param 设置为 flow_var_1 流变量的值。但是,如果 flow_var_1 无法解析,则 Apigee 会抛出异常。

下表介绍 <Parameter> 的特性:

属性 是否必需? 类型 说明
name 必需 字符串 参数的名称。
type 必需 字符串 参数的数据类型。支持的类型包括 integerstringbooleandoublejson
ref 可选 字符串 指定 Apigee 应从中读取参数值的流变量。Apigee 使用以下条件来设置参数值:
  • 如果流变量在运行时解析且有效,则 Apigee 会使用流变量的值。
  • 如果流变量在运行时解析但无效,则 Apigee 会报告异常。
  • 如果流变量在运行时未解析,则 Apigee 会使用 <Parameter> 元素值。如果元素值无效,则 Apigee 会报告错误。

<ParameterArray>

指定输入参数数组。

默认值 不适用
是否必需? 可选
类型 复杂类型
父元素 <Parameters>
子元素 <Value>

<Parameters> 元素中可以有多个 <ParameterArray> 元素。对于参数数组,您可以通过指定实际值或在 ref 特性中指定流变量来设置数组元素的值。如果您指定流变量,则数组元素将设置为流变量的值。本部分中的示例介绍了可用来配置 <ParameterArray> 元素的各种方法。

<ParameterArray> 元素使用以下语法:

语法
<Parameters>
  <ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE" ref="FLOW_VARIABLE_NAME">
    <Value ref="FLOW_VARIABLE_NAME"/>
    <Value ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Value>
    <Value>PARAMETER_VALUE</Value>
  </ParameterArray>
  <ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE" ref="FLOW_VARIABLE_NAME"/>
  <ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE">
    <Value ref="FLOW_VARIABLE_NAME"/>
    <Value ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Value>
    <Value>PARAMETER_VALUE</Value>
  </ParameterArray>
<Parameters/>
Example-1

以下示例将 my_array_param 声明为整数数组,并将数组元素的值设置为 123

<Parameters>
  <ParameterArray name="my_array_param" type="integer">
    <Value>1</Value>
    <Value>2</Value>
    <Value>3</Value>
  </ParameterArray>
<Parameters/>
Example-2

以下示例将 my_array_param 声明为双精度型数组,其中:

  • 第一个元素设置为 flow_var_1 流变量的值。
  • 第二个元素设置为 3.0
<Parameters>
  <ParameterArray name="my_array_param" type="double">
    <Value ref="flow_var_1"/>
    <Value>3.0</Value>
  </ParameterArray>
<Parameters/>
Example-3

以下示例将 my_array_param 声明为布尔值数组,并将其设置为 flow_var_1 流变量的值。

<Parameters>
  <ParameterArray name="my_array_param" type="boolean" ref="flow_var_1">
    <Value>true</Value>
    <Value>false</Value>
    <Value>false</Value>
  </ParameterArray>
<Parameters/>

在此示例中,如果 flow_var_1 成功解析,则 my_array_param 会设置为 flow_var_1 数组的值。但是,如果 flow_var_1 无法解析,则 my_array_param 数组将设置为 Value 元素的值。

Example-4

以下示例将 my_array_param 声明为 JSON 数组,并将其设置为 flow_var_1 流变量的值。

<Parameters>
  <ParameterArray name="my_array_param" type="json" ref="flow_var_1"/>
<Parameters/>

在此示例中,如果 flow_var_1 成功解析,则 my_array_param 会设置为 flow_var_1 数组的值。但是,如果 flow_var_1 无法解析,则 Apigee 会报告异常。

Example-5

以下示例将 my_array_param 声明为字符串数组,并将其设置为 flow_var_1 流变量的值。

<Parameters>
  <ParameterArray name="my_array_param" type="string" ref="flow_var_1">
    <Value ref="flow_var_2"/>
    <Value>test_string</Value>
  </ParameterArray>
<Parameters/>

在此示例中,如果 flow_var_1 成功解析,则 my_array_param 会设置为 flow_var_1 数组的值。仅当 flow_var_1 无法解析时,my_array_param 才会设置为 <Value> 元素中指定的值。

下表介绍 <ParameterArray> 的特性:

属性 是否必需? 类型 说明
name 必需 字符串 参数数组的名称。
type 必需 字符串 参数数组的数据类型。支持的类型包括 integerstringbooleandouble
ref 可选 字符串 指定 Apigee 应从中读取数组值的流变量。Apigee 使用以下条件来设置参数值:
  • 如果流变量在运行时解析且有效,则 Apigee 会使用流变量的值。
  • 如果流变量在运行时解析但无效,则 Apigee 会报告异常。
  • 如果流变量在运行时未解析,则 Apigee 会使用 <Value> 元素中指定的值。
<Value>

指定数组元素的值。

默认值 不适用
是否必需? 可选
类型 字符串
父元素 <ParameterArray>
子元素

数组的每个元素都必须是单独的 <Value> 元素。您可以通过以下方式指定该值:

  • <Value>val</Value>:使用 val 作为元素值。如果 val 无效,Apigee 会报告异常。
  • <Value ref="refval"/>:解析 refval 流变量并使用其值。如果解析后的 refval 值无效或 refval 无法解析,则 Apigee 会报告异常。
  • <Value ref="refval">val</Value>:在运行时解析 refval 流变量并使用其值。如果解析的 refval 值无效,Apigee 将报告异常。如果 refval 无法解析,则 Apigee 会使用 val 作为元素值。
  • <Value>val1 $#flowval#$</Value>:使用 $#FLOW_VARIABLE_NAME#$ 将流变量值作为模板值传递给 Value。Apigee 会在运行时解析 flowval 流变量并使用其值。如果解析的 flowval 值无效,则会报告异常。

<Value> 元素使用以下语法:

语法
<ParameterArray name="ARRAY_NAME" type="ARRAY_DATATYPE" ref="FLOW_VARIABLE_NAME">
  <Value>PARAMETER_VALUE</Value>
  <Value ref="FLOW_VARIABLE_NAME"/>
  <Value ref="FLOW_VARIABLE_NAME">PARAMETER_VALUE</Value>
</ParameterArray>
示例 1

以下示例将 my_array_param 声明成值为 123 的整数参数数组:

<ParameterArray name="my_array_param" type="integer">
  <Value>1</Value>
  <Value>2</Value>
  <Value>3</Value>
</ParameterArray>
示例 2

以下示例将 my_array_param 声明成值为 flow_var_1flow_var_2 流变量的字符串参数数组:

<ParameterArray name="my_array_param" type="string">
  <Value ref="flow_var_1"/>
  <Value ref="flow_var_2"/>
</ParameterArray>
示例 3

以下示例将 my_array_param 声明为字符串参数数组:

<ParameterArray name="my_array_param" type="string">
   <Value ref="flow_var_1">string_1</Value>
   <Value ref="flow_var_2">string_2</Value>
</ParameterArray>

在此示例中,如果流变量成功解析,则数组元素值将设置为 flow_var_1 流变量的值。但是,如果 flow_var_1 无法解析,则数组元素值设置为 string_1

示例 4

以下示例使用模板中传递的流变量值设置 template_strArray_param 字符串数组参数的值。

  <Parameters>
    <ParameterArray name="template_strArray_param" type="string">
    <Value>apple $#flow_var_1#$</Value>
    </ParameterArray>
  </Parameters>
  

在此示例中,如果流变量成功解析,则数组元素值将设置为 flow_var_1 流变量的值。但是,如果 flow_var_1 无法解析,则 Apigee 会抛出异常。

下表介绍 <Value> 的特性:

属性 是否必需? 类型 说明
ref 可选 字符串 指定 Apigee 应从中读取参数值的流变量。Apigee 使用以下条件来设置参数值:
  • 如果流变量在运行时解析且有效,则 Apigee 会使用流变量的值。
  • 如果流变量在运行时解析但无效,则 Apigee 会报告异常。
  • 如果流变量在运行时未解析,则 Apigee 会使用 <Value> 元素的值。如果元素值无效,则 Apigee 会报告错误。

<Request>

指定用于保存请求的流变量名称。

政策执行后,会创建一个新的请求消息对象,并将该对象保存在 FLOW_VARIABLE_NAME 变量中,您可以查询该变量来读取请求。

如果您未指定流变量名称,则政策会将请求保存在请求消息中,并覆盖现有请求消息(如果有)。

默认值 request
是否必需? 可选
类型 字符串
父元素 <SetIntegrationRequest>
子元素

<Request> 元素使用以下语法:

语法

<Request>FLOW_VARIABLE_NAME</Request>

示例

以下示例将请求对象保存在 my_request_var 流变量中:

<Request>my_request_var</Request>

错误代码

This section describes the fault codes, error messages, and the fault variables set by Apigee when this policy triggers an error. This information is essential 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.setintegrationrequest.EmptyParameterArray 500

This error occurs when the <ParameterArray> element has the name and type attributes, but doesn't have the ref attribute or a <Value> element.

steps.setintegrationrequest.EmptyParameterArrayValue 500

This error occurs when the <Value> element is empty and the ref attribute is not set.

steps.setintegrationrequest.InvalidResolvedFlowVariable 500

This error occurs when the flow variable specified in the ref attribute of an element fails to resolve to a valid value.

  • For the ProjectId, IntegrationName, or the ApiTrigger elements, this error occurs if the flow variable resolves to a null, an empty string, or an invalid data type.

    A valid value for these elements is as follows:

    • ProjectId: See the naming requirements for Project ID in the Before you begin section.
    • IntegrationName: See the naming requirements for the IntegrationName element.
    • ApiTrigger: The name should start with api_trigger/.
  • For the ParameterArray element, this error occurs if the flow variable resolves to an empty string.
steps.setintegrationrequest.MismatchedTypeAndResolvedRef 500

This error occurs when the flow variable specified in the ref attribute of the <Parameter> element resolves, but the flow variable value's data type doesn't match the data type specified in the type attribute.

steps.setintegrationrequest.MismatchedTypeAndResolvedRefOfParameterArray 500

This error occurs when the flow variable specified in the ref attribute of the <ParameterArray> element resolves, but the flow variable value's data type doesn't match with the data type specified in the type attribute.

steps.setintegrationrequest.MismatchedTypeAndResolvedRefOfParameterArrayValue 500

This error occurs when the flow variable specified in the ref attribute of the <Value> element resolves, but the flow variable value's data type doesn't match with the data type specified in the type attribute of its parent element (<ParameterArray>).

steps.setintegrationrequest.RequestVariableNotMessageType 500 This error occurs when the flow variable specified by the Request element is not of message type.
steps.setintegrationrequest.RequestVariableNotRequestMessageType 500 This error occurs when the flow variable specified by the Request element is not of Request message type.
steps.setintegrationrequest.UnresolvedVariable 500

This error occurs when Apigee can't resolve the flow variables specified in the <Parameter>, <ParameterArray>, or the <Value> elements.

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 The fault.name can match to any of the faults listed in the Runtime errors table. The fault name is the last part of the fault code. fault.name Matches "UnresolvedVariable"
SetIntegrationRequest.POLICY_NAME.failed POLICY_NAME is the user-specified name of the policy that threw the fault. SetIntegrationRequest.set-integration-request-1.failed = true
For more information about policy errors, see What you need to know about policy errors.

相关主题

如需详细了解 Application Integration 功能,请参阅 Application Integration 概览