Different rewrite modes require different service root URLs in SMP and HCPms
One customer was having a big problem with duplication of records (Violation of PRIMARY KEY constraint), when trying to add any purchase request via their HCPms offline native app for Android. For some reason, the device was not receiving an acknowledge from the backend saying that the flushed data had been committed. So, when another operation in the offline store was performed and a flush was called again, the duplication error happened again, because, for the offline store, the first purchase request had not been committed to the backend yet.
The reason behind this issue was incorrect understanding of how to properly setup and code for offline OData. The documentation provided was somewhat vague and has been improved due to this finding. For now, you can refer to the HCPms documentation which is very well explained: SAP HANA Cloud Platform Mobile Services. Please, remember that some other error would also have happened for an online app.
Different rewrite modes require different service root URLs in SMP and HCPms. The customer had set the Rewrite Mode field of the connection to the backend configuration to the Rewrite URL on Backend value, but had set the serviceRoot option of the OData Offline Store Options as if they had set the Rewrite Mode field of the connection to the backend configuration to the Rewrite URL on HANA Mobile Server value. Remember that the serviceRoot property of an offline store options structure identifies the root of an OData service.
OK, so let’s understand what is the correct value for each Rewrite Mode option:
- Rewrite URL on Backend: the serviceRoot option should be set to the full URL, which includes the server and the full path of the back-end system, http(s)://<server-host>:<server-port>/<back-end path to OData Endpoint>. See and example below:
- If the backend URL is: http://mybackend:5000/sap/opu/odata/sap/service, and the HANA Cloud Platform Mobile Services or SAP Mobile Platform server URL is: http://myserver:8080, then the serviceRoot option should be set to: http://myserver:8080/sap/opu/odata/sap/service.
- Rewrite URL on HANA Mobile Server: the serviceRoot option should be set to http(s)://<server-host>:<server-port>/<ApplicationID>. See an example below:
- If the backend URL is: http://mybackend:5000/sap/opu/odata/sap/service, and the HANA Cloud Platform Mobile Services or SAP Mobile Platform server URL is: http://myserver:8080, then the serviceRoot option should be set to: http://myserver:8080/<ApplicationID>.
- No Rewriting: “request and response messages are not modified; SAP HANA Cloud Platform mobile services passes messages directly between clients and the back end”.
NOTE: “To enable applications using an external back end to run offline, you must select one of the rewrite options.“
In Java code, the store options would look like the following for the Rewrite URL on Backend option:
ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();
…
options.host = “myserver”;
options.port = “8080”;
options.serviceRoot = “http://myserver:8080/sap/opu/odata/sap/service“;
…
In Java code, the store options would look like the following for the Rewrite URL on HANA Mobile Server option:
ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();
…
options.host = “myserver”;
options.port = “8080”;
options.serviceRoot = “http://myserver:8080/<ApplicationID>“;
…
Thanks for your sharing of the story and the solution.