0

is there any way to make an HTTP request inside a Zeppelin paragraph? e.g.

    function get_app_name(){

    //var xmlHttp = new XMLHttpRequest();
    //xmlHttp.open( "GET", "https://example.com/application/key", true, 'username', 'password');
    //xmlHttp.send( null );

    URL url = new URL("https://example.com/application/key");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("GET");
}

I cannot import any of the resources (e.g. URL) because the interpreter doesn't allow it (mongodb interpreter). Is there any way to make a simple GET request in Zeppelin? I'm trying to fetch data for my tables that is not in the specified db as the other elements.

Roxana Tapia
  • 115
  • 9
  • You could use the shell interpreter to do curl requests. You're currently mixing Javascript function definitions and Java classes, so not clear what you're expecting. The Mongo shell interpreter documentation is https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/ – OneCricketeer Apr 04 '18 at 13:05
  • Thanks, I'll check that. The commented lines are JS code that also didn't work. I got quite confused about if mongodb interpreter supports java or JS classes, but neither work so I'll go for a different approach. The thing is, the rest of the data relies on mongodb interpretations, and I cannot use multiple interpreters in a paragraph.. Also many interpreters don't allow sharing global variables as here https://stackoverflow.com/questions/40298155/is-it-possible-to-set-global-variables-in-a-zeppelin-notebook . The curl request should work but I'm afraid I'll need to change all mongo queries :( – Roxana Tapia Apr 04 '18 at 13:14
  • Don't allow sharing? The answer there seems to say that you can... Anyways, I would suggest using the Spark interpreter with a Spark Mongo connector – OneCricketeer Apr 04 '18 at 13:17
  • Not in mongodb interpreter or python. I'm flexible with the second interpreter (python) but if it doesn't communicate with mongo interpreter it's useless :( ... it works with spark and pyspark – Roxana Tapia Apr 04 '18 at 13:20

1 Answers1

0

From HTTP request inside MongoDB

%mongodb

function wget(url){
    var tmp = "/tmp";
    var id = new ObjectId();
    var outFile= tmp+"/wget"+id;
    var p = run("wget", "--user=user", "--password=password", "-o log", "--output-document="+outFile,url);
    if (p==0){
        var result = cat(outFile);
        removeFile(outFile);
        return result;
    } else {
        return "";
    }
}

url = "https://exampleurl.com/resource"
result = wget(url)
print(result)
Roxana Tapia
  • 115
  • 9