OData Jaydata - odata更新请求返回错误404(SAPUI5,节点)

时间:2014-04-03 12:41:22

标签: mongodb express odata jaydata sapui5

我正在使用SAPUI5构建一个Web应用程序,该应用程序提供了一个服务列表,这些服务存储在MongoDB中并可用作OData。 我遵循了这个指南jaydata-install-your-own-odata-server-with-nodejs-and-mongodb,这些是我的model.js:

$data.Class.define("marketplace.Service", $data.Entity, null, {
    Id: {type: "id", key: true, computed: true, nullable: false},
    Name: {type: "string", nullable: false, maxLength: 50},
}, null);
$data.Class.defineEx("marketplace.Context", [$data.EntityContext, $data.ServiceBase], null, {
    Services: {type: $data.EntitySet, elementType: marketplace.Service}
});

exports = marketplace.Context;

和server.js:

var c = require('express');
require('jaydata');
window.DOMParser = require('xmldom').DOMParser; 
require('q');
require('./model.js');

var app = c();
app.use(c.query());
app.use(c.bodyParser());
app.use(c.cookieParser());
app.use(c.methodOverride());
app.configure(function() {app.use(app.router);});
app.use(c.session({secret: 'session key'}));
app.use("/marketplace", $data.JayService.OData.Utils.simpleBodyReader());
app.use("/marketplace", $data.JayService.createAdapter(marketplace.Context, function (req, res) {
    return new marketplace.Context({
        name: "mongoDB",
        databaseName: "marketplace",
        address: "localhost",
        port: 27017
    });
}));
app.use("/", c.static(__dirname));
app.use(c.errorHandler());

app.listen(8080);    

客户端是使用SAPUI5开发的,这些是与odata模型创建相关的代码部分:

oModel = sap.ui.model.odata.ODataModel("http://localhost:8080/marketplace", false); // connection to the odata endpoint

oModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);

sap.ui.getCore().setModel(oModel);

在SAPUI5表中正确显示了各种服务,我可以通过这种方式使用POST OData.request轻松插入新服务:

OData.request({
    requestUri: "http://localhost:8080/marketplace/Services",
    method: "POST",
    data: newEntry // json object with the new entry
    },
    function(insertedItem) {
        // success notifier
    },
    function(err) {
        // error notifier
    }
);

以这种方式使用SAPUI5函数oModel.remove()删除服务(oParams是一个包含警报通知函数的json对象):

var serviceId = oTable.getRows()[selectedIndex].getCells()[0].getText();

oModel.remove("/Services('" + serviceId + "')", oParams);

一切正常,但单个服务的更新请求。我尝试使用SAPUI5提供的函数(oModel.update或oModel.submitChanges),通过使用OData.request(“method:PUT”),通过创建ajax PUT请求,我也试图用Fiddler制作PUT请求。 我总是得到错误404:

Request URL:http://localhost:8080/marketplace/Services('NTMzZDM3M2JlNjY2YjY3ODIwZjlmOTQ0')
Request Method:PUT
Status Code:404 Not Found

哪里可以出问题? 我试过Chrome,IE和Firefox;同样的问题... 感谢

1 个答案:

答案 0 :(得分:3)

尝试使用MERGE谓词进行更新,并在BODY

中传递JSON格式的修改字段