Java Based Apps on SAP Cloud_5_其
2017-05-08 本文已影响0人
LiuliuZhang
API管理
HCP中,启用API管理服务,通过访问API门户的链接,进入API管理界面

在Webshop应用中,我们请求产品列表的URL如下

点击Quick Action中的API,可以打开创建API页面,URL为https://espmc5228335trial.hanatrial.ondemand.com/espm-cloud-web/espm.svc/,API Base Path我们可以填/v1/os/espm/ (注意在本应用中,最后以'/'标记结尾)

我们得到创建的URL https://c5228335trial-trial.apim1.hanatrial.ondemand.com:443/c5228335trial/v1/os/espm/
访问该url可以得到产品的信息
点击Policies,点击Edit,选择PreFlow,增加Verify API Key,下面代码中改成
<APIKey ref='request.header.APIKey'/>
,更新并保存
再访问API URL,会得到错误信息
Failed to resolve API Key variable request.header.APIKey
。在API Portal页面通过Quick Action的Product链接创建Product,并选择前面创建的API

点击HCP API管理中的访问开发人员门户,可以看到前面创建的Product,首次登陆需点击Regist注册为开发人员

进入后,点击Subscribe->New Application,创建ESPM-UI

在Consume下,可以得到Application Key与Application Secret

点击Test,添加Hearder参数,再访问即可访问到Product的信息。

更新APP为API Management Branch,点击设置按钮修改为API Management Call

此时会有
Origin 'https://espmc5228335trial.hanatrial.ondemand.com' is therefore not allowed access.
的错误修改API的Rote Rules如下:

在PostFlow中,添加Assign Message

代码如下
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Add>
<Headers>
<Header name="Access-Control-Allow-Origin">*</Header>
<Header name="Access-Control-Allow-Headers">set-cookie, origin, accept, maxdataserviceversion, x-csrf-token, apikey, dataserviceversion, accept-language, x-http-method,content-type,XRequested-Wit</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE</Header>
<Header name="Access-Control-Expose-Headers">set-cookie, xcsrf-token, x-http-method</Header>
</Headers>
</Add>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="response">response</AssignTo>
</AssignMessage>
在PreFlow中,CheckAPI添加Condition String:request.verb != "OPTIONS"
刷新后,可以访问

Translation HUB
启用HCP的SAP Translation HUB服务
添加File Upload项目

上传i18n.properties文件,上传成功后,在Translation标签下可以自动翻译,修改翻译的内容

修改后,点击下载翻译文件,粘贴到i18n文件夹下,更新APP,即可通过url加后缀sap-language=de等内容查看相应语言下的页面。
Mobile Scenario
GitHub上下载HTML5-Retailer和HTML5-Workshop Branch

在HCP的连接中,导入两个项目的Destination,更新其中的url

打开WEB-IDE,File->git->clone repository,clone github上的url

创建Local Branch,点击加号,选择Html5-workshop

同样的方法创建Html5-retailer Local Branch。
HCP中启用Portal服务,创建新的站点,模板选择SAP Fiori Launchpad。
在站点目录中,将其发布并设为默认。

在WEB-IDE中,将项目Deploy到SAP HANA Cloud Platform,Application Name为workshop,并将其注册到Fiori Launchpad

Application Name为com.sap.espm.webshop,站点选择前面新建的ESPM,Retailer同样的步骤
部署完成后,可以查看

在HCP中新建webshop与retailer的租用

启用HCP的Mobile Fiori服务