openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

odata.v2.ODataModel, Kapsel OData Offline, DataBinding

Open chumbalum opened this issue 11 years ago • 21 comments

Hi,

I encountered a bug with the v2.ODataModel, DataBinding and the SAP Kapsel OData Offline Plugin. The issue does not exist with the old ODataModel class. I didn't find the the source of this issue, so I try to describe the problem:

Szenario:

  • OData Offline Store is initialized with a simple defining request (e.g. "/BusinessPartnerCollection")
  • v2.ODataModel is initialized with the same backend URL
  • Simple UI5 app with a table which items are bound to path /BusinessPartnerCollection
  • Implicit requests should be handled by the OData Offline Store

The startup of the app is like this

initODataModel(context);
initOfflineStore(context);
initSAPUI5();
function initODataModel(context){

    _url = context.applicationEndpointURL;  

    _headers = {
        "X-SMP-APPCID": context.applicationConnectionId
    };    

    var oModel = new sap.ui.model.odata.v2.ODataModel(_url, {
        user: context.registrationContext.user,
        password: context.registrationContext.password,
        headers: _headers
    });

    sap.ui.getCore().setModel(oModel);
}
function initOfflineStore(context){

    var auth = "Basic " + btoa(context.registrationContext.user + ":" + context.registrationContext.password);

    var properties = {
        name: "XYZ",
        host: context.registrationContext.serverHost,
        port: context.registrationContext.serverPort,
        https: context.registrationContext.https,
        serviceRoot: context.applicationEndpointURL,
        definingRequests: {
            BPCollection: "/BusinessPartnerCollection"
        },
        customHeaders: {
            "X-SMP-APPCID": context.applicationConnectionId,
            "Authorization": auth
        }
    };

    var store = sap.OData.createOfflineStore(properties);

    store.open(
        function(){
            jQuery.sap.log.info(".. store open success");
            sap.OData.applyHttpClient();
        },
        function(error){
            jQuery.sap.log.info(".. store open error: " + error);
        }
    );
}
function initSAPUI5(){
    init shell ...
}

with the old ODataModel the app works like expected:

  • the store is opened, the http client is applied, the odata model is initialized
  • when the view with the table is loaded, the implicit request of the model will be made against the odata offline store
  • data is shown in the ui

with the new ODataModel.v2 this happens:

  • the store is opened, the http client is applied, the odata model is initialized
  • when the view with the table is loaded, no request is made against the odata offline store
  • no data shown in the ui

so I have some speculations of what could go wrong here:

  • maybe the requests of v2.ODataModel don't match the request scheme which will be handled by the odata offline plugin

openui5 runtime used: v1.28.10

platform used: ios

cordova plugins used

com.sap.mp.cordova.plugins.authproxy 3.8.1 "AuthProxy"
com.sap.mp.cordova.plugins.corelibs 3.8.1 "CoreLibs"
com.sap.mp.cordova.plugins.logon 3.8.1 "Logon"
com.sap.mp.cordova.plugins.odata 3.8.1 "OData"
org.apache.cordova.console 0.2.13 "Console"
org.apache.cordova.device 0.3.0 "Device"
org.apache.cordova.inappbrowser 0.6.0-patched "InAppBrowser"

I hope this information helps to find the bug. Since this problem does not happen with the old ODataModel, I consider it as a bug. If you have any questions, feel free to ask

greetings, chumbalum

chumbalum avatar Jul 02 '15 12:07 chumbalum

This is a tough one, if you do not have an example that we can test.

The main differences between the two Model versions are asynchronous operations (the v2-Model only supports asynchronous requests) and the enhanced batch support.

Can you please test whether the problem also occurrs when using the (v1) Model with the "loadMetadataAsync" flag set to true?

sirion avatar Jul 03 '15 07:07 sirion

Hi,

I made some more tests and it seems like the call of

sap.OData.applyHttpClient();

does not affect the ODataModel.v2 if the call is made, when the device doesn't have a network connection.

To test this, I made some debug output to the odata offline store plugin (OData.js)

    var httpClient = {
        request: function (request, success, error) {
            console.log(".. odata offline store http client ..");
            ...
        }
    };

