Skip to Content

Consuming xsodata in SAPUI5

I am try consume an xsodata service like Odata in SAPUI5 in Eclipse, but I get some erros:

Failed to load https://.../carimbo.xsodata/$metadata: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost...' is therefore not allowed access.

2017-09-29 10:09:55.242715 [ODataMetadata] initial loading of metadata failed -

Failed to load https://.../carimbo.xsodata/Lacamento: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:...' is therefore not allowed access.

2017-09-29 10:09:55.256280 The following problem occurred: HTTP request failed0,,

Uncaught (in promise) {xmlDoc: document}

Uncaught (in promise) {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…6.140:4311/HelloWorld/carimbo.xsodata/$metadata'.", request: undefined, response: undefined}

Bellow is my code.

Controller:

sap.ui.define([
		'jquery.sap.global',
		'sap/ui/core/mvc/Controller',
		'sap/ui/model/json/JSONModel'
	], function(jQuery, Controller, JSONModel) {
	"use strict";


	var ListController = Controller.extend("sap.m.sample.ListCounter.List", {


		onInit : function (evt) {
			var sServiceUrl = "https://.../carimbo.xsodata";
			var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "user", "pass");


			var oJsonModel = new sap.ui.model.json.JSONModel();


			oModel.read("/Lacamento?", null, null, true, function(oData, response) {
				oJsonModel.setData(oData);


			});
			sap.ui.getCore().setModel(oJsonModel);
			this.getView().setModel(oJsonModel);
		}
	});




	return ListController;


});


View

<mvc:View
	controllerName="sap.m.sample.ListCounter.List"
	xmlns:mvc="sap.ui.core.mvc"
	xmlns="sap.m">
	<List
		headerText="Products"
		items="{
			path: '/results'
		}" >
		<StandardListItem
			title="{CARIMBO}"
			/>
	</List>
</mvc:View>


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 29, 2017 at 03:41 PM

    Hello,

    Your problem comes from CORS issue. You try to access to an URL from another demain.

    For instance your domain is myapp.mycompany.com and you want that app call an url like this thisAPI.anotherdomain.com

    This is forbiden by browser, two solutions :

    1. Use a reverse proxy

    2. for Development only, use a CORS plugin for Chrome

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 22 at 05:11 PM

    Hi,

    Please create a destination with the credentials and call it via a model created in manifest.json file and the path is defined in neoapp.json.

    Add comment
    10|10000 characters needed characters exceeded