Cloud connector fails to load JSON data on device

829 Views Asked by At

Our client has changed its system to SAP and wants an app to display data via SAP interface. We decided to use the SAPUI5 framework + WebIDE to develop the app, since it provides a very good control variety with a solid MVC design as well as easy-to-use cloud connectors for the SAP interface.

We have configured a connector like this:

neo-app.json

{
  "welcomeFile": "/webapp/index.html",
  "routes": [
    {
      "path": "/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources"
      },
      "description": "SAPUI5 Test Resources"
    },
    {
      "path": "/mynews",
      "target": {
        "type": "destination",
        "name": "MyNews_CMS",
        "preferLocal": true
      }
    }
  ],
  "sendWelcomeFileRedirect": true
}

This is our test call in the component.js:

try {                                                                               
  $.get("/mynews/?json=2", function(data, status) {                                                                                 
    alert("success: " + JSON.stringify(data));                                                                              
  }).fail(function(arg1) {                                                                                 
    alert("error: " + JSON.stringify(arg1));                                                                               
  });                                                                           
} catch (err) { 
  alert("global error: " + err);
}

In our WebIDE we get a full JSON with all the wanted data from the SAP connector API, however, as soon as we build the App and publish it on any device using HAT (Android, iOS, even signed), the request fails.

first, it alerts {} (empty object), then it alerts error: {"readyState":0,"status":0,"statusText":"error"}

How can we solve this issue?

1

There are 1 best solutions below

1
On

The neo-app.json has nothing to do with your UI5 application. It isn't even required to get the application working because only the SAP WebIDE interprets and uses this file for configuration purposes.

What you really want to do is define your destinations inside your manifest.json:

...
"dataSources": {
   "ODataEndpoint": {
        "uri": "https://yourappname.hana.ondemand.com/your/odata/path/",
        "type": "OData",
        "settings": {
           "odataVersion": "2.0",
           "localUri": "/your/odata/path/"
        }
    }
}
...
"models": {
    "": {
        "dataSource": "ODataEndpoint"
    }
}
...

If this doesn't work you should debug your devices network activity to see which URL gets called.

How to debug network calls inside an iOS App: https://cordova.apache.org/docs/en/latest/guide/next/#ios-debugging

How to debug network calls inside an Android App: https://cordova.apache.org/docs/en/latest/guide/next/#chrome-remote-debugging