cancel
Showing results for 
Search instead for 
Did you mean: 

a task calls a REST web service and makes the result available to other tasks

forschungsstude
Champ in-the-making
Champ in-the-making
hello,
I use Activiti 5.17, Apache Maven 3.3.3, Apache Tomcat 7.0.62 and jdk 1.8.0_45-b15.

My goal is to create a task which calls my own REST-Webservice to receive a simple PIN (4 digits). The next task should wait until the PIN is received. This is the link to my REST-Webservice returning the PIN: http://wwwlab.cs.univie.ac.at/~a0904202/rest/random.php/TXTPIN (IN JSON: wwwlab.cs.univie.ac.at/~a0904202/rest/random.php/PIN)

I found a description in the Activiti userguide ("8.5.7 Mule Task"). → Is this the solution of my problem?
So I create at Activiti-Explorer → "Processes" → "Model workspace" a "New model", with a "Mule task" and a "User task".
When I deploy the model the error message "Create of BPMN XML failed. Could not find org.activiti.mule. MuleSendActivitiBehavior" appears.
What do I need to do to make it work?

I found a youtube video "Activiti REST Call task demonstration" (https://www.youtube.com/watch? v=x7YCHYCIxpM) where the user has a "rest call task" but I dont have this task in my Activitit Explorer (Alfresco Acitiviti Modeler). Also I cannot define the endpoints as explained in the video as well.

Does somebody have an idea or even an example/instruction on how a task calls a REST web service and makes the result available to other tasks?

Thanks a lot.

Regards.
Sabine


I hope I describe my problem understandable. English is not my first language.
7 REPLIES 7

vasile_dirla
Star Contributor
Star Contributor
Hi,
1. you could use a ServiceTask with a delegate class and inside this class you do the web service call and then put the result on the flow as a variable.

2. related to the mule class not found you have to be sure you have the activti-mule.jar in the classpath.

maudrid
Champ on-the-rise
Champ on-the-rise
I have also solved this problem by using a script task combined with unirest for java.
This is for activiti 6:
<code>
/*
* Javascript
* http://unirest.io/
* Hint: Use maven to download all the required jar files. Place them in the webapps/activiti-app/WEB-INF/lib.
* mvn dependency:resolve
*/

var objectvar = {};
objectvar.name='my name';
objectvar.subobj = {};
objectvar.subobj.testprop = 'test';

var Unirest = Java.type('com.mashape.unirest.http.Unirest');

var response = Unirest.post("http://httpbin.org/post").body(JSON.stringify(objectvar)).asJson();
var body = response.getBody().toString();
execution.setVariable('fullJSON', body);
var bodyObj = JSON.parse(body);
execution.setVariable('MyIp',bodyObj.origin);

/* Another example

var response = Unirest.post("http://httpbin.org/post")
  .header("accept", "application/json")
  .queryString("apiKey", "123")
  .field("parameter", "value")
  .field("foo", "bar")
  .asJson();
 
  */
</code>

hello,
thanks for your help.

"This is for activiti 6" stand for "activiti-6.0.0.Beta2.zip"  or?

Regards,
Sabine

maudrid
Champ on-the-rise
Champ on-the-rise
Yes I am using Beta 2, but it may also work in older activiti 5.
The script will probably not work as is on Java older that java 8, because the scripting engine is Nashorn and not Rhino.

hello,

thanx.
Now I use Activiti 6.0.0.Beta2 and apache-tomcat-8.0.32.

I try –> http://localhost:8080/activiti-app (login: admin@app.activiti.com / test) –> "Identity Management" but there is no "Tenants".
So I cannot define the endpoints as explained in the video "https://www.youtube.com/watch?v=x7YCHYCIxpM".

Any ideas why "Tenants" is missing?

Thank your for your help.

Regards,
Sabine

jbarrez
Star Contributor
Star Contributor
You are mixing up the Activiti open source UI and the commercial offering by Alfresco. The video is the latter and is different from the one in OSS.

forschungsstude
Champ in-the-making
Champ in-the-making
Hello,

thanx for the information.
I hope creating a REST Webservice can also easy create at Acitivit 5.19.0.2.

Regards,
Sabine
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.