when I manually make a request to the Model like this

oModel.read("/BusinessPartnerCollection", {
    success: function(oData, response){
        console.log(".. oModel.read success: " + oData.results.length);
    },
    error: function(oError){
        console.log(".. oModel.read failed");
    }
});

the console.log will not be triggered, hence the ODataModel.v2 doesn't use the http client of the odata offline store.

The old ODataModel uses the odata offline http client as expected and the console.log will be triggered.

The problem with ODataModel.v2 only occurs, if the the device is offline while applying the odata offline store http client (unplugged network cable - ios simulator). If the device has a connection and sap.OData.applyHttpClient() is called, the requests of the ODataModel.v2 will use the odata offline store http client as expected.

short summary of my observations: The OData Offline Store http client is not applied to the ODataModel.v2 if the device doesn't have a network connection. So maybe the initialization of the ODataModel.v2 is blocked somehow when the device is offline and the application of the offline store http client fails (speculation)

greetings, chumbalum

chumbalum avatar Jul 06 '15 12:07 chumbalum

To be honest, I have no idea how to find more details on this. sap.OData is not provided by us and we only use XMLHttpRequests via data.js to access the service.

From which project did you get the code that contains the sap.OData namespace?

sirion avatar Jul 09 '15 07:07 sirion

The sap.OData namespace comes from the SAP Kapsel Plugins for Cordova. It is used for hybrid mobile applications with offline capabilities. The offline plugin catches requests and provides data from a pre-populated database. Kapsel comes with the SAP Mobile Platform SDK.

http://help.sap.com/Download/Multimedia/html-smp308sdk/jsdoc/sap.OData.html

Since OpenUI5 is related with SAPUI5, I thought this would be the right place to report bugs concerning UI5 and SAP technologies.

chumbalum avatar Jul 09 '15 09:07 chumbalum

Actually we do anything but the commercial part of UI5 here. If you are an SAP customer, you can open a ticket - that is usually faster than through our internal channel. I will try get in contact with the colleagues to find out in which of the components the problem lies.

If you open a ticket in the meantime please report the number here, so we can follow up on it.

sirion avatar Jul 09 '15 20:07 sirion

Hi @chumbalum,

could you please try instantiating your v2-Model with the flag useBatch: false The v2-Model uses batch mode by default, but I am not sure the Kapsel-Plugin supports it.

sirion avatar Jul 13 '15 14:07 sirion

Hi,

I tested it with the useBatch=false option but it didn't work either. As I mentioned I added some debug output in the Kapsel OData plugin, which will print some messages, if a request is made.

With the ODataModel.v2, no messages appear. This means, no request of the ODataModel.v2 will be made via the OData Offline Store HTTP Client at all. So I still have the opinion, that the HTTP Client of the OData Offline Store is not correctly attached to the ODataModel.v2. As I mentioned, this only happens, if the device is offline. If the device is online, the Offline Store HTTP Client is correctly attached and used.

greetings, chumbalum

chumbalum avatar Jul 22 '15 13:07 chumbalum

I am in contact with the colleagues. I still think that this is not a UI5 issue as we just use XMLHttpRequest to communicate to any server.

I will update this issue as soon as I hear something.

sirion avatar Jul 24 '15 16:07 sirion

Hi chumbalum,

did you find a solution to this issue? I am experiencing the same thing in a current project.

Maybe I have to handle all offline OData request via the kapsel SDK Sap.OData.request?

It would however be much easier if the OData v2 model was updated automatically against the offline store db.

I hope you have a hint that can help me.

best regards Morten Milbak

mortenmilbak avatar Apr 16 '16 19:04 mortenmilbak

Hi @chumbalum , @mortenmilbak

