cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Still problems with Access-Control-Allow-Origin

Former Member
0 Likes
4,932

Hello there,

i am developing in IntelliJ IDEA with an OpenUI5 SDK 1.36.5. While trying to access my Odata Service with an ODataModel i get continuously an access error seeing below:

What have i done?

Too make it short:

  • Created a new project in SAP Gateway Service Builder (TAC: SEGW)
  • Referenced a table with fields and data (not necessary, its working )
  • Implemented the "GetEntitySet (Query)" Method in the folder "Service Implementation/VBAKUK_UI5Set" (= Name of the Entity Set)

 

To check the headers i use Postman. With http://[server]:[port]/sap/opu/odata/sap/ZUI5_IW74874_TEST_SRV/VBAKUK_UI5Set/ and an Basic Authorization Header (credentials to get access) i get all the data i want plus the "access-control-allow-origin →*" header.

Now to the code i have written

<script>
   sap.ui.localResources("sap_ui5_playground");
   sap.ui.localResources("util");
   sap.ui.localResources("i18n");
   var oView = sap.ui.view({

   viewName: "sap_ui5_playground.Main",
   type: sap.ui.core.mvc.ViewType.HTML
   });
   oView.placeAt("content");
</script>
<script>
   var url = "http://[host]:[port]/sap/opu/odata/sap/ZUI5_IW74874_TEST_SRV/";     //url as full address
   var oModel = new sap.ui.model.odata.ODataModel(url, false, "[username]", "[password]");     //name and pw as plain text here
   sap.ui.getCore().setModel(oModel, "odata");

   var oTable = new sap.ui.table.Table({

        width: "100%",
        title: "Daten aus dem SAP mit OData",
        editable: true,
        items: "{odata>/VBAKUK_UI5Set?$format=json&sap-client=201}"
   });
   oTable.addColumn(new sap.ui.table.Column({

        id: "Mandt",
        label: new sap.ui.commons.Label({

             text: "Mandt"
        }),
        template: new sap.ui.commons.TextView({

             text: "{odata>Mandt}"
        })

  }));

  [more columns]

  oTable.setModel(oModel);

  oTable.placeAt("content");

I tried several ways in coding to fix the issue yet, nothing worked. If you know any way further to help me i would really appreciate it. I am open for every hint you're might be able to give, so don't hesitate to answer

Best regards,

Max

View Entire Topic
jamie_cawley
Product and Topic Expert
Product and Topic Expert
0 Likes

This is your browser preventing a cross origin request.  You can either use a proxy to load the data, turn off your browser security, or use SAP Web IDE.

HTTP access control (CORS) - HTTP | MDN

Regards,

Jamie

SAP - Technology RIG

Former Member
0 Likes

I know that my browser is blocking it, so my try was to turn around that by adding the origin header. Are there only these three options? If yes then i would choose proxy i suppose

jamie_cawley
Product and Topic Expert
Product and Topic Expert
0 Likes

UI5 provides a proxy, which I have only ever used in eclipse

Use a SimpleProxyServlet for Testing to Avoid Cross-domain Requests - UI Development Toolkit for HTM...

You can turn off cors in chrome by starting it with --disable-web-security --user-data-dir

Regards,

Jamie

SAP - Technology RIG

Former Member
0 Likes

I try to avoid disabling CORS because it should be used as most independent as it is possible now. If i can only use it with that its not very...usable i would say additionally, i'm coding on OS X so it's not even possible to do that as easily as it is on Windows

I will take a look over the UI5 Sample Proxy. It looks like a nice try for now. Thanks for that

jamie_cawley
Product and Topic Expert
Product and Topic Expert
0 Likes

You can set in the terminal on a mac...

open '/Applications/Google Chrome.app' --args --disable-web-security --user-data-dir


Regards,

Jamie

SAP - Technology RIG

Former Member
0 Likes

Oh thx...i didn't know that. Will try it out