-
1. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
salaboy21 May 26, 2013 7:42 PM (in response to gmlopezdev)1 of 1 people found this helpfulHi Guillermo L,
I usually don't recommend using script tasks at all unless you are doing a proof of concept or something really simple. It's is usually a bad practice to embed java code inside an xml file, but the bpmn2 specification allows it.
In jBPM6 we are making a huge effort to support CDI in all the framework, but in jBPM5.4 you can use it as well, you will need to do more work for sure. About service tasks, it shoudn't be so hard you can just implement a WorkItemHandler that access the CDI container to get the bean that you want.
Cheers
-
2. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
vchmakov May 27, 2013 10:58 AM (in response to salaboy21)Hi Mauricio,
Then what do you recommend instead of script tasks? What is the best practice in your opinion?
Thanks,
Vladimir
-
3. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
gmlopezdev May 27, 2013 7:07 PM (in response to salaboy21)Hi Mauricio,
I do not personally like programming within XMLs and that's why I was looking forward another way to get my code out of these scripts by getting CDI components from them where my java code could be located, since they appear to be the way to implementa automatic tasks :-(.
I'm a BPM and jBPM beginner so as Vladimir I'd like to get your recommendation for automatic tasks implementation. Service tasks appear to have been specified for other purposes but should we use them instead of script tasks? Other alternatives?
I'd appreciate some more insight you may provide regarding this subject.
Thanks,
Guillermo
-
4. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
vchmakov May 27, 2013 9:44 PM (in response to salaboy21)1 of 1 people found this helpfulHi Mauricio,
I found answer to my question in “jBPM5 Developer Guide” book on page 143:
“Business users do not commonly use script tasks, but they are really helpful for technical people. By adding script tasks to a process we can easily modify the behavior of our processes without modifying any Java class. We can use this type of task to add logs, messages, or to perform data transformation tasks in our processes. As a rule of thumb, script tasks shouldn’t contain business logic inside them. Abstract tasks, human tasks, and service tasks are better place to implement this kind of logic.”
In our company we usually implement the business logic in plain classes and call methods from the script tasks.
Thanks,
Vladimir
-
5. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
gmlopezdev May 27, 2013 10:40 PM (in response to vchmakov)Thanks for your response Vladimir!
I've also found a thread from Esteban here and he does not recommend using script tasks.
I understand that under some scenarios a script task might be an option, however I'm integrating jBPM within JEE 6 and my beans are CDI beans so I need to get references to them through the container. As per what I have read so far, it appears that Task or Service Task might be my alternatives since I can inject and bind the work item handlers into the session however I'd like to know the difference between both (Task vs ServiceTask).
Thanks again for sharing your experience!
-
6. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
vchmakov May 28, 2013 10:46 AM (in response to gmlopezdev)Hi Guillermo L,
We do as well integrate jBPM with JEE6 and run it under JBoss AS 7. We have a set of services which we instantiate at startup and then pass into jBPM engine as a global variable. It is not strictly speaking necessary, though, as the service set container is a singleton and can be accessed from any participating class. One of the services is a persistence service. We receive commands via MDB. There is an injection point in the MDB for the persistence context. Every time a command is invoked we pass the injected instance to our persistence service and to the Drools/jBPM engine to make them participate in the container’s transaction. I guess that the similar approach can be used in your case as well with your CDI beans.
Thanks,
Vladimir
-
7. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
gmlopezdev May 28, 2013 11:04 AM (in response to vchmakov)I can now understand your approach and appears to be good for me. I'm running jBPM within a similar environment (JEE 6/JBoss 7). I guess my CDI beans can be injected as you did with your components as global variables and then invoke their functions from a script task avoiding writing java code within XMLs.
Going back to tasks; do you know what is the actual difference between Tasks and Service Tasks?
Thanks again for sharing your valuable experience!
-
8. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
vchmakov May 28, 2013 11:28 AM (in response to gmlopezdev)Based on what I understood from reading of the “jBPM5 Developer Guide” book Service Task is designed for integrating when you run within SOA implementation. The main parameters are Interface and Operation. Operation is a method on the Interface to be invoked. The Abstract Task is an extension point where you define what object you wish to call and bind it via Task Name. The Task Name is used when you register a handler for your task.
Hope this helps. Someone may want to correct me if I’m wrong.
Thanks,
Vladimir
-
9. Re: Is it possible to integrate CDI beans into script and service tasks within jBPM 5.4?
salaboy21 May 28, 2013 12:18 PM (in response to vchmakov)Vladimir you are correct. I'm happy to see that the book is helping.
I usually recommend using "Abstract Tasks" or just Task and a work item handler implementation associated to it to implement custom logic. Even using the script task for calling your own java classes is a bad and error prone practice in my experience. Services tasks are more SOA oriented as Vladimir mention but as far as I remember they can be also used to call a method in a bean as well.. so you can try that if you don't want to write your WorkItemHandler implementation..
Cheers