Skip to Content

Handling session Timeout in SAP HANA Cloud Portal

Jan 12, 2017 at 07:02 AM


avatar image

Hi Experts,

I am working with HCP Portal SAPUI5 apps. I need to check the session before every data call is made to the backend so I can redirect the user back to the logon page.

In the HANA Cloud documentation, the below code is provided:

jQuery(document).ajaxComplete(function(e, jqXHR) {
  if (jqXHR.getResponseHeader("")) {
    alert("Session is expired, page shall be reloaded.");, this, function() {

Does the above code only works for both Ajax and oData calls. We want to redirect the user in every case to the logon page after session expiry.

Is there a direct method to achieve it both for oData calls and Ajax calls?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Ulrich Block
Jan 16, 2017 at 01:00 PM

Hi Deepak,

check the JSDoc of sap.ui.model.odata.ODataModel or sap.ui.model.odata.v2.ODataModel or newer if you are already using it.

In any case you will see a list of events you could add an event handler to. One try could be the requestFailed, which could be added like:

var oModel = new sap.ui.model.odata.ODataModel(...);
oModel.attachRequestFailed(this.handleRequestFailed, this);

Define the handler like:

handleRequestFailed: function(oEvent) {
10 |10000 characters needed characters left characters exceeded
Boaz Wimmer
Jan 12, 2017 at 02:39 PM

Hi Deepak,

Indeed, the code you mentioned, which is detailed under, is relevant to Ajax calls. However, it doesn't handle oData calls, which you can handle separately for every such call in order to redirect back to the logon page. I'm not aware of any direct method to achieve both calls.

Best Regards,

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks Boaz,

Can you help me with how to acheive the same for oData calls. I tried using below code, but the code never hits oMetadata Failed even after I have invalidated the session., this, function() {
				var serviceURL = this.getManifestEntry("/");
				var sessionCheckURL = serviceURL + "/BRS/HAA/services/AppConfig.xsodata";
				var oSessionChckModel = new sap.ui.model.odata.ODataModel(sessionCheckURL);
					alert("session expired");	
				}, this);
					alert("session Alive");

It never goes into the attachMetadataFailed Event and inside the MetadataLoaded Event, I cannot find the parameter "" in the headers.

The way I test the session timeout is as follows:

  1. Run the SAPUI5 App.
  2. Logout of HANA Cloud Platform Cockpit so it invalidates the session at IDP level (i.e. each single application).
  3. make oData calls to a sample service every 5 seconds to check if session is valid.

Should I be using a different approach?

Best Regards,