cancel
Showing results for 
Search instead for 
Did you mean: 

Calling REST from activiti task

vahaj
Champ in-the-making
Champ in-the-making
Please confirm if the below scenario is possible..

I want to call REST based webservice through service task and wants to pass the return result of REST to drool file, is it possible that I can do it with no java code? Means I don't have to call REST service in Java delegate class and pass returned results from java class.

Is it also possible that I can call REST service from script task and pass the result of REST to drool file?
2 REPLIES 2

vahaj
Champ in-the-making
Champ in-the-making
If I sum up my above requirements than I would say is it possible to call REST based webservices in activiti work flow with out using java code?

If Yes than please share any working example of it, or in which task element I can do it?

vasile_dirla
Star Contributor
Star Contributor
Hi,
sorry I ask you directly but, what's wrong using java ? Smiley Happy

There are a few solutions but in my point of view the ServiceTask is the best way.
Anyway, the other solutions i'm thinking of, the ScriptTask is involved:
1. groovy scripting
<java>
  import groovy.json.*

def url = "http://www.mocky.io/v2/55a18e8fd66d56fe140e9356'.toURL().text
def root = new JsonSlurper().parseText(url)

root.each() { elem ->
    println "${elem.name}"
}
</java>

note that you could use the groovyx.net.http.RESTClient which is maybe a better solution.

2. javascript (fyi: Activiti is using Rhino javascript engine so you could study it to see what exactly you are allowed to do with it.)
here is an example of Rhino script for getting the content from an url.
<javascript>
function fetch(urlStr) {
  importPackage(java.io, java.net);

  var url = new URL(urlStr);
  var urlStream = url.openStream();
  var reader = new BufferedReader(new InputStreamReader(urlStream, "latin1"));

  var html = "";
  var line;
  while (line = reader.readLine()) {
   if (line == null) break;
   html += line;
  }
  return html;
}
</javascript>

Just let your imagination fly  Smiley Happy
you could use Apache HttpClient which fits better for such a task.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.