您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
問題
用戶端應用程式會收到 HTTP 狀態碼 502 Bad Gateway 和錯誤碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse,做為 API 呼叫的回應。
錯誤訊息
用戶端應用程式會取得下列回應代碼:
HTTP/1.1 502 Bad Gateway
此外,您可能會看到類似下方的錯誤訊息:
{
"fault":{
"faultstring":"Decompression failure at response",
"detail":{
"errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"
}
}
}可能原因
只有在下列情況下才會發生這個錯誤:
- HTTP 回應 (來自後端/目標伺服器) 標頭
Content-Encoding中指定的編碼有效,且 Apigee Edge 支援該編碼。 - 後端/目標伺服器在 HTTP 回應中傳送的酬載格式,與
Content-Encoding標頭中指定的編碼格式不符
BUT
這是因為酬載格式與 Content-Encoding 標頭中指定的編碼格式不同,因此 Apigee Edge 無法使用指定的編碼解碼酬載。
以下列舉幾個支援的 Content-Encoding值,以及 Apigee Edge 在這些情況下預期的酬載表示法:
| 情境 | Content-Encoding | 酬載表示法 |
|---|---|---|
| 單一編碼 | gzip | Unix 請參閱 RFC1952 GZIP 格式。 |
| 單一編碼 | deflate | 這個格式使用 |
| 多重編碼 | 多重編碼 舉例來說,如果編碼作業執行兩次,則可能為:
|
系統會按照標頭中顯示的順序,對酬載套用多種編碼。 |
這項錯誤的可能原因如下:
| 原因 | 說明 | 適用於以下裝置的疑難排解說明 |
|---|---|---|
| 回應酬載格式與 Content-Encoding 不符 | 後端/目標伺服器傳送的回應酬載格式未經過編碼,或與 Content-Encoding 標頭中指定的編碼不符。 |
Edge 公有和私有雲使用者 |
常見的診斷步驟
請使用下列其中一種工具/技術診斷這項錯誤:
API Monitoring
如要使用 API 監控功能診斷錯誤,請按照下列步驟操作:
- 以具備 適當角色的使用者身分登入 Apigee Edge UI。
切換至要調查問題的機構。
- 依序前往「Analyze」>「API Monitoring」>「Investigate」頁面。
- 選取您觀察到錯誤的特定時間範圍。
- 確認「Proxy」篩選器已設為「All」。
- 繪製「錯誤代碼」與「時間」的關係圖。
選取含有故障代碼
messaging.adaptors.http.flow.DecompressionFailureAtResponse的儲存格,如下所示:( 查看較大圖片)
故障代碼資訊
messaging.adaptors.http.flow.DecompressionFailureAtResponse會顯示如下:( 查看較大圖片)
按一下「查看記錄」,然後展開發生
502錯誤的資料列。( 查看較大圖片)
- 在「記錄」視窗中,記下下列詳細資料:
- 狀態碼:
502 - 錯誤來源:
target - 故障代碼:
messaging.adaptors.http.flow.DecompressionFailureAtResponse。
- 狀態碼:
- 如果「Fault Source」的值為
target,表示回應酬載格式與後端伺服器回應標頭Content-Encoding中指定的 支援編碼不符。
追蹤工具
如要使用「追蹤」工具診斷錯誤,請按照下列步驟操作:
- 啟用追蹤工作階段
和下列任一項目:
- 等待發生
502 Bad Gateway錯誤,或 - 如果可以重現問題,請發出 API 呼叫並重現問題。
502 Bad Gateway
- 等待發生
確認已啟用「顯示所有流程資訊」:
- 選取其中一個失敗的回應,並檢查追蹤記錄。
- 瀏覽追蹤記錄的不同階段,找出發生失敗的位置。
通常在流程中,您會在「Response Received from target server」(從目標伺服器收到回應) 階段後立即發現錯誤,如下所示:
( 查看較大圖片)
-
請注意追蹤記錄中屬性的值:
- Content-Encoding:
gzip - 回應內容主體:
{"fault":{"faultstring":"Decompression failure at response","detail":{"errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"}}}
- Content-Encoding:
在「Response Received from target server」(從目標伺服器收到回應) 階段後,前往錯誤階段:
( 查看較大圖片)
請注意下列屬性:
- 錯誤:
Decompression failure at response - error.class:
com.apigee.errors.http.server.BadGateway error.cause:
Not in GZIP formaterror.cause 指出回應酬載並非 GZIP 格式。 這表示 Apigee Edge 預期回應酬載會採用 GZIP 格式,如
Content-Encoding標頭中所指定 (在上一個步驟中判斷)。因此,Apigee Edge 無法使用 gzip 解壓縮酬載,並會傳回Decompression failure at response錯誤。
請注意,目標/後端伺服器的回應在此情況下為
200;不過,由於錯誤是由 Apigee Edge 傳回,因此用戶端應用程式會收到502回應。- 錯誤:
在追蹤記錄中前往「Response Sent to Client」(已將回應傳送給用戶端) 階段,然後按一下該階段。
( 查看較大圖片)
請注意追蹤記錄中的下列詳細資料:
- 狀態碼:
502 Bad Gateway。 - 錯誤內容:
{"fault":{"faultstring":"Decompression failure at response","detail":{"errorcode":"messaging.adaptors.http.flow.DecompressionFailureAtResponse"}}}
- 狀態碼:
前往追蹤記錄中的「AX」(記錄的 Analytics 資料) 階段,然後按一下該階段。AX
- 向下捲動至「Phase Details」(階段詳細資料) 和「Error Headers」(錯誤標頭) 專區,然後判斷 X-Apigee-fault-code 和 X-Apigee-fault-source 的值,如下所示:
( 查看較大圖片)
- 您會看到 X-Apigee-fault-code 和 X-Apigee-fault-source 的值為
messaging.adaptors.http.flow.DecompressionFailureAtResponse和target,表示回應酬載格式與Content-Encoding標頭中指定的編碼不符。回應標頭 值 X-Apigee-fault-code messaging.adaptors.http.flow.DecompressionFailureAtResponseX-Apigee-fault-source target
NGINX
如要使用 NGINX 存取記錄診斷錯誤,請按照下列步驟操作:
- 如果您是私有雲使用者,可以透過 NGINX 存取記錄判斷 HTTP
502錯誤的相關金鑰資訊。 檢查 NGINX 存取記錄:
/opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log說明: ORG、ENV 和 PORT# 會替換為實際值。
- 搜尋特定時間範圍內是否有任何
502錯誤 (如果問題發生在過去),或是否有任何回應仍502失敗。 如果發現任何
502錯誤,且 X-Apigee-fault-code 與messaging.adaptors.http.flow.DecompressionFailureAtResponse的值相符,請判斷 X-Apigee-fault-source 的值。NGINX 存取記錄檔中的 502 錯誤範例:
上述 NGINX 存取記錄檔的範例項目具有下列 X-Apigee-fault-code 和 X-Apigee-fault-source 值:
回應標頭 值 X-Apigee-fault-code messaging.adaptors.http.flow.DecompressionFailureAtResponseX-Apigee-fault-source target
原因:回應酬載格式與 Content-Encoding 不符
根據預設,如果回應標頭 Content-Encoding 包含有效且
支援的編碼,Apigee Edge 一律會解壓縮酬載。因此,回應酬載的格式應與回應標頭 Content-Encoding 中指定的編碼相符。如果不相符,就會收到這項錯誤訊息。
診斷
- 使用 API 監控、追蹤工具或 NGINX 存取記錄,判斷所觀察到的錯誤的錯誤代碼和錯誤來源,如常見診斷步驟所述。
- 如果「Fault Code」為
messaging.adaptors.http.flow.DecompressionFailureAtResponse,且「Fault Source」的值為target,表示後端/目標伺服器傳送的回應酬載格式與回應標頭Content-Encoding中指定的 支援編碼不符。 您可以透過下列其中一種方法,在 HTTP 回應中判斷不符情況:
錯誤訊息
如何使用錯誤訊息進行驗證:
-
如果您可以存取 Apigee Edge 傳送的完整錯誤訊息,請參閱
faultstring。錯誤訊息範例:
"faultstring":"Decompression failure at response"
- 在上述錯誤訊息中,系統會顯示
"Decompression failure at response",這表示無法使用Content-Encoding標頭中指定的編碼,解壓縮 response。
追蹤記錄
如要使用追蹤驗證,請按照下列步驟操作:
- 使用「追蹤」,判斷 Content-Type 和 error.cause,如「常見診斷步驟」一文所述。
範例追蹤記錄中的值如下:
- Content-Encoding:
gzip - error.cause:
Not in GZIP format
回應標頭 Content-Encoding 中的值為 gzip,但回應酬載並非 GZIP 格式 (如 error.cause 所示)。因此,Apigee Edge 會傳回
502 Bad Gateway和錯誤代碼messaging.adaptors.http.flow.DecompressionFailureAtResponse。- Content-Encoding:
實際要求
如要使用實際要求進行驗證,請按照下列步驟操作:
如果您有權存取向目標/後端伺服器應用程式發出的實際要求,請執行下列步驟:
- 如果您是公有雲/私有雲使用者,請直接從後端伺服器或任何其他機器向後端伺服器提出要求,前提是您有權從該機器向後端伺服器提出要求。
- 如果您是私有雲使用者,也可以從其中一個訊息處理器向後端伺服器提出要求。
- 檢查後端伺服器傳送的回應,並判斷回應標頭
Content-Encoding.中傳遞的值 - 判斷要求中傳送的酬載格式。
- 如果
Content-Encoding標頭的值位於 支援的編碼清單中,但回應酬載的格式與Content-Encoding標頭中指定的編碼不符,這就是問題的原因。範例:
curl -v https://HOSTALIAS/test
***trimmed*** > < HTTP/1.1 200 OK < Accept-Ranges: bytes <
Content-Encoding: gzip< Date: Mon, 02 Aug 2021 08:17:35 GMT < Transfer-Encoding: chunked < < response_payload.zip Response Body(not in GZIP format)>上述範例回應會將
gzip值傳送至Content-Encoding標頭,這是 Apigee Edge 支援的編碼。不過,response_payload.zip會以 ZIP 檔案形式傳送。因此,這項回應會因502 Bad Gateway錯誤而失敗,並傳回錯誤代碼:messaging.adaptors.http.flow.DecompressionFailureAtResponse。
訊息處理器記錄
如要使用訊息處理器記錄進行驗證,請按照下列步驟操作:
如果您是私有雲使用者,則可使用訊息處理器記錄檔,判斷 HTTP
502錯誤的關鍵資訊。查看訊息處理器記錄:
/opt/apigee/var/log/edge-message-processor/logs/system.log搜尋特定時間範圍內是否有任何
502錯誤 (如果問題發生在過去),或是否有任何回應仍失敗並顯示502。您可以使用下列搜尋字串:grep -ri "ZipException"
您會看到類似下列內容的 system.log 行:
情境 1
情境 1:API 回應含有標頭 Content-Encoding: gzip
2021-08-02 06:50:25,433 NIOThread@2 ERROR HTTP.CLIENT - HTTPClient$Context.onInputException() : ClientInputChannel(ClientChannel[Connected: Remote:3.8.1.1:9000 Local:10.0.115.32:41298]@38140 useCount=1 bytesRead=0 bytesWritten=203 age=469ms lastIO=0ms isOpen=true).onExceptionRead exception: {}java.util.zip.ZipException: Not in GZIP format---trimmed-- 2021-08-02 06:50:25,433 NIOThread@2 INFO HTTP.CLIENT - HTTPClient$Context.logContextDetails() : Request details : host=null path=/folder/testFile method=GET. Channel details : Bytes read=0 2021-08-02 06:50:25,434 NIOThread@2 ERROR ADAPTORS.HTTP.FLOW - AbstractResponseListener.onException() : AbstractResponseListener.onError(HTTPResponse@4806fdab, Not in GZIP format) 2021-08-02 06:50:25,434 NIOThread@2 INFO HTTP.SERVICE - ExceptionHandler.handleException() : Exceptionjava.util.zip.ZipException: Not in GZIP formatoccurred while writing to channel null 2021-08-02 06:50:25,434 NIOThread@2 INFO HTTP.SERVICE - ExceptionHandler.handleException() : Exception trace: java.util.zip.ZipException: Not in GZIP format上述錯誤訊息中的
java.util.zip.ZipException: Not in GZIP format行指出,雖然Content-Encoding指定為 gzip,但回應酬載並未以 GZIP 格式傳送。因此,Apigee Edge 會擲回例外狀況,並將502狀態碼和錯誤代碼messaging.adaptors.http.flow.DecompressionFailureAtResponse傳回給用戶端應用程式。情境 #2
情境 #2:API 回應含有「Content-Encoding: deflate」標頭
2021-08-02 06:35:21,215 NIOThread@0 ERROR HTTP.CLIENT - HTTPClient$Context.onInputException() : ClientInputChannel(ClientChannel[Connected: Remote:3.8.1.1:9000 Local:192.168.194.140:35224]@36014 useCount=1 bytesRead=0 bytesWritten=202 age=439ms lastIO=2ms isOpen=true).onExceptionRead exception: {}java.util.zip.ZipException: incorrect header check---trimmed---- Caused by:java.util.zip.DataFormatException: incorrect header check---trimmed--- 2021-08-02 06:35:21,215 NIOThread@0 INFO HTTP.CLIENT - HTTPClient$Context.logContextDetails() : Request details : host=null path=/folder/testFile method=GET. Channel details : Bytes read=0 2021-08-02 06:35:21,216 NIOThread@0 ERROR ADAPTORS.HTTP.FLOW - AbstractResponseListener.onException() : AbstractResponseListener.onError(HTTPResponse@3966e277, incorrect header check) 2021-08-02 06:35:21,216 NIOThread@0 INFO HTTP.SERVICE - ExceptionHandler.handleException() : Exception java.util.zip.ZipException: incorrect header check occurred while writing to channel null 2021-08-02 06:35:21,217 NIOThread@0 INFO HTTP.SERVICE - ExceptionHandler.handleException() : Exception trace: java.util.zip.ZipException: incorrect header check上述錯誤訊息中的
java.util.zip.ZipException: incorrect header check和Caused by: java.util.zip.DataFormatException: incorrect header check這幾行表示回應酬載並非以 deflate 格式傳送,且與 deflate 的Content-Encoding標頭中指定的編碼不符。因此,Apigee Edge 會擲回例外狀況,並向用戶端應用程式傳回502狀態碼和錯誤代碼messaging.adaptors.http.flow.DecompressionFailureAtResponse。
-
解析度
- 如果 Apigee Edge 的 API Proxy 流程和後端伺服器不需要壓縮回應酬載,請不要傳遞
Content-Encoding標頭。如需壓縮回應酬載,請前往步驟 2。 - 如需壓縮回應酬載,請確保後端伺服器一律會傳送下列內容:
- 任何
支援的編碼,做為回應中
Content-Encoding標頭的值 - 傳送至 Apigee Edge 的支援格式回應酬載,與
Content-Encoding標頭中指定的編碼格式相符
- 任何
支援的編碼,做為回應中
- 在上述範例中,回應酬載為 ZIP 格式,但回應標頭指定
Content-Encoding: gzip。如要修正這個問題,請以Content-Encoding: gzip格式傳送回應標頭,並以gzip格式傳送回應酬載:curl -v https://HOSTALIAS/v1/test
> < HTTP/1.1 200 OK < Accept-Ranges: bytes <
Content-Encoding: gzip< Date: Mon, 02 Aug 2021 08:17:35 GMT < Transfer-Encoding: chunked < < response_payload.gz Response Body(in GZIP format)>
規格
Apigee Edge 會根據下列 RFC 規格,傳回狀態碼 502 Bad Gateway 和錯誤碼 messaging.adaptors.http.flow.DecompressionFailureAtResponse:
| 規格 |
|---|
| RFC 7231 第 6.5.1 節 |
| RFC 7231 的 3.1.2.2 節 |
如果仍需要 Apigee 支援團隊協助,請參閱「 必須收集診斷資訊」。
必須收集診斷資訊
收集下列診斷資訊,然後聯絡 Apigee Edge 支援團隊:
如果您是公有雲使用者,請提供下列資訊:
- 機構名稱
- 環境名稱
- API Proxy 名稱
- 用於重現
502錯誤的完整curl指令 - API 回應的追蹤記錄檔
如果您是 Private Cloud 使用者,請提供下列資訊:
- 失敗回應的完整錯誤訊息
- 環境名稱
- API Proxy 套裝組合
- API 回應的追蹤記錄檔
NGINX 存取記錄
/opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log說明: ORG、ENV 和 PORT# 會替換為實際值。
- 訊息處理器系統記錄
/opt/apigee/var/log/edge-message-processor/logs/system.log