Calling REST Webservice (HTTP GET)
I'm trying to use a currency converter in Xpert.ivy: http://rate-exchange.appspot.com. This service is called like this: [http://rate-exchange.appspot.com/currency?from=EUR&to=CHF][1] http://rate-exchange.appspot.com/currency?from=EUR&to=CHF and gives a response like this: {"to": "CHF", "rate": 1.2223900000000001, "from": "EUR"}.
I would like this to call in a script step. So far I tried the method described in [http://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.html][2]:http://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.html:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://rate-exchange.appspot.com/currency?from=EUR&to=CHF");
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
out.SOME_STRING_DATATYPE = line;
}
At execution this throws an error in line 'HttpResponse response = client.execute(request);'
Is there a better method to use a REST webservice from within Xpert.ivy?
[1]: http://rate-exchange.appspot.com/currency?from=EUR&to=CHF
[2]: http://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.htmlXpert.ivy?