Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Atlas Cross Origin CORS

Solved Go to solution

Atlas Cross Origin CORS

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

Accepted Solutions

Re: Atlas Cross Origin CORS

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.

4 REPLIES 4

Re: Atlas Cross Origin CORS

Expert Contributor

@Smart Data,

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

Nixon

Re: Atlas Cross Origin CORS

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

Re: Atlas Cross Origin CORS

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.

Re: Atlas Cross Origin CORS

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