您正在查看 Apigee 和 Apigee Hybrid 說明文件。
查看
Apigee Edge 說明文件。
RequestVariableNotMessageType
錯誤代碼
steps.servicecallout.RequestVariableNotMessageType
錯誤回應主體
{ "fault": { "faultstring": "ServiceCallout[POLICY_NAME]: request variable [VARIABLE_NAME] value is not of type Message", "detail": { "errorcode": "steps.servicecallout.RequestVariableNotMessageType" } } }
原因
如果 ServiceCallout 政策的 <Request>
元素中指定的變數不是 message
類型,就會發生這個錯誤。如果變數是字串或任何其他非訊息類型,就會顯示這項錯誤。
訊息類型變數代表整個 HTTP 要求和回應。內建流程變數 request
、response
和 message
的類型為 message
。
診斷
找出發生錯誤的 ServiceCallout 政策,以及類型有誤的變數名稱。您可以在錯誤回應的
faultstring
元素中找到這兩項項目。例如,在以下faultstring
中,政策名稱為ExecuteGeocodingRequest
,變數為PostalCode
:"faultstring": "ServiceCallout[ExecuteGeocodingRequest]: request variable PostalCode value is not of type Message"
在失敗的 ServiceCallout 政策 XML 中,請確認
<Request>
元素中設定的變數名稱,與錯誤字串中指出的變數名稱相符 (步驟 1 上方)。舉例來說,下列政策會指定名為PostalCode
的要求變數,與faultstring
中的內容相符:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="ExecuteGeocodingRequest"> <Request variable="PostalCode"/> <Response>GeocodingResponse</Response> <HTTPTargetConnection> <URL>http://maps.googleapis.com/maps/api/geocode/json</URL> </HTTPTargetConnection> </ServiceCallout>
判斷這個變數是否為 message 類型:
- 找出 API Proxy 套件中的程式碼,該程式碼會先定義變數。
- 在大多數情況下,您會發現問題變數是在 ServiceCallout 政策執行前,由另一個政策建立並填入。舉例來說,指派訊息政策通常用於在 API 代理程式流程中建立及填入變數。
- 找出先定義及填入變數的政策後,您需要依下列方式判斷該變數的類型:
- 檢查
type
屬性 (如有) 的值。 - 如果沒有
type
屬性,系統會將變數視為字串。
- 檢查
- 如果變數的類型不是訊息 (例如字串),則是錯誤的原因。如要瞭解常見的變數及其類型,請參閱流程變數參考資料。
舉例來說,假設 ServiceCallout 政策中參照的 PostalCode
變數是在下列 AssignMessage 政策中建立。請注意,PostalCode
會指派流程變數 request.queryparam.postalcode
的值。這個值是字串,因為變數指派中沒有 type
屬性。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="GenerateGeocodingRequest">
<AssignTo createNew="true" type="request">GeocodingRequest</AssignTo>
<Set>
<QueryParams>
<QueryParam name="address">{request.queryparam.postalcode}</QueryParam>
<QueryParam name="region">{request.queryparam.country}</QueryParam>
<QueryParam name="sensor">false</QueryParam>
</QueryParams>
<Verb>GET</Verb>
</Set>
<AssignVariable>
<Name>PostalCode</Name>
<Ref>request.queryparam.postalcode</Ref>
</AssignVariable>
<AssignVariable>
<Name>Country</Name>
<Ref>request.queryparam.country</Ref>
</AssignVariable>
</AssignMessage>
回想一下,PostalCode
變數會用於 ServiceCallout 政策的 <Request>
元素:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ExecuteGeocodingRequest">
<Request variable="PostalCode"/>
<Response>GeocodingResponse</Response>
<HTTPTargetConnection>
<URL>http://maps.googleapis.com/maps/api/geocode/json</URL>
</HTTPTargetConnection>
</ServiceCallout>
由於 PostalCode
不是 message 類型 (在本例中為字串),因此您會收到錯誤代碼:steps.servicecallout.RequestVariableNotMessageType
。
解決方法
請確認在失敗的 ServiceCallout 政策中,<Request>
元素中設定的變數為現有的 message
類型流程變數,或者您也可以直接在 ServiceCallout 政策中建立新的訊息類型變數 (如「ServiceCallout 政策」一文所述) 並加以使用。
如要修正政策,您必須修改 <Request>
元素,指定現有或新變數的類型為 message。舉例來說,在「指派訊息」政策中設定的變數 GeocodingRequest
屬於訊息類型,因此在「ServiceCallout」政策中會正常運作。例如:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ExecuteGeocodingRequest">
<Request variable="GeocodingRequest"/>
<Response>GeocodingResponse</Response>
<HTTPTargetConnection>
<URL>http://maps.googleapis.com/maps/api/geocode/json</URL>
</HTTPTargetConnection>
</ServiceCallout>
RequestVariableNotRequestMessageType
錯誤代碼
steps.servicecallout.RequestVariableNotRequestMessageType
錯誤回應主體
{ "fault": { "faultstring": "ServiceCallout[policy_name]: request variable [variable_name] value is not of type Request Message", "detail": { "errorcode": "steps.servicecallout.RequestVariableNotRequestMessageType" } } }
原因
如果 ServiceCallout 政策的 <Request>
元素中指定的變數不是 message
類型,就會發生這個錯誤。如果變數是回應訊息類型、字串或任何其他類型,就會顯示這項錯誤。
message
類型變數代表整個 HTTP 要求和回應。內建流程變數 request
、response
和 message
的類型為 message
。
診斷
找出發生錯誤的 ServiceCallout 政策,以及類型有誤的變數名稱。您可以在錯誤回應的
faultstring
元素中找到這兩項項目。例如,在以下faultstring
中,政策名稱為ExecuteGeocodingRequest
,變數為var_response
:"faultstring": "ServiceCallout[ExecuteGeocodingRequest]: request variable var_response value is not of type Message"
在失敗的 ServiceCallout 政策 XML 中,請確認
<Request>
元素中設定的變數名稱,與錯誤字串中指出的變數名稱相符 (步驟 1 上方)。舉例來說,下列政策會指定名為var_response
的要求變數,與faultstring
中的內容相符:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="ExecuteGeocodingRequest"> <Request variable="var_response"/> <Response>GeocodingResponse</Response> <HTTPTargetConnection> <URL>http://maps.googleapis.com/maps/api/geocode/json</URL> </HTTPTargetConnection> </ServiceCallout>
判斷變數是否為要求訊息類型:
- 找出 API Proxy 套件中的程式碼,該程式碼會先定義變數。
- 在大多數情況下,您會發現問題變數是在 ServiceCallout 政策執行前,由另一個政策建立並填入。舉例來說,指派訊息政策通常用於在 API 代理程式流程中建立及填入變數。
- 找出先定義及填入變數的政策後,您需要依下列方式判斷該變數的類型:
- 檢查
type
屬性 (如有) 的值。 - 如果沒有
type
屬性,系統會將變數視為字串。
- 檢查
- 如果變數的類型不是「請求訊息」類型,則是錯誤的原因。如要瞭解常見的變數及其類型,請參閱流程變數參考資料。
舉例來說,假設在下列指派訊息政策中,ServiceCallout 政策中參照的 var_response
變數已建立。請注意,var_response
的類型為 response
。因此,var_response
變數的類型為回應訊息。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="GenerateGeocodingRequest">
<AssignTo createNew="true" type="request">GeocodingRequest</AssignTo>
<AssignTo createNew="true" type="response">var_response</AssignTo>
<Set>
<QueryParams>
<QueryParam name="address">{request.queryparam.postalcode}</QueryParam>
<QueryParam name="region">{request.queryparam.country}</QueryParam>
<QueryParam name="sensor">false</QueryParam>
</QueryParams>
<Verb>GET</Verb>
</Set>
<AssignVariable>
<Name>PostalCode</Name>
<Ref>request.queryparam.postalcode</Ref>
</AssignVariable>
<AssignVariable>
<Name>Country</Name>
<Ref>request.queryparam.country</Ref>
</AssignVariable>
</AssignMessage>
請注意,var_response
變數會用於 ServiceCallout 政策的 <Request>
元素。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ExecuteGeocodingRequest">
<Request variable="var_response"/>
<Response>GeocodingResponse</Response>
<HTTPTargetConnection>
<URL>http://maps.googleapis.com/maps/api/geocode/json</URL>
</HTTPTargetConnection>
</ServiceCallout>
由於 var_response
不是要求訊息類型 (其類型為回應訊息),因此您會收到錯誤代碼:steps.servicecallout.RequestVariableNotRequestMessageType
。
解決方法
請確認在失敗的 ServiceCallout 政策中,<Request>
元素中設定的變數為現有的 message
類型變數,或者您也可以直接在 ServiceCallout 政策中建立新的請求訊息類型變數 (如「ServiceCallout 政策」一文所述) 並加以使用。
如要修正政策,您必須修改 <Request>
元素,指定現有或新變數的類型為要求訊息,這樣才能在 ServiceCallout 政策中運作。例如:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ExecuteGeocodingRequest">
<Request variable="GeocodingRequest"/>
<Response>GeocodingResponse</Response>
<HTTPTargetConnection>
<URL>http://maps.googleapis.com/maps/api/geocode/json</URL>
</HTTPTargetConnection>
</ServiceCallout>
ExecutionFailed
錯誤代碼
steps.servicecallout.ExecutionFailed
錯誤回應主體
{ "fault": { "faultstring": "Execution of ServiceCallout [policy_name] failed. Reason: Host not reachable", "detail": { "errorcode": "steps.servicecallout.ExecutionFailed" } } }
或
{ "fault": { "faultstring": "Execution of ServiceCallout [policy_name] failed. Reason: ResponseCode [http_code] is treated as error", "detail": { "errorcode": "steps.servicecallout.ExecutionFailed" } } }
可能原因
導致這項錯誤的可能原因包括:
原因 | 說明 |
無效或格式不正確的網址 | ServiceCallout 政策中的目標網址格式錯誤,或是包含無效或無法存取的主機名稱。 |
後端伺服器錯誤 | 後端伺服器會傳回 4XX 或 5XX 錯誤回應。 |
原因:網址無效或格式有誤
ServiceCallout 政策中的目標網址格式錯誤,或是包含無效或無法存取的主機名稱。
診斷
找出導致錯誤的 ServiceCallout 政策。政策名稱會顯示在錯誤回應的
faultstring
元素中。例如,在以下faultstring
中,失敗的 ServiceCallout 政策名稱為ExecuteGeocodingRequest
。"faultstring": "ServiceCallout[ExecuteGeocodingRequest]"
在失敗的 ServiceCallout 政策中,檢查
<URL>
元素。如果格式錯誤或主機名稱無效或無法連線,就會導致這個錯誤。舉例來說,下列 ServiceCallout 政策指定了無效的<URL>
:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="ExecuteGeocodingRequest"> <Request variable="GeocodingRequest"/> <Response>GeocodingResponse</Response> <HTTPTargetConnection> <URL>http://</URL> </HTTPTargetConnection> </ServiceCallout>
<URL>
元素只有通訊協定http://
,但沒有有效的主機名稱;因此,ServiceCallout 政策會失敗,並顯示錯誤訊息:Execution of ServiceCallout ExecuteGeocodingRequest failed. Reason: Host not reachable
。
解決方法
請確認失敗的 ServiceCallout 政策中的 <URL>
元素具有有效的網址,且可到達主機名稱。
如要修正上述的 ServiceCallout 政策,您可以修改 <URL>
元素,指定有效的網址:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ExecuteGeocodingRequest">
<Request variable="GeocodingRequest"/>
<Response>GeocodingResponse</Response>
<HTTPTargetConnection>
<URL>http://maps.googleapis.com/maps/api/geocode/json</URL>
</HTTPTargetConnection>
</ServiceCallout>
原因:後端伺服器錯誤
後端伺服器會傳回 4XX 或 5XX 錯誤回應。
診斷
找出導致錯誤的 ServiceCallout 政策。政策名稱會顯示在錯誤回應的
faultstring
元素中。例如,在以下faultstring
中,失敗的 ServiceCallout 政策名稱為ExecuteGeocodingRequest
。"faultstring": "ServiceCallout[ExecuteGeocodingRequest]
檢查錯誤回應主體中的
faultstring
,並確認Reason
中是否列有任何 4XX 或 5XX 回應代碼。舉例來說,下列錯誤字串清楚指出後端伺服器傳回的回應代碼為 502:"faultstring": "Execution of ServiceCallout ExecuteGeocodingRequest failed. Reason: ResponseCode 502 is treated as error"
解決方法
確定錯誤回應代碼後,您可以按照處理任何 4XX 或 5XX 錯誤的方式,排解這個問題。