on 01-12-2017 7:02 AM
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("com.sap.cloud.security.login")) {
alert("Session is expired, page shall be reloaded.");
jQuery.sap.delayedCall(0, this, function() {
location.reload(true);
});
}
});
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?
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) {
console.log(oEvent);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Deepak,
Indeed, the code you mentioned, which is detailed under https://help.hana.ondemand.com/help/frameset.htm?de16793b391a4bcfae6096f34433de76.html, 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,
Boaz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
jQuery.sap.intervalCall(5000, this, function() {
var serviceURL = this.getManifestEntry("/sap.app/dataSources/domainPath/uri");
var sessionCheckURL = serviceURL + "/BRS/HAA/services/AppConfig.xsodata";
var oSessionChckModel = new sap.ui.model.odata.ODataModel(sessionCheckURL);
oSessionChckModel.attachMetadataFailed(function(oEvent){
alert("session expired");
}, this);
oSessionChckModel.attachMetadataLoaded(function(oEvent){
alert("session Alive");
});
});
It never goes into the attachMetadataFailed Event and inside the MetadataLoaded Event, I cannot find the parameter "com.sap.cloud.security.login" in the headers.
The way I test the session timeout is as follows:
Should I be using a different approach?
Best Regards,
Deepak
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.