SAPUI5 (33) - 使用 SAP Web IDE 提供的代理服务

前面我们访问 Northwind OData service,使用的是 https://cors-anywhere.herokuapp.com/ 提供的代理服务。其实,如果在 SAP Web IDE 中编写代码的话,Web IDE 也提供了代理服务。本篇我们就来看看如何使用 SAP Web IDE 提供的代理服务。

使用 Web IDE 配置连接

进入在线版 Web IDE,登陆后找到左边 Panel 下的 Connectivity -> Destinations:

Paste_Image.png

点击 New Destination,然后设置如下:

点击 New Property,设置如下属性:

保存后,点击 Check connection,如果出现成功提示,则表示连接成功。

Web IDE 的这个 Destination 设置,可以用于该账户下的所有项目。 如果配置了 destination, IDE
中的项目 serviceUrl 的写法和之前通过代理的方法不同。比如,我们之前的连接 url 为:

var sServiceUrl = proxy + "http://services.odata.org/V2/(S(tigt4zfne0egj3u25bhqq32a))/OData/OData.svc/"

现在这个 serviceUrl 应该这样写:

var sServiceUrl = "/destinations/northwind/V2/(S(vitw3mhyp5ifhga2mttx5okl))/OData/OData.svc"

Host 和 port 被替换成 /destinations/northwind/

SAP Web IDE 连接测试

在 SAP Web IDE 中创建一个类型为 SAPUI5 Applicaation 类型的项目,IDE 预设的项目文件结构为:

在项目的根目录下多了 neo-app.json 文件和 .project.json 文件。neo-app.json 文件中包含了引用的 destination :

{
    "path": "/destinations/northwind",
    "target": {
    "type": "destination",
    "name": "northwind"
    },
    "description": "Northwind OData Service"
}

代码测试:

// Application data
var sServiceUrl = "/destinations/northwind/V2/(S(vitw3mhyp5ifhga2mttx5okl))/OData/OData.svc"
var oModel = new sap.ui.model.odata.v2.ODataModel({
    serviceUrl: sServiceUrl
});
oModel.setUseBatch(false);

function readTest(){
    oModel.read("/Suppliers(0)", {
        success: function(oData, oResponse){
            console.log(oResponse);
            console.log(oData);
        },
        error: function(oError){
            console.log(oError);
        }
    });
}

var oButton = new sap.m.Button({
    text: "Read first supplier",
    press: readTest
});

Personal Edition 如何使用代理

因为 SAP Web IDE 只是 SAP Cloud Platform (简称为 HCP) 中 Service 下面的一个子功能,而 Destination 的配置是在 Connectivity - Destinations 下面,所以个人版中是没有这个设置界面的。那么,个人版能不能使用这个代码功能呢?答案是可以,方法如下:

将 Web IDE 在线版的 Destination 文件下载:

然后,在 SAP Web IDE 个人版的安装目录下,找到子文件夹:config_master\service.destinations\destinations,将这个文件放进去就可以了。

注意这个文件不能有扩展名,如果放进去的时候本地服务已经启用,需要退出重新启用服务。这个 destination 文件是一个类似 ini 的配置文件,我们可以用文本编辑器打开编写,也就是说,我们也可以手工编辑这个文件。

#
#Sat Apr 22 13:40:42 UTC 2017
Description=Northwind
Type=HTTP
Authentication=NoAuthentication
WebIDEUsage=odata_gen
Name=northwind
WebIDEEnabled=true
CloudConnectorVersion=2
URL=http\://services.odata.org
ProxyType=Internet
WebIDESystem=Northwind

参考

Create a Northwind Destination

Connecting Remote Systems in SAP Web IDE Personal Edition

Step 26: Remote OData Service

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,052评论 6 342
  • 继续上一篇的内容,完成使用 OData Model 连接到后端 SAP 系统,实现 CRUD 操作。 程序界面: ...
    Stone0823阅读 9,309评论 3 2
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,112评论 25 709
  • 别轻易与现实死磕 与其头破血流 不如云淡风轻 一切 终究在未来的某个时刻戛然而止 答案跃然 风起了 就理理吹乱的...
    春天2016阅读 2,523评论 1 0