How to call an external REST Service from Activiti in Alfresco 4.1?

Showing results for 
Search instead for 
Did you mean: 
Member II

How to call an external REST Service from Activiti in Alfresco 4.1?


I have tried to find examples that describe how to call an external REST service from an automated task in Activiti that is embedded in Alfresco 4.1. 

Here is the use case:
1) Start an Activiti workflow
2) collect metadata from several user tasks and store in the workflow instance
3) invoke and a web service that has an endpoint on a non-Alfresco server to do some work (passing the metadata collected from the user tasks)
4) branch the workflow based on success or failure of the external service call
5) If success end the workflow, if failure route to a user to inform them of the service failure

Any help would be greatly appreciated
2 Replies
Established Member

Re: How to call an external REST Service from Activiti in Alfresco 4.1?

Hi jtomonto,

Activiti at its heart is basically a big Java app, so it's easy to use standard Java libraries for doing heavy lifting, once you wire up up the workflow related stuff. So from an activiti workflow task, you'll need to be using a TaskListener, an ExecutionListener or ServiceTask, depending on where in your workflow is most suitable for the event to happen (i.e. when you arrive in or leave a user task, when you take a specific execution path out of a task or whether you want a dedicated task in the workflow for this background processing). You can use either plain Java objects or Spring-based delegates for the implementation as long as they implement the relevant interface (org.activiti.engine.delegate.JavaDelegate, org.activiti.engine.delegate.TaskListener or org.activiti.engine.delegate.ExecutionListener).  The standard UI for creating workflows will let you define any of these options pretty easily and allow you to point at a Java class to do the actual work.

In your implementation of the service task/listener you can then use basic, plain old Java code & libraries to send out a HTTP message directly (e.g. Apache HTTP Client) or use a REST library like the Java standard JAX-RS or Spring Boot or whatever your preferred REST client library is.  You just need to make sure that you package any libraries that are not part of the core Alfresco code along with your custom workflow amp.  It can then modify the executionScope of the workflow afterwards with the result of the call, so that you can use a Gateway to act as a decision point in the workflow based on the result of the call.

In the case you're outlining, possibly a service task is most appropriate as it seems like a discrete task within the workflow rather than a side effect and will give me more power over doing specific error handling within the BPMN like using Timers, or error event listeners etc. if you need to.


Member II

Re: How to call an external REST Service from Activiti in Alfresco 4.1?

Hello, were you able to successfully call the external REST service via HTTP in Activiti?