3

I am trying to access my database tables from SAP HANA, and I am encountering a CORS issue I believe in accessing the data without ta Access-Control-Allow-Origin Error, and of all the resources I've been looking at haven't solved the issue yet.

So I have created a cloud connector port to connect to a destination I have setup in my SAP HANA Cloud Platform Cockpit, which I am trying to access from my SAP WebIDE. I am trying to access a few tables from SAP HANA, so I created a XS project with the following .xsacccess file:

{
 "exposed" : true,  
              
 "authentication" :                                            
        {
           "method": "Basic"   
        },

 "cache_control" : "must-revalidate", 

 "cors" :[{
         "enabled" : true,
         "allowMethods": [
         "GET",
         "POST",
         "HEAD",
         "OPTIONS"],
         "allowOrigin" : ["*"],
         "exposeHeaders": "access-control-allow-headers,Access-Control-Allow-Origin,access-control-expose-headers,authorization",
         "allowHeaders":"Origin, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control",
         "maxAge" : "3600"
        }],
        
 "headers" : {"enabled": true},
                 
 "enable_etags" : true,

 "force_ssl" : true,
 
 "prevent_xsrf" : false,
 "allowCredential":true,
 
 "anonymous_connection": null
}

And the following .xsodata file:

service {
"HD"."TESTCASES" as "TESTCASES";
"HD"."FAILCASES" as "FAILCASES";
}

I setup my CORS in the XS Admin Tool as the following:

Image 1 Image2

I am trying to call the service with the SAPUI5 command:

var newModel = new sap.ui.model.odata.v2.ODataModel("https://webidecp-i863039trial.dispatcher.hanatrial.ondemand.com/destinations/Hana/oDataAcess/oData.xsodata", {
        headers: {"Access-Control-Allow-Origin" : "*"},
        user: "XXXXX",
        password: "XXXXXX",
        withCredentials: true
        });

But I am getting the popular error message:

Failed to load https://webidecp-XXXXXXXtrial.dispatcher.hanatrial.ondemand.com/destinations/Hana/oDataAcess/oData.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 'https://webidetesting3106899-XXXXXXXtrial.dispatcher.hanatrial.ondemand.com' is therefore not allowed access.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
seanjedi
  • 69
  • 1
  • 10
  • One thing you probably want to do is, check to make sure the HTTP status code of the response is a 2xx code (and not a 4xx or 5xx error code, or a 3xx redirect). – sideshowbarker Aug 03 '18 at 06:22
  • The HTTP status code is: Status Code: 200 OK – seanjedi Aug 03 '18 at 18:52
  • If you have setup a destination, why use the full url in your ODataModel call? You should just need the destination name then the path to the XSOData service. – Abdel Dadouche Aug 05 '18 at 07:45
  • @AbdelDadouce I put in the full url because I want to export the project, so that later on it can be standalone, and run on it's own server. I don't know if it would still work if I don't have the full URL. I tried what you suggested, and it still doesnt work for me (I put in the Destination/path, and its now a 404) – seanjedi Aug 06 '18 at 17:01
  • Maybe I missed something in your architecture, so let see if I got it right. You have HANA on prem. WebIDE on SAP CP. And you want to build a SAPUI5 to be deployed on SAP CP, right? – Abdel Dadouche Aug 06 '18 at 22:28
  • If so, then in HANA on prem you have to build your xs odata service. From there you should be able to accès it from a REST client on prem too. Then you can start playing with the SAP Cloud Conector, and define a Cloud to On Prem connection to the xs odata url using https most likely. This will surface the virtual host on your SAP CP cockpit to be used in your destination and the used in your SAPUI5 app – Abdel Dadouche Aug 06 '18 at 22:36
  • 1
    But first you need to test if you can use the xs odata on prem using a rest client. I would also recommend you to use something different than * in the allow origin config as this might end up be a security problem later. – Abdel Dadouche Aug 06 '18 at 22:42
  • I want to build SAPUI5 to be deployed on a Monsoon Server later on. So I need to be able to export my program so that it can work even when it is not deployed on SAP CP. I was coding on SAP Eclipse IDE earlier, but I felt like SAP WebIDE was more comfortable to use. – seanjedi Aug 08 '18 at 01:16

0 Answers0