AnsweredAssumed Answered

How to setup a Service Task class via El Expression

Question asked by asdfg195 on Nov 5, 2015
Latest reply on Nov 6, 2015 by asdfg195
I am using Activiti 5.18.0.  My process has a slightly complicated error handling that needs to go around every Service Task. Instead of replicating that everywhere, I want to create a subprocess that does the error handling around a simple Service Task. I am passing in the fully qualified Class name using the input parameters of a Call Activity to create a process variable 'taskClass'. I have verified that the variable is being set correctly with the fully qualified class name.

I created a test Class for the purpose of this experiment. The code is as below.

//package statement

import java.io.Serializable;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogTask implements Serializable,JavaDelegate {
    private static final long serialVersionUID = -6489042542454599211L;
    private static final Logger LOG = LoggerFactory.getLogger(LogTask.class);

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        LOG.info("Hello World");
    }
}

My original attempt was to see if I could use the EL expression for the class name

<serviceTask id="servicetask1" name="Service Task" activiti:class="#{taskClass}"></serviceTask>

That yields the following error

java.lang.ClassNotFoundException: #{taskClass}

So it looks like the class option will not resolve from the process variable. My next thought was to try using a delegate expression. I updated my process to the following

<serviceTask id="servicetask1" name="Service Task" activiti:delegateExpression="#{taskClass}"></serviceTask>
I got the following error while trying to run the service task

Caused by: org.activiti.engine.ActivitiIllegalArgumentException: Delegate expression #{taskClass} did neither resolve to an implementation of interface org.activiti.engine.impl.pvm.delegate.ActivityBehavior nor interface org.activiti.engine.delegate.JavaDelegate

My class implements JavaDelegate so I'm guessing that the delegate expression does not resolve from process variable. Does anyone know a way in which I can make this work because it would vastly simplify my process? I am using the programmatic configuration since my lead does not like Spring and therefore, I cannot rely on any Spring mechanisms.

Outcomes