did you find a solution to this issue? I have the same problem :-( Best Regards Patrizia

ghost avatar Sep 12 '16 10:09 ghost

Hi,

no sorry. I didn't investigate it further, so also don't have a solution for the problem. Since I didn't find a solution back in the days, I ditched Kapsel OData Offline and implemented some workaround using sqlite.

greetings, chumbalum

chumbalum avatar Sep 17 '16 21:09 chumbalum

Hi,

thank you for your answer. I solved my problem. It was a SAP WebIDe bug (template for offline 1.32) .

Greetings

Patrizia

From: Christian Hoff [mailto:[email protected]] Sent: sabato 17 settembre 2016 23:01 To: SAP/openui5 [email protected] Cc: patrizia0103 [email protected]; Comment [email protected] Subject: Re: [SAP/openui5] odata.v2.ODataModel, Kapsel OData Offline, DataBinding (#504)

Hi,

no sorry. I didn't investigate it further, so also don't have a solution for the problem. Since I didn't find a solution back in the days, I ditched Kapsel OData Offline and implemented some workaround using sqlite.

greetings, chumbalum

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SAP/openui5/issues/504#issuecomment-247807742 , or mute the thread https://github.com/notifications/unsubscribe-auth/AEQ3tPqI3avqxxRHHVE_kw1_Ilri9JUEks5qrFTugaJpZM4FQoFX . https://github.com/notifications/beacon/AEQ3tKANl7BNF7Xp2IfPz5CM5K8vurkYks5qrFTugaJpZM4FQoFX.gif

ghost avatar Sep 19 '16 07:09 ghost

Any details about the "WEB IDE" bug?

sfdfklskldf avatar Feb 07 '17 08:02 sfdfklskldf

I've created a internal incident 1770162072. You can check its status on GitHub.

Shtilianova avatar Apr 11 '17 14:04 Shtilianova

Hi, both models, v1 and v2, use data.js for the http communication. Data.js uses XMLHttpRequests. Both models use the same version of datajs. So I don't think this is a UI5 bug.

The main difference between the models is that v2 model is working completely asynchronous. It also uses batch requests as default. To investigate further we need an example to reproduce the issue. BR, Jan

loginger avatar Apr 11 '17 15:04 loginger

As far as I can see, the sap.OData API of Kapsel does nothing more than replacing datajs's OData.defaultHttpHandler with its own handler. That handler checks any request (basically the requestUri) against the registered offline storages. If the request matches any of them, the storage is involved, otherwise the request is delegated to the original defaultHttpHandler(XHR).

Our OData v2 model uses OData.request for all its requests, so I don't see a reason from the basic concept of the offline store why it could fail for V2.

The only thing that comes to my mind is order of execution. I'm not sure with the meaning of the above code in the initial post. What exactly does the call initSAPUI5() do? Has UI5 been loaded before initODataModel()? If not, datajs might have been loaded twice, a) by some non-UI5 code and b) by UI5. The applyHttpClient then was made on the datajs instance loaded in a), but UI5 will use b).

@chumbalum: if you're still interested in this, you might check if the defaultHttpClient is still the injected one when the UI5 ODataModel is created (e.g. you might tag it with some property after sap.OData.applyHttpClient().

codeworrior avatar Apr 12 '17 07:04 codeworrior

Is there any SAP Note about that topic. Looks like I also have issues with v2.odatamodel in combination of SAP Kapsel Offline plugin.

sfdfklskldf avatar Apr 27 '17 09:04 sfdfklskldf

Hi.. I am having the same issue. How this issue can be resolved? Any ideas / hints towards resolving this issue would be greatly appreciated.

Thanks.. Balaji

balajigraman avatar May 10 '17 05:05 balajigraman

This error is still not solved after 4 years??? I have the same problem, obviously the reason is, that the Odata-Model's Service Url is e.g. /destination/servicepath and the endpoint of the offline store is e.g. https://mobile-account.hana.ondemand.com/destination/servicepath.

dominik-st avatar Dec 03 '19 12:12 dominik-st

Please run an incident to Hybrid Application Toolkit teams with a question about the valid settings for using v2 oData via sap.ui.model.odata.v2.oDataModel in an offline scenario, and if it is a supported scenario.

On OpenUi5 side, you can test the different setting to cover the restrictions for working with offline data e.g. useBatch:false, defaultCountMode:Inline, json:false and etc. https://openui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel

Try to log in code what requests are initiated and how they ended (blocked, executed with errors, returning wrong response) \Try using the read method to see if data can be requested

stephania87 avatar Dec 03 '19 16:12 stephania87