cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming xsodata in SAPUI5

rubens12
Participant
0 Kudos

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>


Accepted Solutions (0)

Answers (2)

Answers (2)

tridwip
Participant
0 Kudos

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.

Joseph_BERTHE
Active Contributor
0 Kudos

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

rubens12
Participant
0 Kudos

Can you show me an example how can I use reverse proxy?

Joseph_BERTHE
Active Contributor
0 Kudos

Oula !!!! 🙂 for Reverse proxy, you will need a Apache proxy server (I assume you will not deploy on SAP Cloud Platefrom because it has already a reverse proxy integrated)

Please have a look at this blog

Regards