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 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&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?

asked 18.02.2014 at 17:52

Bj%C3%B6rn's gravatar image

Björn
(suspended)
accept rate: 100%

edited 20.02.2014 at 10:53

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
(suspended)


REST is supported by Axon.ivy since 6.1 out of the box.

The Axon.ivy Designer comes with a sample project called 'ConnectivityDemos' where the REST capabilities are demonstrated.

See also the documentation about how to provide or call a REST service from Axon.ivy: http://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.integration.html#ivy-integration-rest


For Axon.ivy 6.0 and older

Unfortunately REST Web Services are not supported by default yet.

But you can use a JAX-RS client library like Jersey 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 Build Path > Add to Build Path).

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 Client API to learn how to use it.

Sample project which makes a google search via Rest API: RestFulWebService.iar

link
This answer is marked "community wiki".

answered 20.02.2014 at 09:11

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k202857
accept rate: 74%

edited 14.11.2016 at 09:10

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958

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?

(13.10.2014 at 13:08) DanielGauch DanielGauch's gravatar image

I guess that your class loading issue can be solved by using a specific context-classLoader as described here: http://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query/948

(17.10.2014 at 10:23) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

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: https://jersey.java.net/documentation/latest/migration.html#mig-1.x

(13.08.2016 at 02:52) Helmut Burge... Helmut%20Burgemeister's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×33

Asked: 18.02.2014 at 17:52

Seen: 7,601 times

Last updated: 14.11.2016 at 09:13