<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: apache livy and ajax post requests: Method Not Allowed in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180564#M80380</link>
    <description>&lt;P&gt;Hi. Thank you very much. That helps me.&lt;/P&gt;</description>
    <pubDate>Sun, 15 Jul 2018 20:34:57 GMT</pubDate>
    <dc:creator>ndumelchipaul20</dc:creator>
    <dc:date>2018-07-15T20:34:57Z</dc:date>
    <item>
      <title>apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180557#M80373</link>
      <description>&lt;P&gt;Good morning everyone,&lt;/P&gt;&lt;P&gt;can someone help me to see why this jquery code can note create a session to the apache livy? I got these errors : &lt;/P&gt;&lt;P&gt; &lt;STRONG&gt;OPTIONS &lt;A href="http://localhost:8998/" target="_blank"&gt;http://localhost:8998/&lt;/A&gt; 405 (Method Not Allowed)&lt;/STRONG&gt; and &lt;STRONG&gt;Failed to load &lt;A href="http://localhost:8998/:" target="_blank"&gt;http://localhost:8998/:&lt;/A&gt; Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8084' is therefore not allowed access. The response had HTTP status code 405.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This is the code I used :&lt;/P&gt;&lt;PRE&gt;$.ajax({
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            url: 'http://localhost:8998',
            data: {kind: 'spark'},
            success: function (resultat) {
                document.getElementById(response).innerHTML = resultat;
                console.log(resultat);
            }
        });
&lt;/PRE&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;</description>
      <pubDate>Sat, 07 Jul 2018 06:39:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180557#M80373</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-07T06:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180558#M80374</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt; . Thank you for your help. I tried your first code, for starting a session, but I still get the error :  &lt;STRONG&gt;OPTIONS &lt;A href="http://localhost:8998/sessions" target="_blank"&gt;http://localhost:8998/sessions&lt;/A&gt; 405 (Method Not Allowed). &lt;/STRONG&gt;Do you know why this? Thank you again for your efforts.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jul 2018 07:07:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180558#M80374</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-08T07:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180559#M80375</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt; , thank you again for your help.&lt;/P&gt;&lt;P&gt;I think, based on this : &lt;A href="https://issues.apache.org/jira/browse/LIVY-444?jql=text%20~%20%22LIVY%3A%20CORS%22" target="_blank"&gt;https://issues.apache.org/jira/browse/LIVY-444?jql=text%20~%20%22LIVY%3A%20CORS%22&lt;/A&gt;, my problem is because Livy REST API does not have routes to handle OPTIONS requests. I have a web application and apache livy which are using different ports, so then different domains. Do you think it is possible to run apache Livy REST API into my existing java web application so that they can have the same port and then the same domain? Do you have any idea?&lt;/P&gt;&lt;P&gt;Thank you &lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 04:22:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180559#M80375</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-10T04:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180560#M80376</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt; , can you help please, by telling me where I can put that configuration that he is talking here: &lt;A href="https://benjaminhorn.io/code/setting-cors-cross-origin-resource-sharing-on-apache-with-correct-response-headers-allowing-everything-through" target="_blank"&gt;https://benjaminhorn.io/code/setting-cors-cross-origin-resource-sharing-on-apache-with-correct-response-headers-allowing-everything-through&lt;/A&gt;? I still have the problem and I think that problem is because apache livy doesn't allow CORS. I don't know exactly where I can tell apache livy to accept this. Which kind of server does apache livy use? It uses apache, right? So I tried to modify /etc/apache2/apache2.conf in my Ubuntu system but it doesn't work. I really need a help!&lt;/P&gt;&lt;P&gt;Thank you and I hope you understand well my English which must be very bad.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 16:27:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180560#M80376</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-11T16:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180561#M80377</link>
      <description>&lt;P&gt;Hi every one,&lt;/P&gt;&lt;P&gt;do you think it is possible to enable cors in apache livy? I think my problem is from that. I tried all propositions from forums but no solution can resolve my problem. May be it is possible by modifying the livy.conf or livy-client.conf files to do that. But I don't know how.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 17:46:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180561#M80377</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-12T17:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180562#M80378</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt; ,&lt;/P&gt;&lt;P&gt; is this normal that I can not see any of your comments on this topic? That was helping me in resolving my problem. Please, I know  I didn't give a return because I was searching in my side how to make proxy reverse.&lt;/P&gt;&lt;P&gt;Is that possible to put again your comments here?&lt;/P&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 05:50:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180562#M80378</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-15T05:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180563#M80379</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/87152/ndumelchipaul2000.html" nodeid="87152"&gt;@Melchicédec NDUWAYO&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tried deleting one comment  and ended up deleting full thing, sorry. I have a backup of the instructions I provided initially. Later we found this was related to CORS and that Livy does not support it yet. So alternatives are using an http proxy or your web application to redirect the requests.&lt;/P&gt;&lt;P&gt;web page --&amp;gt; your web app backend --&amp;gt; livy&lt;/P&gt;&lt;P&gt;I recommend you use google Postman as it has a feature to generate jquery code. &lt;/P&gt;&lt;P&gt;Here is the jquery code to start a session:&lt;/P&gt;&lt;PRE&gt;var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://localhost:8999/sessions",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "X-Requested-By": "user",
    "Cache-Control": "no-cache",
  },
  "processData": false,
  "data": "{\"kind\": \"spark\"}"
}
 
