如何在Java程式碼中使用SAP雲平臺CloudFoundry環境的環境變數
本文使用的例子原始碼在我的github上。
在我的公眾號文章在SAP雲平臺的CloudFoundry環境下消費ABAP On-Premise OData服務介紹瞭如何透過Cloud Connector連線ABAP On-Premise系統。
我建立了三個service的例項,詳情如上圖和下表:
服務型別 | 服務例項名稱 |
---|---|
connectivity | connectivity-jerry-demo |
destination | jerry-destination-lite |
xsuaa | xsuaa-jerry-demo |
這三個服務例項的名稱維護在應用的manifest.xml中。
將應用使用cf push部署到CloudFoundry之後,在Cockpit裡能觀察到生成的系統變數VCAP_SERVICES:
在Java程式碼裡,使用如下程式碼將該環境變數的值讀取出來儲存到字串中。
private static final String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
該Json物件的具體欄位透過getJSONObject讀取出來。
下圖是connectivity例項的credentials明細:
要獲取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:
附錄
VCAP_SERVICES全部內容:
{ "VCAP_SERVICES": { "xsuaa": [
{ "name": "xsuaa-jerry-demo", "instance_name": "xsuaa-jerry-demo", "binding_name": null, "credentials": { "uaadomain": "authentication.eu10.hana.ondemand.com", "tenantmode": "dedicated", "sburl": "", "clientid": "sb-connectivity-jerry-demo!t3704", "verificationkey": "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwThn6OO9kj0bchkOGkqYBnV1dQ3zU/xtj7Kj7nDd8nyRMcEWCtVzrzjzhiisRhlrzlRIEY82wRAZNGKMnw7cvCwNixcfcDJnjzgr2pJ+5/yDZUc0IXXyIWPZD+XdL+0EogC3d4+fqyvg/BF/F0t2hKHWr/UTXE6zrGhBKaL0d8rKfYd6olGWigFd+3+24CKI14zWVxUBtC+P9Fhngc9DRzkXqhxOK/EKn0HzSgotf5duq6Tmk9DCNM4sLW4+ERc6xzrgbeEexakabvax/Az9WZ4qhwgw+fwIhKIC7WLwCEJaRsW4m7NKkv+eJR2LKYesuQ9SVAJ3EXV86RwdnH4uAv7lQHsKURPVAQBlranSqyQu0EXs2N9OlWTxe+FyNkIvyZvoLrZl/CdlYc8AKxRm5rn2/88nkrYQ0XZSrnICM5FRWgVF2hn5KfZGwtBN85/D4Yck6B3ocMfyX7e4URUm9lRPQFUJGTXaZnEIge0R159HUwhTN1HvyXrs6uT1ZZmW+c3p47dw1+LmUf/hIf8zd+uvHQjIeHEJqxjqfyA8yqAFKRHKVFrwnwdMHIsRap2EKBhHMfeVf0P2th5C9MggYoGCvdIaIUgMBX3TtCdvGrcWML7hnyS2zkrlA8SoKJnRcRF2KxWKs355FhpHpzqyZflO5l98+O8wOsFjGpL9d0ECAwEAAQ==-----END PUBLIC KEY-----", "xsappname": "connectivity-jerry-demo!t3704", "identityzone": "jerry", "identityzoneid": "f3bd7f84-ebf1-4c11-b7c7-a278ebd54dcb", "clientsecret": "WAxzZxYQCgB7Dkml8dFdU+kaLSE=", "tenantid": "f3bd7f84-ebf1-4c11-b7c7-a278ebd54dcb", "url": "" }, "syslog_drain_url": null, "volume_mounts": [], "label": "xsuaa", "provider": null, "plan": "application", "tags": [ "xsuaa" ]
}
], "connectivity": [
{ "name": "connectivity-jerry-demo", "instance_name": "connectivity-jerry-demo", "binding_name": null, "credentials": { "uaadomain": "authentication.eu10.hana.ondemand.com", "onpremise_proxy_port": "20003", "tenantmode": "dedicated", "clientid": "sb-clone5282c913c9164bb284239adcc4d74210!b3704|connectivity!b17", "verificationkey": "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwThn6OO9kj0bchkOGkqYBnV1dQ3zU/xtj7Kj7nDd8nyRMcEWCtVzrzjzhiisRhlrzlRIEY82wRAZNGKMnw7cvCwNixcfcDJnjzgr2pJ+5/yDZUc0IXXyIWPZD+XdL+0EogC3d4+fqyvg/BF/F0t2hKHWr/UTXE6zrGhBKaL0d8rKfYd6olGWigFd+3+24CKI14zWVxUBtC+P9Fhngc9DRzkXqhxOK/EKn0HzSgotf5duq6Tmk9DCNM4sLW4+ERc6xzrgbeEexakabvax/Az9WZ4qhwgw+fwIhKIC7WLwCEJaRsW4m7NKkv+eJR2LKYesuQ9SVAJ3EXV86RwdnH4uAv7lQHsKURPVAQBlranSqyQu0EXs2N9OlWTxe+FyNkIvyZvoLrZl/CdlYc8AKxRm5rn2/88nkrYQ0XZSrnICM5FRWgVF2hn5KfZGwtBN85/D4Yck6B3ocMfyX7e4URUm9lRPQFUJGTXaZnEIge0R159HUwhTN1HvyXrs6uT1ZZmW+c3p47dw1+LmUf/hIf8zd+uvHQjIeHEJqxjqfyA8yqAFKRHKVFrwnwdMHIsRap2EKBhHMfeVf0P2th5C9MggYoGCvdIaIUgMBX3TtCdvGrcWML7hnyS2zkrlA8SoKJnRcRF2KxWKs355FhpHpzqyZflO5l98+O8wOsFjGpL9d0ECAwEAAQ==-----END PUBLIC KEY-----", "xsappname": "clone5282c913c9164bb284239adcc4d74210!b3704|connectivity!b17", "identityzone": "jerry", "clientsecret": "nyiGD9QQSOZO+NTeEJdexWWjxYY=", "tenantid": "f3bd7f84-ebf1-4c11-b7c7-a278ebd54dcb", "url": "", "onpremise_proxy_host": "10.0.85.1" }, "syslog_drain_url": null, "volume_mounts": [], "label": "connectivity", "provider": null, "plan": "lite", "tags": [ "connectivity", "conn", "connsvc" ]
}
], "destination": [
{ "name": "jerry-destination-lite", "instance_name": "jerry-destination-lite", "binding_name": null, "credentials": { "uaadomain": "authentication.eu10.hana.ondemand.com", "tenantmode": "dedicated", "clientid": "sb-clone39a01503ac1845fbbda5d5ffccb1a469!b3704|destination-xsappname!b404", "instanceid": "39a01503-ac18-45fb-bda5-d5ffccb1a469", "verificationkey": "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwThn6OO9kj0bchkOGkqYBnV1dQ3zU/xtj7Kj7nDd8nyRMcEWCtVzrzjzhiisRhlrzlRIEY82wRAZNGKMnw7cvCwNixcfcDJnjzgr2pJ+5/yDZUc0IXXyIWPZD+XdL+0EogC3d4+fqyvg/BF/F0t2hKHWr/UTXE6zrGhBKaL0d8rKfYd6olGWigFd+3+24CKI14zWVxUBtC+P9Fhngc9DRzkXqhxOK/EKn0HzSgotf5duq6Tmk9DCNM4sLW4+ERc6xzrgbeEexakabvax/Az9WZ4qhwgw+fwIhKIC7WLwCEJaRsW4m7NKkv+eJR2LKYesuQ9SVAJ3EXV86RwdnH4uAv7lQHsKURPVAQBlranSqyQu0EXs2N9OlWTxe+FyNkIvyZvoLrZl/CdlYc8AKxRm5rn2/88nkrYQ0XZSrnICM5FRWgVF2hn5KfZGwtBN85/D4Yck6B3ocMfyX7e4URUm9lRPQFUJGTXaZnEIge0R159HUwhTN1HvyXrs6uT1ZZmW+c3p47dw1+LmUf/hIf8zd+uvHQjIeHEJqxjqfyA8yqAFKRHKVFrwnwdMHIsRap2EKBhHMfeVf0P2th5C9MggYoGCvdIaIUgMBX3TtCdvGrcWML7hnyS2zkrlA8SoKJnRcRF2KxWKs355FhpHpzqyZflO5l98+O8wOsFjGpL9d0ECAwEAAQ==-----END PUBLIC KEY-----", "xsappname": "clone39a01503ac1845fbbda5d5ffccb1a469!b3704|destination-xsappname!b404", "identityzone": "jerry", "clientsecret": "QCnO+2k8gvUkdTyiCZI5rhzylbQ=", "tenantid": "f3bd7f84-ebf1-4c11-b7c7-a278ebd54dcb", "uri": "", "url": "" }, "syslog_drain_url": null, "volume_mounts": [], "label": "destination", "provider": null, "plan": "lite", "tags": [ "destination", "document" ]
}
], "application-logs": [
{ "name": "jerry-log", "instance_name": "jerry-log", "binding_name": null, "credentials": {}, "syslog_drain_url": "", "volume_mounts": [], "label": "application-logs", "provider": null, "plan": "lite", "tags": []
}
]
}
}
{ "VCAP_APPLICATION": { "cf_api": "", "limits": { "fds": 16384, "mem": 512, "disk": 1024 }, "application_name": "connectivity-jerry-demo", "application_uris": [ "connectivity-jerry-demo-i042416.cfapps.eu10.hana.ondemand.com" ], "name": "connectivity-jerry-demo", "space_name": "dev", "space_id": "69abfd46-d228-4903-b245-de88ceff3642", "uris": [ "connectivity-jerry-demo-i042416.cfapps.eu10.hana.ondemand.com" ], "users": null, "application_id": "fa893f26-69ee-4a4a-aa04-8f8ae0676475", "version": "d964d7cc-e067-4810-b834-25c995fe1bc5", "application_version": "d964d7cc-e067-4810-b834-25c995fe1bc5" }
}
要獲取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2155918/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP雲平臺CloudFoundry環境hdb build成功的日誌分析CloudUI
- SAP雲平臺CloudFoundry環境裡route 超過quota的錯誤處理Cloud
- 如何上傳HTML5應用到SAP雲平臺的CloudFoundry環境下HTMLCloud
- SAP BTP 平臺 CloudFoundry 環境入門級別的介紹Cloud
- 在SAP雲平臺的CloudFoundry環境下消費ABAP On-Premise OData服務CloudREM
- SAP 雲平臺 ABAP 程式設計環境的前世今生程式設計
- Java 環境變數Java變數
- Java環境變數Java變數
- java 環境變數的配置Java變數
- 雲平臺雲環境之要素
- Java環境變數新增Java變數
- java環境變數配置Java變數
- java 配置環境變數Java變數
- 如何在SAP雲平臺的Cloud Foundry環境下新增新的Service(服務)Cloud
- Bash 中的環境變數變數
- 精讀《如何在 nodejs 使用環境變數》NodeJS變數
- Mac配置Java環境變數MacJava變數
- ubuntu 配置java環境變數UbuntuJava變數
- JAVA環境變數設定Java變數
- XP Java 環境變數配置Java變數
- 將Java應用部署到SAP雲平臺neo環境的兩種方式Java
- 環境變數變數
- 什麼是環境變數?Python中如何設定環境變數?變數Python
- 在solaris環境下,根據java程式的不同,設定不同的環境變數Java變數
- java語言環境jdk的安裝和環境變數的配置JavaJDK變數
- SAP雲平臺執行環境Cloud Foundry和Neo的區別Cloud
- java配置環境變數的錯誤Java變數
- JDK和Java環境變數的配置JDKJava變數
- 環境變數{Linux環境(也稱為Shell環境)}(轉)變數Linux
- Linux 新增環境變數和刪除環境變數Linux變數
- ASP.NET Core微服務如何在雲環境中跨平臺服務?ASP.NET微服務
- linux java環境變數配置LinuxJava變數
- linux配置java環境變數LinuxJava變數
- centos下配置java環境變數CentOSJava變數
- java JDK環境變數設定JavaJDK變數
- JAVA環境變數配置介紹Java變數
- java jdk 設定環境變數JavaJDK變數
- Win10怎麼配置java環境變數 win10配置java環境變數的方法Win10Java變數