Skip to Content
author's profile photo Former Member
Former Member

Problem in enabling CORS with Hana SPS6

Hi folks,

I asked it in other discussion, but I thought it'd be interesting to create this one in case that anyone else faces this same issue.

I'm having problem in enabling the CORS (Cross-Origin Request Sharing) feature in my Hana version 68.

According to the Developer Guide rev.SPS6, it's said that just including the follow line bellow in the .xsaccess file of the XS project is enough to activate it:

"cors" : [{ "enabled" : true }]

However, this is not working for me. I'm not able yet to receive permission to access any xsjs using HTTP requests from my local webserver using jQuery Ajax.

Does anyone already used CORS successfully on Hana?

Thanks in advance!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Oct 31, 2013 at 10:20 PM

    What Web Browser are you using?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I've tried on Firefox and Chrome.

      I'm able to receive response using JSONP normally. The problem is that I'd like to implement Form-Based authentication on my app and, thus, I need to perform POST requests, which is not able with JSONP

  • author's profile photo Former Member
    Former Member
    Posted on Nov 04, 2013 at 07:00 PM

    Does anyone have any insight about how to make CORS work on Hana rev. 68?

    Thanks in advance..

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 12, 2013 at 10:14 AM

    Just to inform those who can face the same problem, I realized why CORS wasn't working before.

    You have to disable any type of authentication on the .xsaccess to make it work, otherwise, you'll still receive the same origin policy error from the browser.

    But, as in my purpose, the idea was to use it to get easier to implement Form-Based Authentication on my application, it didn't solved my problem.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 29, 2013 at 10:37 AM

    Hi,

    Trying to call an AWS Hana xsjs service to insert table values from a localhost script, specifically wanting to perform asynchronous Hana updates from a local UI.

    I have removed the following from my .xsaccess

    "authentication":[

    {

    "method":"LogonTicket"

    },

    {

    "method":"Basic"

    }

    ]

    And added:

    "cors" : { "enabled" : true }

    My jquery ajax call to the xsjs service looks like:

    var msg = '001ABCDE';

    var jURL = 'http://hanaserver:8000/abc/def/services/Log.xsjs';

    jQuery.ajax({

    url:jURL,

    data: {msg : msg},

    type: 'POST',

    headers : {"Access-Control-Allow-Origin" : "*"},

    crossDomain: true,

    success: function() { console.log('Success'); },

    error: function() { console.log('Failed!'); }

    });

    And the XSJS service like this:

    function logVMessage(){

    var conn = $.db.getConnection();

    var msg = $.request.parameters.get('msg');

    var vId = msg.substr(0,3);

    var feed = msg.substr(3,5);

    var query = 'INSERT INTO "abc.def.data::vLog" values(?,?)';

    var st = conn.prepareStatement(query);

    st.setString(1,vId);

    st.setString(2,feed);

    st.execute();

    conn.commit();

    conn.close();

    }

    logVMessage();

    I get the error "No Access-Control-Allow-Origin header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access".

    Anyone got CORS working on Hana? I am on AWS Rev 68, using Chrome browser.

    Many thanks.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Thomas,

      I just got the jquery ajax call to work, inserting table data via my xsjs service, jquery ajax called modified as below:

      jQuery.ajax({

      url:jURL,

      jsonpCallback: 'processJSON',

      dataType: 'jsonp',

      data: {msg : msg},

      type: 'GET',

      headers : {"Access-Control-Allow-Origin" : "*"},

      crossDomain: true,

      success: function(result) { console.log(result); },

      error: function() { console.log('Failed!'); }

      });

      Note the type = GET (I don't think this matters from the point of view of successful xsjs service execution whether this is POST or GET?).

      Also I am prompted for basic authentication with my user name/password on first call to service, even though I have updated my .xsaccess file removing the basic authentication entry (I did not restart my AWS instance as I was using a spot instance).

      Thus it works at the moment, however I would like to remove the authentication so imagine this can be done by configuring the anonymous service.

      Many thanks.

  • Posted on Jan 06, 2014 at 02:11 PM

    Please try adding xhrFields: {withCredentials: true} parameter in the ajax call! We had the same issue, adding this parameter resolved the issue.

    Regards,

    Ram

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.