Hello Experts
,
My SAPUI5 application server is a SAP J2EE engine and my Gateway server is an ABAP server (there is SSO between the two servers).
I'm trying to run a service as JSONModel and ODataModel:
1) JSON Model
var oModel = new sap.ui.model.json.JSONModel();
jQuery.ajax({
url: "<server>:<port>sap/opu/odata/sap/ZOMRI_PRJ2_SRV/ConnectionDetailsSet(RequestText='Omri')?$format=json",
dataType: "json",
xhrFields: {
withCredentials: true
},
success: function(data, textStatus, jqXHR) {
oModel.setData({data: data});
console.log(data.d.RequestText);
console.log(data.d.ResponseText);
console.log(data.d.ResponseEchoText);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Error --> " + errorThrown);
}
});
in the ABAP side (Gateway), I added the following headers in DPC_EXT class:
ls_header-name = 'Access-Control-Allow-Origin'.
ls_header-value = '<server>:<port>'.
/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).
ls_header-name = 'Access-Control-Allow-Credentials'.
ls_header-value = 'true'.
/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).
This works and I'm getting the result data.
2) Trying to run the service as ODataModel (or to be exact create the model without invoking and method)
var oModel2 = new sap.ui.model.odata.ODataModel(
"http://<server>:<port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV/",
true, // bJSON
null, // sUser
null, //sPassword
true, // mHeaders
false, //bTokenHandling
true //bWithCredentials
);
Doesn't work - I'm getting 401 Unauthorized error
SAP UI Version is 1.16.6
I assumed that setting 'bWithCredentials' to true will work with ODataModel because it's working on JSONModel.
How can I solve it?
Regards,
Omri