3

I would like to write a JavaScript code processed with Mozilla Rhino that can do a simple HTTP GET request, which fetches a text string from a URL. The problem is that, I couldn't find any support in Rhino to do any kind of HTTP requests. Besides, I don't have access to the Rhino instance itself, it's running via TopBraid Composer IDE for ontology modelling. I believe any idea about a simple library that I can import within my JavaScript file maybe a good solution.

Any help? Thanks.

Ahmed Emad
  • 619
  • 10
  • 23
  • If you're using TopBraid, why not use their various REST services - SPIN templates, SPARQLMotion, SWP all have REST services built in. – scotthenninger Mar 10 '16 at 15:13

1 Answers1

6

Okay, so it wasn't that difficult to figure it out. This one works via TopBraid Composer and without importing any JAVA libraries. Here's the answer in case anyone needs it later on.

var resourceURL = new java.net.URL(
        'http://someurl');
var urlConnection = resourceURL.openConnection();
var inputStream = new java.io.InputStreamReader(urlConnection
        .getInputStream());
var bufferedReader = new java.io.BufferedReader(inputStream);
var inputLine = bufferedReader.readLine();
bufferedReader.close();
var jsString = String(inputLine);
return jsString;
Ahmed Emad
  • 619
  • 10
  • 23