課題
UI5アプリからCAPで作成したODataを呼び出したところ、504エラー(Gateway Timeout)が発生しました。
デフォルトでは30秒でTimeoutする設定になっていそうです。
対応策
mta.yamlにてTimeout時間を指定します。
HTML5.Timeoutというプロパティにミリ秒単位でTimeout時間を設定します。
(デプロイ後にBTP CockpitのDestinationタブから対象のDestinationを開くと、プロパティHTML5.Timeoutが追加されていることを確認できます。)
mta.yaml
- name: test-destination-content
type: com.sap.application.content
requires:
- name: test-destination-service
parameters:
content-target: true
- name: test_html_repo_host
parameters:
service-key:
name: test_html_repo_host-key
- name: test-auth
parameters:
service-key:
name: test-auth-key
- name: srv-api
parameters:
content:
subaccount:
destinations:
- Name: cap_test_html_repo_host
ServiceInstanceName: test-html5-app-host-service
ServiceKeyName: test_html_repo_host-key
sap.cloud.service: cap
- Authentication: OAuth2UserTokenExchange
Name: cap_test_auth
ServiceInstanceName: test-auth
ServiceKeyName: test-auth-key
sap.cloud.service: cap
- Authentication: OAuth2UserTokenExchange
Name: cap_test_srv
ServiceInstanceName: test-auth
ServiceKeyName: test-auth-key
sap.cloud.service: cap
URL: ~{srv-api/srv-url}
HTML5.DynamicDestination: true
HTML5.Timeout: 300000 //ミリ秒単位で設定
UI5からODataを呼び出したところ、Timeoutエラーが発生せず、処理が正常完了しました!
補足
本記事では「30 秒以上レスポンスが返らないケース」でのTimeout挙動を確認するため、CAP 側で意図的に60秒待ってからレスポンスを返すエンドポイントを作成しました。
実運用ではパフォーマンスチューニングや非同期化により、長時間待ちが発生しないよう工夫すべきだと考えます。

