AnsweredAssumed Answered

activiti-cdi problem with inject

Question asked by cweber on Jan 9, 2013
Latest reply on Jan 11, 2013 by ronald.van.kuijk
Hi. After ronald.van.kuijk told me a few weeks ago that maybe cdi could be a good try to use it for my JSF gui, I found now the time to give it a try.

I found in this forum a link from Daniel Meyer to this topic.
I used the example of Daniel Meyer were he showed to start the engine with code.
https://bitbucket.org/meyerd/activiti-cdi-jbossas7.1.1-setup/src/4216c17d3adc/programmatic/src/main/java/TestBean.java?at=master 

I got the example work on my local Jboss 7.1.1.Final with activiti-5.9 and activiti-cdi-5.9 without any problem.

But if I try to inject another class of the activiti engine I run into errors.

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.identity.User;

import de.mettenmeier.util.DebugConsole;

@Startup
@Singleton
public class TestBean {

   @Inject
   private ProcessEngine processEngine;

   @Inject
        private IdentityService identityService;
   
   @PostConstruct
   protected void init() {
      DebugConsole.out("This is the Engine with the name : "+ processEngine.getName(), 9);
      DebugConsole.out(processEngine.VERSION, 9);
      //IdentityService identityService = processEngine.getIdentityService();

      User u = identityService.createUserQuery().userId("kermit")
            .singleResult();
      System.out.println(u.getId());
   }
}

The code above prints out the the name and the version of the engine. But If I try to use the injected identityService I get the following errors.


13:05:07,329 INFO  [stdout] (MSC service thread 1-8) This is the Engine with the name : default

13:05:07,330 INFO  [stdout] (MSC service thread 1-8) 5.9

13:05:07,354 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.unit."MBSActivitiProjekt.war".component.TestBean.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."MBSActivitiProjekt.war".component.TestBean.START: Failed to start service
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_07]
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_07]
   at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_07]
Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
   at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
   at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85)
   at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:116)
   at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:130)
   at org.jboss.as.ee.component.ComponentStartService.start(ComponentStartService.java:44)
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
   … 3 more
Caused by: javax.ejb.EJBException: java.lang.NullPointerException
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:333)
   at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
   … 9 more
Caused by: java.lang.NullPointerException
   at TestBean.init(TestBean.java:31)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_07]
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_07]
   at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_07]
   at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:73)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
   … 18 more

13:05:07,572 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "MBSActivitiProjekt.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"MBSActivitiProjekt.war\".component.TestBean.START" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"MBSActivitiProjekt.war\".component.TestBean.START: Failed to start service"}}
13:05:07,575 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."MBSActivitiProjekt.war".component.TestBean.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."MBSActivitiProjekt.war".component.TestBean.START: Failed to start service

13:05:07,587 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"MBSActivitiProjekt.war\".component.TestBean.START" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"MBSActivitiProjekt.war\".component.TestBean.START: Failed to start service"}}}}
13:05:07,601 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016009: Stopping weld service for deployment MBSActivitiProjekt.war
13:05:07,603 INFO  [org.activiti.engine.impl.jobexecutor.JobExecutor] (MSC service thread 1-1) Shutting down the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].
13:05:07,604 INFO  [org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable] (Thread-70) JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] stopped job acquisition
13:05:07,605 INFO  [org.activiti.cdi.impl.ActivitiExtension] (MSC service thread 1-1) Shutting down activiti-cdi

Another way I tried was not to use the injection of the IdentityService. I tried to get it with my injected processEngine.
IdentityService identityService = processEngine.getIdentityService(); (its commented in the example)
But this failed, too.

So it seems the injection of the processEngine is wrong even if I got its name and version.

Can somebody tell me what I have to do to get the IdentityService, RuntimeService, TaskService…. injected?
Would be nice to help me get started.

Outcomes