SAPUI5模拟服务器未收到请求

时间:2018-08-10 07:07:07

标签: javascript request sapui5 mockserver

我没有找到解决此问题的方法。我目前正在使用 CRUD主详细应用程序 WebIDE 模板,并通过 OData 调用添加了一些自定义功能。在模拟服务器上运行应用程序时,它将加载模拟数据。到目前为止,一切都很好。但是,如果我向模拟服务器发送读取请求,则为throws a 404 not found error

请求URL

https://webidetesting[...].dispatcher.hana.ondemand.com/here/goes/your/serviceurl/MyEntity(12345)

这是我的index文件flpSandboxMockServer.html中的模拟服务器部分:

<script>
        sap.ui.getCore().attachInit(function() {

            sap.ui.require([
                "my/project/localService/mockserver"
            ], function (mockserver) {
                // set up test service for local testing
                mockserver.init();

                // initialize the ushell sandbox component
                sap.ushell.Container.createRenderer().placeAt("content");
            });
        });
    </script>

OData读取调用看起来像:

onRemoveMyEntityBtnPress: function () {
        let oEntityTable = this.byId("lineItemsList");
        let aSelectedItems = oEntityTable.getSelectedItems();
        let oModel = this.getModel();

        for (let oSelectedItem of aSelectedItems) {
            let sBindingPath = oSelectedItem.getBindingContext().getPath();
            let sGuid = this._selectGuidFromPath(sBindingPath);

            this._loadEntityFromService(sGuid, oModel).then((oData) => {
                // Next step: change a property value
            }).catch((oError) => {
                jQuery.sap.log.error(oError);
            });
        }

        if (oModel.hasPendingChanges()) {
            oModel.submitChanges();
        }
    },
_loadEntityFromService: function (sGuid, oModel) {
        return new Promise((resolve, reject) => {
            oModel.read(`/MyEntity(${sGuid})`, { 
                success: (oData) => {
                    resolve(oData);
                },
                error: (oError) => { // call always ends up here with 404 error
                    reject(oError);
                }
            });
        });
    },

有人知道将我的读取请求发送到模拟服务我还需要做什么吗?

1 个答案:

答案 0 :(得分:1)

终于找到了解决方案! 我使用OData实体类型来读取我的实体。我将目的地更改为我的实体集,现在它不会引发404错误。