您正在查看 Apigee X 說明文件。
查看
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.
HTTPModifier[GenerateStudentsRequest]: index must be greater than zero in id.0
原因
如果 HTTPModifier 政策的 <Copy>
和/或 <Remove>
元素中指定的索引為 0 或負數,則 API Proxy 的部署作業會失敗。
舉例來說,如果您傳遞多個同名查詢參數,可以將這些參數做為已編入索引的流程變數存取。假設您想將 3 位學生的 ID 做為查詢參數傳遞,可以按照下列方式操作:
https://$EXTERNAL_IP/$PROXY_BASEPATH?school_name=NPS&id=1&id=2&id=3
接著,假設您嘗試存取 HTTPModifier 政策中索引編號為 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」元素說明文件。
診斷
找出發生錯誤的 HTTPModifier 政策、屬性名稱和無效索引。您可以在錯誤訊息中找到所有這些項目。舉例來說,在以下錯誤中,政策名稱為
GeneratingGeocodingRequest
、屬性名稱為id
,索引為0
:HTTPModifier[GenerateStudentsRequest]: index must be greater than zero in id.0
請確認在失敗的 HTTPModifier 政策 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
解決方法
在 HTTPModifier 中,如果您要存取多個標頭、查詢參數或其他同名參數,請務必確保索引值一律大於零。例如:
<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>