您正在查看 Apigee 和 Apigee Hybrid 說明文件。
查看
Apigee Edge 說明文件。
InvalidIndex
錯誤訊息
透過 Apigee UI 或 API 部署 API Proxy 時失敗,並顯示以下錯誤訊息:
Error in deployment for environment [environment] The revision is deployed, but traffic cannot flow. AssignMessage[policy_name]: index must be greater than zero in [attribute].[index]
錯誤訊息示例
Error in deployment for environment test.
The revision is deployed, but traffic cannot flow.
AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0
螢幕截圖範例
原因
如果指派訊息政策的 <Copy>
和/或 <Remove>
元素中指定的索引為 0 或負數,則 API Proxy 的部署作業會失敗。
���例來說,如果您傳遞多個同名查詢參數,可以將這些參數做為已編入索引的流程變數存取。假設您想將 3 位學生的 ID 做為查詢參數傳遞,可以按照下列方式操作:
https://$EXTERNAL_IP/$PROXY_BASEPATH?school_name=NPS&id=1&id=2&id=3
接著,假設您嘗試存取「Assign Message」政策中索引編號為 0、1 和 2 的這些查詢參數,如下所示:
id.0
id.1 and
id.2
在這種情況下,Proxy 的部署作業會失敗,因為索引必須以 1 開頭。也就是說,您可以使用「id.1」存取第一個查詢參數「id=1」。如要存取第二個查詢參數「id=2」,您需要使用索引 2,也就是「id.2」。同樣地,如要存取第三個查詢參數「id=3」,您可以使用「id.3」。
詳情請參閱 AssignMessage 政策的「Copy」元素說明文件。
診斷
找出發生錯誤的「指派訊息」政策、屬性名稱和無效的索引。您可以在錯誤訊息中找到所有這些項目。舉例來說,在以下錯誤中,政策名稱為
GeneratingGeocodingRequest
、屬性名稱為id
,索引為0
:AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0
請確認在失敗的 Assign Message 政策 XML 中使用的���性名稱和���引,與錯誤訊息中指出的屬性名稱和索引相符 (請參閱上述步驟 1)。舉例來說,下列政策會將屬性
id
和索引指定為0
,這與錯誤訊息中的內容相符:<AssignMessage name="GenerateStudentsRequest"> <AssignTo createNew="true" type="request">StudentsInfoRequest</AssignTo> <Copy source="request"> <QueryParams> <QueryParam name="school_name"/> <QueryParam name="id.0"/> <QueryParam name="id.1"/> <QueryParam name="id.2"/> </QueryParams> </Copy> </AssignMessage>
如果指定的索引為 0 或負數,就是錯誤的原因。
在上述示例的「指派訊息」政策中,您嘗試使用索引 0 存取查詢參數「id」的第一個值。因此,API Proxy 的部署作業會失敗,並顯示以下錯誤:
AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0
解決方法
在「指派訊息」中,如果您要存取多個標頭、查詢參數或其他同名參數,請務必確保索引值一律大於零。例如:
<AssignMessage name="GenerateStudentsRequest">
<AssignTo createNew="true" type="request">StudentsInfoRequest</AssignTo>
<Copy source="request">
<QueryParams>
<QueryParam name="school_name"/>
<QueryParam name="id.1"/>
<QueryParam name="id.2"/>
<QueryParam name="id.3"/>
</QueryParams>
</Copy>
</AssignMessage>
InvalidVariableName
錯誤訊息
透過 Apigee UI 或 API 部署 API Proxy 時失敗,並顯示以下錯誤訊息:
Error Saving Revision [revision_number] The revision is deployed, but traffic cannot flow. AssignMessage schema validation failed: invalid variable name - null - in assign variable.
錯誤訊息示例
Error Saving Revision 3
AssignMessage schema validation failed: invalid variable name - null - in assign variable.
螢幕截圖範例
原因
如果子元素 <Name>
為空白,或是未在 <AssignVariable>
元素中指定,則由於沒有有效的變數名稱可指派值,因此 API 代理程式無法部署。必須提供有效的變數名稱。
診斷
請檢查發生失敗的特定 API Proxy 中,所有「指派訊息」政策。如果有������指派訊息政策,其中子元素 <Name>
為空白,或是未在 <AssignVariable>
元素中指定,則會導致錯誤。
範例 1:以下「指派訊息」政策未定義 <Name>
元素。
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<AssignVariable>
<Value>abcd1234</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo>
</AssignMessage>
範例 2:以下「指派訊息」政策含有空白 <Name>
元素。
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<AssignVariable>
<Name></Name>
<Value>abcd1234</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo>
</AssignMessage>
解決方法
請確認在「指派訊息」政策的 <AssignVariable>
元素中,子元素 <Name>
一律已指定且非空白。例如:
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1"> <DisplayName>Assign Message-1</DisplayName> <Properties/> <AssignVariable> <Name>appSecret</Name> <Value>abcd1234</Value> </AssignVariable> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo> </AssignMessage>