AnsweredAssumed Answered

CDI Injection for JavaDelegate + Programmatic Config

Question asked by maikelnait on Mar 30, 2016
Hi all.

I'm facing a problem similar to these old threads:
https://forums.activiti.org/content/activiti-cdi-injection-javadelegate#p15043
https://forums.activiti.org/content/cdi-injection-javadelegate

In my case, I'm trying to setup an Activiti Embedded CDI enabled Engine:
- Using the CdiStandaloneProcessEngineConfiguration  ( no need for JTA so far )
- Inside an EAR package deployed in WildFly 8.2.0.Final
- Using Activiti v5.19.0.2

My customized ProcessEngineLookup, using an in-memory H2 database for testing purposes, looks like this:


import org.activiti.cdi.CdiStandaloneProcessEngineConfiguration;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;

public class AtmcEngineLookup implements org.activiti.cdi.spi.ProcessEngineLookup {
 
  @Override
  public int getPrecedence() {
    return 10;
  }

  protected String processEngineName = ProcessEngines.NAME_DEFAULT;
  protected ProcessEngine atmcProcessEngine;

  @Override
  public ProcessEngine getProcessEngine() {
    
     atmcProcessEngine = new CdiStandaloneProcessEngineConfiguration()
           .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP)
           .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
           .setAsyncExecutorEnabled(true)
           .setAsyncExecutorActivate(false)
           .buildProcessEngine();
                           System.out.print("================ ");
                           System.out.print("CdiStandaloneProcessEngineConfiguration used for ");
                           System.out.print("populating the CDI ACTIVITI ENGINE");                      
                           System.out.print(" ================");
     return atmcProcessEngine;
  }

  public String getProcessEngineName() {
    return processEngineName;
  }

  public void setProcessEngineName(String processEngineName) {
    this.processEngineName = processEngineName;
  }

  @Override
  public void ungetProcessEngine() {
    try {
       atmcProcessEngine.close();
       atmcProcessEngine = null;
    } catch (Exception e) {
      throw new ActivitiException("Unable to close the local ProcessEngine", e);
    }
  }
}

I have the /META-INF/services/org.activiti.cdi.spi.ProcessEngineLookup correctly pointing to my ProcessEngineLookup class.

The application starts up without any problems, as we can see from the server logs, and our BPM processes are deployed correctly.

14:29:59,970 INFO  [org.activiti.cdi.impl.ActivitiExtension] (MSC service thread 1-5) Initializing activiti-cdi.
14:30:00,181 ERROR [stderr] (MSC service thread 1-5) ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.sun.script.javascript.RhinoScriptEngineFactory not found

14:30:00,776 INFO  [org.activiti.engine.impl.db.DbSqlSession] (MSC service thread 1-5) performing create on engine with resource org/activiti/db/create/activiti.h2.create.engine.sql
14:30:00,807 INFO  [org.activiti.engine.impl.db.DbSqlSession] (MSC service thread 1-5) performing create on history with resource org/activiti/db/create/activiti.h2.create.history.sql
14:30:00,812 INFO  [org.activiti.engine.impl.db.DbSqlSession] (MSC service thread 1-5) performing create on identity with resource org/activiti/db/create/activiti.h2.create.identity.sql
14:30:00,815 INFO  [org.activiti.engine.impl.ProcessEngineImpl] (MSC service thread 1-5) ProcessEngine default created
14:30:00,819 INFO  [stdout] (MSC service thread 1-5) ================ CdiStandaloneProcessEngineConfiguration  used for populating the CDI ACTIVITI ENGINE ============

