Esteban Robles Luna on Thursday, February 17, 2011

Activiti + Mule ESB – Part 2

5

In the first part of this post we show how to start an Activiti process from Mule ESB using the new Mule’s activiti module. In this part we are going to show how to call a Web Service from Activiti that is going to be contained in Mule. Notice that you can expose anything as a Web service in Mule such as: beans, queues, etc.

Activiti configuration

First of all we need to create our proces. It will receive a request containing the username that has requested the image and the image name. The process will work as follows: check if the image needs copyright; if it needs copyright then allow the owner to approve or disapprove the request. If the request is approved, then charge the requester otherwise cancel it. In case that the image doesn’t need approval, just charge the requester with the cost.

The following process definition follows the logic described above (Fig. 1):

Fig. 1. Picture request process definition

Fig. 1. Picture request process definition

The process definition uses 2 delegates to check whether an image has copyright and to call the Web service in Mule. In the first case we have created the following simplified Java class for it:

The other Java delegate calls the Web service in Mule (using the approach presented by Bernd as Activiti doesn’t support calls to web services yet). Next we outline the class:

You need to deploy the following 2 classes as explained in the User guide by copying the jar to ${activiti distro}/apps/apache-tomcat-6.0.29/webapps/activiti-rest/lib/. You can download the project for the extensions from here; the project is under the activiti-extensions directory.

Finally, we need to upgrade our form to allow the user to approve or disapprove the request using a select element as shown next:

We are almost done with Activiti; just delete the previous version of the definitions and upload the new version using Activiti-probe (the new definitions are under the activiti-picture-example directory). Next we will show how to create the Web service in the Mule side.

Mule configuration

Now all we need to do is extend the previous Mule configuration from part 1 and add a new flow exposing the Web service.

We have also added some ajax configuration so that we can notify our user when the request has been approved (either automatically or manually). You can see a picture of the notification of Fig. 2.

Fig. 2. Picture request approved

Fig. 2. Picture request approved

As it’s an exemplar application we implement the following stub Web service to check everything works as expected by just returning the image name that will be push to the ajax channel:

You can download the complete Mule project here and browse the source here.  You can start the project by setting your MULE_HOME variable and running mvn clean install from the root of the project; the application will be available at: http://localhost:8999/. Also, don’t forget to publish the Activiti deployment zip file under the activiti-picture-example directory.

Don’t have time to deploy it? Try this short video:

Hope you like this post and I’m looking forward to your comments.

No related posts.


5 Responses to “Activiti + Mule ESB – Part 2”

Rainer February 18th, 2011, 11:00 am

Hi Esteban,

thanks for your cool samples. I tried to get them to work with Activiti 5.2 but it failed.
I deployed the process via activiti-probe,
I copied the picture-request-activit.jar to the activiti-rest/web-inf/lib folder and finally
I deployed the file picture-1.0-SNAPSHOT.zip to mule

I start Activiti and Mule and then I go to the Sample Application (localhost:8999), I choose one
picture and click the Request image button -> I get an error in the tomcat log.
The Process Definition can’t be found with the given ID=pictureRequest:1, I saw in the database tables
that since Activiti 5.2 the ID has another number after the version 1, in my case it is pictureRequest:1:113.
In Activiti 5.0 and 5.1 it was still pictureRequest:1.
I also tried the versions 5.0 and 5.1 but I get the same error. I only use the H2 database, perhaps this is
the problem.

Which configuration did you use (Activiti version, database)?

Regards,
Rainer.

18.02.2011 08:23:00 org.activiti.engine.impl.interceptor.CommandContext close
SCHWERWIEGEND: Error while closing command context
org.activiti.engine.ActivitiException: no deployed process definition found with id ‘{imageName=mule1.jpg, user=mulee, processDefinitionId=pictureRequest:1}’
at org.activiti.engine.impl.db.DbRepositorySession.findDeployedProcessDefinitionById(DbRepositorySession.java:181)
at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:47)
at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:29)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:22)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:37)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:69)
at org.activiti.rest.api.process.ProcessInstancePost.executeWebScript(ProcessInstancePost.java:49)
at org.activiti.rest.util.ActivitiWebScript.executeImpl(ActivitiWebScript.java:68)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
at org.springframework.extensions.webscripts.PresentationContainer.executeScript(PresentationContainer.java:69)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

Esteban Robles Luna February 21st, 2011, 5:04 am

Hi Rainer,
It’s good to hear that you tried the example. I have to mentioned that I tested it with Activiti 5.0/5.1 so you will have to modify your mule config to set the right process definition id.
Check the first part of this post and change:

map.put(“processDefinitionId”, “pictureRequest:1″) //the id of the definition

to:

map.put(“processDefinitionId”, “pictureRequest:1:113″) //the id of the definition

It shouldn’t be a problem of the database. I tried it with the demo.setup ant task.
Thanks
Esteban

Rainer February 21st, 2011, 11:57 am

Hi Esteban,

thanks for your answer. Example works great now ;-) )
It was my failure. I deployed the wrong project to mule. I took mule-transport-activiti.jar instead of mule-module-activiti-3.1.0.jar.

Thanks for this excellent job,
Rainer.

Atif August 29th, 2011, 6:10 pm

Hi, Thanks for this very nice post !
I have flowed all the steps but i am getting this error while Kermit is trying to complete the task ! :

Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier ‘approvalConfirmed’

am i missing something ?

Jovan February 16th, 2012, 8:12 am

Hi Esteban,
very nice post but it should be updated to the latest versions.
In the meantime both Mule and Activiti versions has been changed that implies pom.xml, mule flows, activiti forms etc modifications.
I spent some days to fix those problems and finally I got it running with mule 3.2.1 and activiti 5.8.

So at this point I don’t understand if this combination of technologies should be used for a real project. From theoretical point of view, the architecture make sense but in practice it seems a nightmare to develop and manage an application that is stable and running.

What do you think? Which are the benefits to use those technologies in a real project? I read the posts that you mentioned at the beginning but they explain the benefits only from theoretical point of view.

Regards
jovan

Leave a Comment