Skip to Content
0

Consuming xsodata in SAPUI5

Sep 29, 2017 at 01:16 PM

188

avatar image

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>


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Joseph BERTHE Sep 29, 2017 at 03:41 PM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0

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

0