cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically create a Process which has a ServiceTask calling my Java Service

viggo_navarsete
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to extend on the example found here: http://stacktrace.be/blog/2013/03/dynamic-process-creation-and-deployment-in-100-lines/

I have made my own service, MyService which implements the JavaDelegate interface. Currently I'm only doing a System.out.println from this class, but I'm trying to call it from a programatically made ServiceTask which is added to the Process. Code example with error output can be found here:
http://pastie.org/private/0ztlandefvdhw710exltw

Thanks in advanceSmiley Happy
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
Have you tried to use the line below (and leave out the setType()):

serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
Also, make sure you add a sequence-flow from task2 to serviceTask and one from serviceTask to end, to make sure the process-flow includes the service-task…

viggo_navarsete
Champ in-the-making
Champ in-the-making
Thanks for update! It certainly helped using the setImplementationType the way you described, I also missed the wiring you noted. BUT, now when I run the test, it runs green, the generated PNG contains all three tasks, BUT in my class implementing the JavaDelegate I both log a message and throw a UnsupportedOperation, but nothing fails, and nothing is logged, which makes me believe it's not called at all!

public class MyJavaService implements JavaDelegate {

    private static final Logger logger = LoggerFactory.getLogger(MyJavaService.class);
   
    @Override
    public void execute(DelegateExecution de) throws Exception {
        logger.info("CALLING MyJavaService");       
        throw new UnsupportedOperationException("Not supported yet.");
    }
   
}

Any clue?

Here is the unit test I run: http://pastie.org/private/hcfkouxlulvaeos7nxr2xa

viggo_navarsete
Champ in-the-making
Champ in-the-making
I also tried to change the value of the serviceTask.setImplementation to something crap (not a valid package+class name) and I got no issues, so the process doesn't seem to care about it at allSmiley Happy

viggo_navarsete
Champ in-the-making
Champ in-the-making
I realized that since the two first tasks were user tasks, they probably need some user interaction(!) in order for the process to go from task 1 to task 2, and hence the third task which I added (a ServiceTask) would never be called/executed!
So, I switched the order of the tasks so that the ServiceTask was the first one, and it was calledSmiley Happy

I consider this question as answered! (but, is it possible to simulate user interaction programatically as well? Maybe not a valid use case for it, but just curious..)

frederikherema1
Star Contributor
Star Contributor
Sure, use the TaskService to query for taks (createTaskQuery()) and complete them (or any other action you might want to do). I suggest you do a quick read through the Javadocs of our services, so you get an overview of the possibilities of the API…