本文我们在前面一篇How to develop XS Application on the SAP HANA Cloud Platform的基础上介绍在HANA和HANA Cloud上如何创建和使用HTTP Destination来访问Internet http api或者On-Premise系统的api。为了更贴近现实应用场景,我们仍然使用HANA XS Application与Line服务器的集成场景。本文完整项目代码可以在Github下载。
Series
- How to develop an XS application on the SAP HANA Cloud Platform
- How to develop an XS Odata Service by CDS on the HCP
- How to Create a Fiori app Using OData service on the HCP
- How to Config Fiori App in Fiori Launchpad
- How to use HTTP Destination in HANA and HANA Cloud
- HANA Cloud Connector
HANA
Create file .xshttpdest
在Project Package下创建文件LineProfiles.xshttpdest
description = "Trialbot Profiles of Line";
host = "trialbot-api.line.me";
port = 443;
pathPrefix = "/v1/profiles";
proxyType = none;
authType = none;
useSSL = true;
timeout = 0;
这个HTTP Destination使用了SSL连接,所以需要添加SSL证书
XS Admin Trust Manager
下载https://api.line.me域名的证书,并在XS Admin管理界面(https://
下载LINE API的证书时注意,要使用完整的API访问(不然域名会发生跳转),然后使用默认配置导出cer证书文件
Assign Trust Store
把创建好的Trust Store of line分配给LineProfiles Destination
Use Destination in XSJS
在XSJS程序里使用http destination的文件名来获取destination并用在http client发送请求里
var conDestPackage = "digital-account",
conLineDestName = "LineProfiles";
function getUserProfiles( persons ) {
var mids = persons.join(",");
var dest = $.net.http.readDestination(conDestPackage, conLineDestName);
var client = new $.net.http.Client();
var req = new $.web.WebRequest($.net.http.GET, "?mids="+mids);
req.headers.set("X-Line-ChannelID", "<your line channel id>");
req.headers.set("X-Line-ChannelSecret", "<your line channel secret>");
req.headers.set("X-Line-Trusted-User-With-ACL", "<your line mid");
client.request(req, dest);
var response = client.getResponse();
var contacts = JSON.parse(response.body.asString()).contacts;
var i = 0;
for(i = 0; i < contacts.length; i++) {
$.trace.info(contacts[i]);
}
}
需要注意的是当访问On-Premise的Gateway service时,Authorization x-csrf-token等http headers需要考虑
HANA Cloud Platform
MDC Database
对于HCP的MDC类型的HANA数据库,HTTP Destination文件内容里需要添加proxy才能访问Internet网络服务。Internet 和 On-Premise连接的代理配置列表如下
Internet Connectivity
XS parameter | hana.ondemand.com | us1.hana.ondemand.com | ap1.hana.ondemand.com | hanatrial.ondemand.com |
---|---|---|---|---|
useProxy | true | true | false | true |
proxyHost | proxy | proxy | N/A | proxy-trial |
proxyPort | 8080 | 8080 | N/A | 8080 |
useSSL | true / false | true / false | true / false | true / false |
On-Premise Connectivity
XS parameter | hana.ondemand.com | us1.hana.ondemand.com | ap1.hana.ondemand.com | hanatrial.ondemand.com |
---|---|---|---|---|
useProxy | true | true | true | |
proxyHost | localhost | localhost | localhost | |
proxyPort | 20003 | 20003 | 20003 | |
useSSL | false | false | false |
trial账号应该是没有权限访问On-Premise连接
关于Cloud访问Internet Connectivity和On-Premise Connectivity参见SAP SAP HANA Cloud Documentation - Consuming the Connectivity Service (HANA XS)
Schema of HANA (<shared>) DB
// TODO
Comments