14:30:00,841 INFO  [org.activiti.cdi.impl.ProcessDeployer] (MSC service thread 1-5) Adding 'activiti-flows/IdleLoop.bpmn' to deployment.
14:30:00,843 INFO  [org.activiti.cdi.impl.ProcessDeployer] (MSC service thread 1-5) Adding 'activiti-flows/MainFlow.bpmn' to deployment.
14:30:00,843 INFO  [org.activiti.cdi.impl.ProcessDeployer] (MSC service thread 1-5) Adding 'activiti-flows/StartUp.bpmn' to deployment.
14:30:00,844 INFO  [org.activiti.cdi.impl.ProcessDeployer] (MSC service thread 1-5) Adding 'activiti-flows/INQ.bpmn' to deployment.
14:30:00,845 INFO  [org.activiti.cdi.impl.ProcessDeployer] (MSC service thread 1-5) Adding 'activiti-flows/testFlow.bpmn20.xml' to deployment.
14:30:00,859 INFO  [org.activiti.engine.impl.bpmn.deployer.BpmnDeployer] (MSC service thread 1-5) Processing resource activiti-flows/IdleLoop.bpmn
14:30:01,212 INFO  [org.activiti.engine.impl.bpmn.deployer.BpmnDeployer] (MSC service thread 1-5) Processing resource activiti-flows/MainFlow.bpmn
14:30:01,405 INFO  [org.activiti.engine.impl.bpmn.deployer.BpmnDeployer] (MSC service thread 1-5) Processing resource activiti-flows/StartUp.bpmn
14:30:01,604 INFO  [org.activiti.engine.impl.bpmn.deployer.BpmnDeployer] (MSC service thread 1-5) Processing resource activiti-flows/INQ.bpmn
14:30:01,777 INFO  [org.activiti.engine.impl.bpmn.deployer.BpmnDeployer] (MSC service thread 1-5) Processing resource activiti-flows/testFlow.bpmn20.xml

The problem comes when trying to reference a CDI Bean implementing ( or not ) the JavaDelegate interface from within a
<serviceTask>
step.

We have the following very simple CDI test bean implementing the JavaDelegate interface:

@Named("testFlowTaskCDI")
public class TestFlowTaskCDI implements JavaDelegate {

   @Override
   public void execute(DelegateExecution execution) {            
      System.out.println("Hello from a CDI JavaDelegate class !!");
   }

   public void doSomething(DelegateExecution execution) {
      System.out.println("Hello from a CDI JavaDelegate class !!");
   }
}

Now, no matter how do we try to reference the CDI bean from the XML file ( we tried all the possibilities below ), an error is always raised.

<serviceTask id="serviceTask1" name="Standard service" activiti:expression="#{testFlowTaskCDI.doSomething(execution)}" />
<serviceTask id="serviceTask1" name="Standard service" activiti:delegateExpression="#{testFlowTaskCDI}" />
<serviceTask id="serviceTask1" name="Standard service" activiti:expression="${testFlowTaskCDI.doSomething(execution)}" />
<serviceTask id="serviceTask1" name="Standard service" activiti:delegateExpression="${testFlowTaskCDI}" />
<serviceTask id="serviceTask1" name="Standard service" activiti:expression="testFlowTaskCDI.doSomething(execution)" />
<serviceTask id="serviceTask1" name="Standard service" activiti:delegateExpression="testFlowTaskCDI" />

Stack trace of one of the possibilities,
using
activiti:expression="#{testFlowTaskCDI.doSomething(execution)}"
( similar results are obtained with other possibilities )
ANY IDEAS WHY THIS IS NOT WORKING ?? ANY HELP WOULD BE GREATLY APPRECIATED !!!

org.activiti.engine.ActivitiException: Unknown property used in expression: #{testFlowTaskCDI.doSomething(execution)}
   at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:53) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior.execute(ServiceTaskExpressionActivityBehavior.java:68) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:80) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:116) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:35) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:453) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:431) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:140) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:66) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.execute(FlowNodeActivityBehavior.java:36) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStartInitial.eventNotificationsCompleted(AtomicOperationProcessStartInitial.java:45) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStart.eventNotificationsCompleted(AtomicOperationProcessStart.java:64) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:636) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:629) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:381) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:110) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:37) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:77) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at com.alpha.jproduct.jsf.managed.ActivitiFlowManager.startActivitiFlow(ActivitiFlowManager.java:86) [classes:]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_31]
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_31]
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_31]
   at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_31]
   at javax.el.ELUtil.invokeMethod(ELUtil.java:308) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
   at javax.el.BeanELResolver.invoke(BeanELResolver.java:537) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
   at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
   at com.sun.el.parser.AstValue.invoke(AstValue.java:286) [javax.el-3.0.1-b05.jar:]
   at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304) [javax.el-3.0.1-b05.jar:]
   at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
   at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
   at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
   at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
   at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.2.8-jbossorg-1.jar:]
   … 44 more
Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'testFlowTaskCDI'
   at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:90) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:86) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:50) [activiti-engine-5.19.0.2.jar:5.19.0.2]
   … 123 more

Outcomes