Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Atlas Cross Origin CORS

avatar
Contributor

Hello,

I would like to access to Apache Atlas via a XmlHtttRequest object. It doesn't work:

Access-Control-Allow-Origin is missing.

Thks for your help.

1 ACCEPTED SOLUTION

avatar
Expert Contributor
Try adding CORS related headers here and recompile atlas project.
responseWrapper.setHeader("Access-Control-Allow-Origin", "*"); 
responseWrapper.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD, PUT, POST");

This should work.

View solution in original post

4 REPLIES 4

avatar
Expert Contributor

@Smart Data,

Can you please give more details on how are you trying to access and error you are getting?

Nixon

avatar
Contributor

Hello @Nixon Rodrigues

My snippet code :

<html>
<head>
</head>
<body>
<h1>TEST</h1>
<script type="text/javascript">
    var myTestRequest = function() {
        var myUrl = "http://SERVER_IP:21000/api/atlas/types/";
        //Instantiate HTTP Request
        var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
        request.open("GET", myUrl, true);
        request.setRequestHeader("Content-Type","application/json");
        //request.channel.QueryInterface(Components.interfaces.nsIHttpChannel).redirectionLimit = 0;

        request.setRequestHeader("Authorization", "Basic " + btoa("admin:admin"));
        //request.withCredentials = true;
        request.send(null);
    }
</script>
    <div id="myTestRequest" style="display: block">
      <button onclick="myTestRequest()">Login</button>
    </div>
</body>
</html>

Error (in attached file):

XMLHttpRequest cannot load http://SERVER_IP:21000/api/atlas/types/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://SERVER_IP:8000' is therefore not allowed access. The response had HTTP status code 400.

Thank you for your help.


cors.jpg

avatar
Expert Contributor
Try adding CORS related headers here and recompile atlas project.
responseWrapper.setHeader("Access-Control-Allow-Origin", "*"); 
responseWrapper.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD, PUT, POST");

This should work.

avatar
Contributor

@Nixon RodriguesThank you so much for your help. It will try it; it should work.

May we shoud notify a JIRA ? Or Pull Request on github for this change.

It should better if we could put this on atlas-application.properties.

Best regards