2
votes

I implemented an odata-Service on a SAP NetWeaver Application Server ABAP 7.4 on SAP MaxDB - Trial Edition. It is hosted on Amazon AWS EC2. The odata was implemented with transaction SEGW. (I used this instruction: http://www.abap-developers.com/2014/07/simple-openui5-application-i-how-to-create-odata-model-using-segw/)

I see that the odata service works, because if I input the AWS Linux external IP-adress and enter the credentials on https://52.2.xxx.xxx:50001/sap/opu/odata/sap/ZGW_BUCH_SRV/$metadata I get information about this odata service in the browser (I use https, because the odata will be consumed in the future from a https-site)

Then I want to implement it with OpenUI5. In Chrome I use the extention "Allow-Control-Allow-Origin"

To get access to my odata service I use a similar construction as this:

var url = "http://someurl/SERVICE";
var username = "username";
var password = "password";
var oModel = new sap.ui.model.odata.ODataModel(url, true, username, password);

(I would not use the hardcoded password in a productive scenario).

So my code looks like this:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

        <script src="/js/openui5/resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-libs="sap.ui.commons, sap.ui.table"
                data-sap-ui-theme="sap_bluecrystal">
        </script>

        <script>            

            // setting up model
            var oModel = new sap.ui.model.odata.ODataModel("https://52.2.xxx.xxx:50001/sap/opu/odata/sap/ZGW_BUCH_SRV/", false, "AAA", "BBB");

            sap.ui.getCore().setModel(oModel);

Nevertheless the console in Chrome shows me:

OPTIONS htttps://52.2.xxx.xxx:50001/sap/opu/odata/sap/ZGW_BUCH_SRV/$metadata 401 (Unauthorized) XMLHttpRequest cannot load htttps://52.2.xxx.xxx:50001/sap/opu/odata/sap/ZGW_BUCH_SRV/$metadata. Response for preflight has invalid HTTP status code 401

(I wrote htttps intead of https because I can post here only a limited number of links.)

Access is also not possible in Firefox, Internetexplorer, Edge or Opera. Who can help me out here?

1

1 Answers

0
votes

your server refuses the options request in chrome you can debug it in the developer tools network panel or by using tools like fiddler, tcpdump, wireshark

odata requires specific headers to be sent so your browser will send an option request with those information and your browser plugin might not handle these special keywords

your options:

  1. (best) configure your server to handle cors, more info: http://enable-cors.org, I can not send you a configuration because it's server dependent
  2. create a proxy with handles cors