Search code examples
odatasapui5metadata

Odata service Metadata failed


Backend team has given a new Odata service. I declared it in manifest and used it in controller. It works correct in my system. But it does not work correct in any other environment. I get an error saying - initial loading of Metadata failed. and also some internal server errors.

Manifest.json

"ordersq": {
            "uri": "/sap/opu/odata/sap/ZOrders_QUEUE_SRV/",
            "type": "OData",
            "settings": {
                "odataVersion": "2.0",
                "localUri": "localService/ZOrders_QUEUE_SRV/metadata.xml"
            }
        },

Controller:

var sServiceUrl = this.getOwnerComponent().getMetadata().getManifestEntry("sap.app").dataSources["ordersq"].uri;
                var OdataModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl);
                var sPath = "/BuyersQueueSet('" + mfOrder + "')";
                OdataModel.read(sPath, {
                    success: this.queueSuccess.bind(this),
                    error: this.queueError.bind(this)
                });
            }

Is there something I am missing. Do I have to do something for that metadata.xml ? I did not configure anything more. I just copy pasted localuri how it is given for other services without adding any metadata for this new service.


Solution

  • Probably you are getting a CORS issue. Check in the network trace if you have a 401 or 403 when requesting the $metadata. This happens when you try to load certain resources from a different server.

    It is a known common issue, and it is there for security reasons. There are several ways to overcome it, all pretty well documented.

    In general, if you are using SAP Cloud Platform, just configure a Destination pointing to your service in the Netweaver server (you will need a Cloud Connector to access form the Cloud to your private network). If you are deploying your apps in other Netweaver servers, I think the easiest solution is setting a WebDispatcher as reverse proxy.

    Another possibility is a 404 error when requesting the $metadata. If you are getting this, it is because you are not routing your requests to the correct Netweaver system. Make sure you configure a WebDispacher to resolve certain URLs to the correct system. Again, tons of tutorials out there showing you how to do it.