$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/PRE&gt;&lt;P&gt;Of course on the done function instead of printing to console you need to parse the json and grab the session id to use later as a variable.
Then you will need to wait until session state transitions to idle, in oder to do this you need to execute the following request in regular intervals until state = idle:&lt;/P&gt;&lt;PRE&gt;var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://c24-node2:8999/sessions/&amp;lt;session_id&amp;gt;",
  "method": "GET",
  "headers": {
    "Cache-Control": "no-cache",
    "Postman-Token": "60246911-890b-4f81-8635-da52e54ef633"
  }
}
 
$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/PRE&gt;&lt;P&gt;Above done function needs to parse the json and check if state is idle
Once state is idle we can submit code using the following jquery code:&lt;/P&gt;&lt;PRE&gt;var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://c24-node2:8999/sessions/&amp;lt;session_id&amp;gt;/statements",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "X-Requested-By": "user",
    "Cache-Control": "no-cache",
    "Postman-Token": "aece2722-cbdd-48a2-ae9a-821aba97a2b6"
  },
  "processData": false,
  "data": "{\"code\": \"1 + 1\"}"
}
 
$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/PRE&gt;&lt;P&gt;The above is pushing code "1+1" - Same as before with session we need to grab the result in done function and save the statement id to use later to retrieve the results.
With session id and statement id we can retrieve the results of the execution by running the following jquery:&lt;/P&gt;&lt;PRE&gt;var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://c24-node2:8999/sessions/&amp;lt;session_id&amp;gt;/statements/&amp;lt;statment_id&amp;gt;",
  "method": "GET",
  "headers": {
    "Content-Type": "application/json",
    "X-Requested-By": "user",
    "Cache-Control": "no-cache",
    "Postman-Token": "3be8a12e-af07-4567-83ff-e37b48974e76"
  }
}
 
$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/PRE&gt;&lt;P&gt;The result of the above execution should be similar to this:&lt;/P&gt;&lt;PRE&gt;{
    "id": 1,
    "code": "1 + 1",
    "state": "available",
    "output": {
        "status": "ok",
        "execution_count": 1,
        "data": {
            "text/plain": "res1: Int = 2"
        }
    },
    "progress": 1
}
&lt;/PRE&gt;&lt;P&gt;Hopefully this will help you. Feel free to update this thread if you have any questions.
HTH
*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 20:13:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180563#M80379</guid>
      <dc:creator>falbani</dc:creator>
      <dc:date>2018-07-15T20:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180564#M80380</link>
      <description>&lt;P&gt;Hi. Thank you very much. That helps me.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 20:34:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180564#M80380</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-15T20:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180565#M80381</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt;, I come back again for your help.&lt;/P&gt;&lt;P&gt;I am trying to execute your code step by step, but at the end in the result I get "output": null. Do you know where the problem can come from?&lt;/P&gt;&lt;P&gt;And the state: waiting in the result. &lt;/P&gt;&lt;P&gt;But in the livy/ui I see the result correctly.&lt;/P&gt;&lt;P&gt;Maybe I have to wait until state: available? No?&lt;/P&gt;&lt;P&gt;Here is what I get exactly:&lt;/P&gt;&lt;PRE&gt;{id: 0, code: "1 + 1", state: "waiting", output: null, progress: 0}code:"1 + 1"id:0output:nullprogress:0state:"waiting"__proto__:constructor:ƒ Object()hasOwnProperty:ƒ hasOwnProperty()isPrototypeOf:ƒ isPrototypeOf()propertyIsEnumerable:ƒ propertyIsEnumerable()toLocaleString:ƒ toLocaleString()toString:ƒ toString()valueOf:ƒ valueOf()__defineGetter__:ƒ __defineGetter__()__defineSetter__:ƒ __defineSetter__()__lookupGetter__:ƒ __lookupGetter__()__lookupSetter__:ƒ __lookupSetter__()get __proto__:ƒ __proto__()set __proto__:ƒ __proto__()&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 21:46:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180565#M80381</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-18T21:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180566#M80382</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt;, thank for your help in this topic. It really helped me. Now I am trying to submit a code from a textarea,&lt;/P&gt;&lt;P&gt;I succeded to send a simple code of operations, for example 5+7, 8-7,789/0, 47*7. The problem is when the user wants to submit a huge code with many strings, how can we get that automatically and send it to the apache livy server? In other words, how can I change this line : &lt;STRONG&gt;"data":"{\"code\": \"1 + 1\"}"&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;This is what I did &lt;STRONG&gt;"data": "{\"code\": \""+code+"\"}", &lt;/STRONG&gt;but i works only for operations!&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 19:24:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180566#M80382</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-19T19:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180567#M80383</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/87152/ndumelchipaul2000.html" nodeid="87152"&gt;@Melchicédec NDUWAYO&lt;/A&gt; you will probably need to escape quotes in the strings (or try using single quotes instead) so that it wont break the javascript. If you agree lets discuss this in different thread as it seems to be specific to running code with strings now and the initial question has been addressed. &lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 19:49:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180567#M80383</guid>
      <dc:creator>falbani</dc:creator>
      <dc:date>2018-07-19T19:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: apache livy and ajax post requests: Method Not Allowed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180568#M80384</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/11048/falbani.html" nodeid="11048"&gt;@Felix Albani&lt;/A&gt;&lt;P&gt;, so I have to create another thread for this or you you will create it?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 19:51:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-livy-and-ajax-post-requests-Method-Not-Allowed/m-p/180568#M80384</guid>
      <dc:creator>ndumelchipaul20</dc:creator>
      <dc:date>2018-07-19T19:51:19Z</dc:date>
    </item>
  </channel>
</rss>

