cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti listeners not working

logic3
Champ in-the-making
Champ in-the-making
HI,

I am trying to catch all the events for a process running on the Activiti explorer. I have implemented the bpmnparselistener class and moved my handler classes as Jars file to the WEB-INF/lib folder (ParseListener.jar). I have uploaded my process to the explorer using the bar file. However. no events are generated for the deployed process i.e. start event. I think It is my code below, which i am not sure where to put. Currently, it is in \webapps\activiti-explorer\WEB-INF\applicationContext.xml. I tried embedding the Listener with in the BPMN xml file and it worked but look like the Activiti can not read when using BPMNParseListener (implemented). It doesn't raise any exceptions or errors. My understanding is that Activiti engine automatically understand the customPostBPMNParseListeners property and there is nothing to declare in the process itself

 <property name="customPostBPMNParseListeners">
      <list>
        <bean class="org.handler.ParseListener"></bean>
      </list>
    </property>



Any help would be highly appreciated

thanks,
32 REPLIES 32

trademak
Star Contributor
Star Contributor
Are you using Activiti 5.10?
What did you implement in the BpmnParseListener?

Best regards,

logic3
Champ in-the-making
Champ in-the-making
Yes, It is Activiti 5.10.

I tried to Implement the BpmnParseListener like the HistoryParseListner class. I have a method (addActivityHandlers()-shown below) with in the BpmnParseListener that is called from different parse events for example;


public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {addActivityHandlers(activity);
  }


addActivityHandlers(ActivityImpl activity) {
activity.addExecutionListener(PvmEvent.EVENTNAME_START, ACTIVITY_INSTANCE_START_LISTENER, 0);
activity.addExecutionListener(PvmEvent.EVENTNAME_END, ACTIVITY_INSTANCE_END_LISTENER);
}

I also have my handler classes to catch the events. They are separate classes for example: ActivityInstanceStartHandler, ActivityInstanceEndHandler.

I have tested this application offline with unit Testing and it works perfectly  but it is not working on server or activiti explorer to generate live events.

thanks,

Kind regards,
Logic3

frederikherema1
Star Contributor
Star Contributor
Is your engine-configuration in the activiti-explorer application-context? A default activiti.cfg.xml file IS NOT picked up in activiti-explorer, as it uses the spring-context to fire up the engine, unlike how it is done in a standalone setup.

logic3
Champ in-the-making
Champ in-the-making
Honestly I am not sure about my engine configuration  Smiley Surprisedops: . I thought the Activiti engine uses activiti-explorer\WEB-INF\applicationContext.xml by default for configuration and that's why I added the bpmnParseListner property to the activiti-explorer\WEB-INF\applicationContext.xml. Could you please advise how to resolve this or fix this problem ?

many thanks

applicationContext.xml file:
<context:annotation-config />
 
  <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:db.properties" />
    <!– Allow other PropertyPlaceholderConfigurer to run as well –>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
  </bean>

  <bean id="demoDataGenerator" class="org.activiti.explorer.demo.DemoDataGenerator">
    <property name="processEngine" ref="processEngine" />
  </bean>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driver}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
     <property name="defaultAutoCommit" value="false" />
  </bean>
 
  <!– <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true" />
    <property name="username" value="activiti" />
    <property name="password" value="activiti" />
     <property name="defaultAutoCommit" value="false" />
  </bean> –>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource" />
  </bean>
 
  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
   <property name="dataSource" ref="dataSource" />
   <property name="transactionManager" ref="transactionManager" />
   <property name="databaseSchemaUpdate" value="true" />
   <property name="jobExecutorActivate" value="true" />
    <property name="customFormTypes">
      <list>
        <ref bean="userFormType"/>
      </list>
    </property>

    <!–  My Listener –>
    <property name="customPostBPMNParseListeners">
      <list>
        <bean class="org.bpmnwithactiviti.handler.ParseListener"></bean>
      </list>
    </property>
  
   
  </bean>
 
  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
   <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>
 
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
 
  <bean id="activitiLoginHandler" class="org.activiti.explorer.ui.login.DefaultLoginHandler">
    <property name="identityService" ref="identityService" />
  </bean>
 
 
 
  <!– Include the UI-related wiring. This UI context will be used in the alfresco activiti admin UI –>
  <import resource="activiti-ui-context.xml" />
 
  <!–  Custom form types –>
  <bean id="userFormType" class="org.activiti.explorer.form.UserFormType"/>

</beans>

frederikherema1
Star Contributor
Star Contributor
You are right, it does. But if you test you code in a unit-test for example, standalone activiti.cfg.xml is used (if using default activiti test cases).

That configuration looks good. You said that it worked outside of tomcat, how did you test that?

logic3
Champ in-the-making
Champ in-the-making
Thanks for your reply.

I really can't figure out why it is not working. Below you can find my applicationcontext file for offline testing. It offers engine configuration, deploy the process and contain the BPMNParseListner property.  I then used the "@ContextConfiguration("classpath:listener/application-context.xml")" with in my tester.java file which simply run the process using "ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");". For unit testing, the running process successfully throws out events.

<bean id="dataSource"
  class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
  <property name="targetDataSource">
   <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    <property name="driverClass" value="org.h2.Driver" />
    <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
    <property name="username" value="sa" />
    <property name="password" value="" />
   </bean>
  </property>
</bean>

<bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="databaseType" value="h2" />
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
 
<!– Deploy BPMN process –>
  <property name="deploymentResources"
   value="classpath*:listener/processEventListener.bpmn20.xml" />
 
 
  <property name="history" value="full" />
  <property name="jobExecutorActivate" value="false" />
 
  <!–  My Listener –>
   <property name="customPostBPMNParseListeners">
       <list>
             <bean class="org.bpmnwithactiviti.handler.ParseListener"></bean>
       </list>
     </property>
 
 
</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<bean id="repositoryService" factory-bean="processEngine"
  factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
  factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
  factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
  factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
  factory-method="getManagementService" />

</beans>

frederikherema1
Star Contributor
Star Contributor
I don't see any other customizations in your app-context.xml file. Are you sure there is NO activiti.cfg.xml on your class path somewhere?

Because it *could* be that the wrong default-process-engine has been initialized BEFORE, so the one that your spring-context fires up, is not registered as default. All explorer-app code uses ProcessEngines.getDefaultProcessEngine() to obtain a process-engine.

So the presence of a activiti.cfg.xml-file will cause that engine to be used, while all other parts (UI, …) are taken from spring.

logic3
Champ in-the-making
Champ in-the-making
thanks for your response.
Could you please advise how to fix this so that the activiti explorer start throwing events?

cheers

frederikherema1
Star Contributor
Star Contributor
As I said in the previous post: can you check IF there ere any activiti.cfg.xml-files on your tomcat class path (in WEB-INF/classes, inside a jar, in tomcat/lib, …). If this is the case, remove it. If this is not the case, we're back to square one…

logic3
Champ in-the-making
Champ in-the-making
Thanks a million. It is working now Smiley Very Happy .
You were right. I had to delete the activiti-cfg.jar from tomcat/lib.
Thanks again.