on 08-17-2014 9:58 AM
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
Solved it by using APACHE as reverse proxy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Detail explanation of the issue-
I have 2 laptops in both laptops I am using eclipse Mars.
In 1 laptop my code is working fine when I use Internet Explorer (but not in chrome and mozilla). Here I have windows 7.
In another laptop I am getting 'no data' for all browser even in IE. Here I am using Windows 10.
While calling Odata service getting 401 unauthorized issue.
So why same code is working in 1 laptop in IE but not in another laptop ?
var oModel = new sap.ui.model.odata.ODataModel("http://220.227.93.78:8000/sap/opu/odata/SAP/ZBG_FLIGHT_SRV", false, "Username", "Password");
IMO, '401' is different than the CORS issue. It might be because of sending " true //bWithCredentials" but null for userid/password.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would try
var oModel2 = new sap.ui.model.odata.ODataModel("http://<server>:port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV")
without supplying any other optional parameters.
Hi,
I tried to write a single line of code:
var oModel2 = new sap.ui.model.odata.ODataModel("http://<server>:<port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV");
This is the console output:
2014-08-19 08:46:31 Device API logging initialized - DEVICE sap-ui-core.js:41
2014-08-19 08:46:31 registerResourcePath ('', '/sapui5/resources/') - sap.ui.ModuleSystem sap-ui-core.js:77
2014-08-19 08:46:31 URL prefixes set to: - sap.ui.ModuleSystem sap-ui-core.js:77
2014-08-19 08:46:31 (default) : /sapui5/resources/ - sap.ui.ModuleSystem sap-ui-core.js:77
2
OPTIONS http://<server>:<port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV/$metadata 401 (Unauthorized) datajs.js:17
OPTIONS http://<server>:<port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV/$metadata 401 (Unauthorized) datajs.js:17
XMLHttpRequest cannot load http://<server>:<port>/sap/opu/odata/sap/ZOMRI_PRJ2_SRV/$metadata. Origin http://<server2>:<port2> is not allowed by Access-Control-Allow-Origin. datajs.js:17
2014-08-19 08:46:32 The following problem occurred: A network error occurred. - sap-ui-core.js:77
u sap-ui-core.js:77
fatal sap-ui-core.js:77
sap.ui.model.odata.ODataModel._handleError ODataModel.js:35
b ODataMetadata.js:7
o.request datajs.js:17
o.read datajs.js:17
sap.ui.model.odata.ODataMetadata._loadMetadata ODataMetadata.js:7
sap.ui.base.Object.extend.constructor ODataMetadata.js:6
sap.ui.model.Model.extend.constructor ODataModel.js:6
o sap-ui-core.js:117
(anonymous function) index.html:60
Regards,
Omri
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.