Cloud connector fails to load JSON data on device
Asked Answered
E

1

6

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?

Enginery answered 15/8, 2017 at 11:55 Comment(2)
@wargre The full url works. Its just the destination that doesn`t work. In my final iOS project i can't find any reference to the destination. It feels like my iOS project is missing the neo-app file or something else.Centrist
I am not a HAT guru but I am afraid neo-app.json file is only used inside WebIDE or inside a deployed app in SAP Cloud (in Portal service for example). Can you confirm that this file is exported when you deploy the app?Priory
K
-1

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

Kistner answered 17/2, 2018 at 12:50 Comment(1)
If anyone ever comes here and reads this answer: The neo-app.json has everything to do with your UI5 application. If your app is running in the SAP Cloud Platform this is the way to tell your app which backend to load. Pls no hardcoded absolute URLs in your manifest.Mcfarlane

© 2022 - 2024 — McMap. All rights reserved.