cancel
Showing results for 
Search instead for 
Did you mean: 

Error while execute EJB method from ExecutionListener

shanakamm
Champ in-the-making
Champ in-the-making
HI All,

Im getting below error while trying to execute EJB method inside my ExecutionListener class. the class is invoked by sequenceFlow. please see below code.

My BPMN process
<sequenceFlow id="flow27" sourceRef="emailsTimer" targetRef="END">
         <extensionElements>
            <activiti:executionListener
               class="com.test.tools.EmailTimerHandler" />
         </extensionElements>         
      </sequenceFlow>


My EmailTimerHandler class
public class EmailTimerHandler  implements ExecutionListener {

   private static final long serialVersionUID = 1L;
   private static final Logger log = Logger.getLogger(EmailTimerHandler.class.getName());
   
   @EJB
   private EdgevantageUtilBeanLocal utilBeanLocal;
   
   @Override
   public void notify(DelegateExecution execution) throws Exception {
      log.info("EmailTimerHandler Called for event- " + execution.getEventName());      
      try{         
         utilBeanLocal.testJoin();
         
      }catch(RuntimeException rte){
         rte.printStackTrace();
         log.warning(rte.getMessage());
      }
   }
}


Exception
22:40:00,346 ERROR [stderr] (pool-11-thread-1) java.lang.NullPointerException
22:40:00,347 ERROR [stderr] (pool-11-thread-1)    at com.test.tools.EmailTimerHandler.notify(EmailTimerHandler.java:29)
22:40:00,347 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.delegate.ExecutionListenerInvocation.invoke(ExecutionListenerInvocation.java:34)
22:40:00,348 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
22:40:00,349 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
22:40:00,349 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:71)
22:40:00,350 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:48)
22:40:00,351 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,351 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,352 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,353 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:116)
22:40:00,353 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,354 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,355 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,355 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36)
22:40:00,357 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
22:40:00,358 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,359 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,361 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,362 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
22:40:00,362 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,363 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,364 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,365 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:114)
22:40:00,365 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,366 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,367 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,369 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36)
22:40:00,370 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
22:40:00,371 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:87)
22:40:00,372 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:532)
22:40:00,373 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:527)
22:40:00,374 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:367)
22:40:00,375 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.pvm.runtime.OutgoingExecution.take(OutgoingExecution.java:44)
22:40:00,375 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.takeAll(ExecutionEntity.java:501)
22:40:00,376 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior.execute(BoundaryEventActivityBehavior.java:76)
22:40:00,377 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler.execute(TimerExecuteNestedActivityJobHandler.java:47)
22:40:00,377 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:79)
22:40:00,378 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
22:40:00,379 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:70)
22:40:00,379 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
22:40:00,380 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:61)
22:40:00,381 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
22:40:00,382 ERROR [stderr] (pool-11-thread-1)    at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:46)
22:40:00,382 ERROR [stderr] (pool-11-thread-1)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
22:40:00,383 ERROR [stderr] (pool-11-thread-1)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
22:40:00,384 ERROR [stderr] (pool-11-thread-1)    at java.lang.Thread.run(Thread.java:619)
22:40:00,384 WARNING [com.test.tools.EmailTimerHandler] (pool-11-thread-1) null


Thanks and regards
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
If you use the activiti:class="…", there will be an instance of that class created by activiti, using class.forName() somewhere deep down in the engine. Since activiti is NOT aware of your EJB-context, all the annotations you have, related to EJB are NOT picked up by the EJB-container.

The EJB-container can't do magic, neither can activiti. The way you should do this is to use the "beans" property on the process engine configuration. Before the engine is build, you should add a reference to a valid EJB-bean (your com.test.tools.EmailTimerHandler) fetched from the EJB-container eg. using the key 'emailHandler'. In the BPMN, instead of using a activiti:class, use activiti:delegateExpression="${emailHandler}". At runtime, the expression will be resolved and the instance that was put into the "beans" map will be used, which is an instance that is aware of the EJB-context.