<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Calling REST Webservice (HTTP GET)</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get</link><description>&lt;pre&gt;&lt;code&gt;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&amp;amp;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:

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&amp;amp;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;
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At execution this throws an error in line 'HttpResponse response = client.execute(request);'&lt;/p&gt;
&lt;p&gt;Is there a better method to use a REST webservice from within Xpert.ivy?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get" rel="self"></atom:link><language>en</language><lastBuildDate>Sat, 13 Aug 2016 02:52:17 -0400</lastBuildDate><item><title>Comment by Helmut Burgemeister on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1961</link><description>&lt;p&gt;In Ivy 6.0 and higher there is already Jersey 2 included!
Therefore the examples here with Jersey 1 does not work.
On Designer it works, but on Server you get the mentioned error about the media-types missing. The error can occur in different forms.
Solution is to use the Jersey 2 libs directly. So it works on the server also.
See the site for migration or the Ivy 6.2 Example-project "Connectivity Demo".
Site:
&lt;a href="https://jersey.java.net/documentation/latest/migration.html#mig-1.x"&gt;https://jersey.java.net/documentation/latest/migration.html#mig-1.x&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Helmut Burgemeister</dc:creator><pubDate>Sat, 13 Aug 2016 02:52:17 -0400</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1961</guid></item><item><title>Comment by Reguel Wermelinger on beatjost's answer</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1467</link><description>&lt;p&gt;This is a new question, so i'll delete it. But the answer is here: &lt;a href="http://answers.axonivy.com/questions/1453/can-i-expose-api-as-rest-service"&gt;http://answers.axonivy.com/questions/1453/can-i-expose-api-as-rest-service&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 08 Sep 2015 16:02:29 -0400</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1467</guid></item><item><title>Comment by Reguel Wermelinger on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1010</link><description>&lt;p&gt;I guess that your class loading issue can be solved by using a specific context-classLoader as described here: &lt;a href="http://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query/948"&gt;http://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query/948&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 17 Oct 2014 10:23:43 -0400</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#1010</guid></item><item><title>Comment by DanielGauch on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#998</link><description>&lt;p&gt;Hi Reto. Unfortunately it seems that this solution doesn't work anymore with Axon.ivy Engine 5.1.0. I tried adding the jars to my project and I also tried the RestFulWebService.iar from the other post. Both work in the Designer, but in the Engine I get an exception "java.lang.NoClassDefFoundError: Could not initialize class com.sun.jersey.core.header.MediaTypes". As soon as I add the jersey jars to the servers lib/shared folder it works again (but that's not a clean solution). Seems to be a ClassLoader/Isolation issue. Any ideas or hints?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DanielGauch</dc:creator><pubDate>Mon, 13 Oct 2014 13:08:03 -0400</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get#998</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get/539</link><description>&lt;p&gt;&lt;strong&gt;REST is supported by Axon.ivy since 6.1 out of the box.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Axon.ivy Designer comes with a sample project called 'ConnectivityDemos' where the REST capabilities are demonstrated.&lt;/p&gt;
&lt;p&gt;See also the documentation about how to provide or call a REST service from Axon.ivy:
&lt;a href="http://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.integration.html#ivy-integration-rest"&gt;http://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.integration.html#ivy-integration-rest&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;For Axon.ivy 6.0 and older&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately REST Web Services are not supported by default yet. &lt;/p&gt;
&lt;p&gt;But you can use a JAX-RS client library like &lt;a href="https://jersey.java.net/"&gt;Jersey&lt;/a&gt; to call REST Web Services. To do this, simple add the needed jersey libraries (.jar files) to your project. Then add the jar files to the Java Classpath (Switch to Java perspective. Select the jar file and use the context menu &lt;em&gt;Build Path &amp;gt; Add to Build Path&lt;/em&gt;). &lt;/p&gt;
&lt;p&gt;After that you can access the classes provided by the library from your own java classes but also from ivyScript. See Jersey user documentation chapter &lt;a href="https://jersey.java.net/documentation/latest/client.html"&gt;Client API&lt;/a&gt;  to learn how to use it.&lt;/p&gt;
&lt;p&gt;Sample project which makes a google search via Rest API: &lt;a href="http://www.ivyteam.ch/demo/RestFulWebService.iar"&gt;RestFulWebService.iar&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 20 Feb 2014 09:11:16 -0500</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get/539</guid></item></channel></rss>