About the event handler documentation example

1
0
-1

Hello,

Following the example given here :

I want to write an event handler.

I'm not aware of Spring mecanics which I'm starting to learn thanks to bonita (thank you bonita).

It seems my attempt is not working. I've added the following in my cfg.xml bean configuration file:

<bean id="eventService"
       class="com.bonitasoft.engine.events.impl.ConfigurableEventServiceImpl">
        <constructor-arg name="eventBuilders" ref="eventBuilders" />
        <constructor-arg name="handlers">
                <map>
                        <entry key="ACTIVITYINSTANCE_CREATED">
                                <bean class="fr.univlille2.bpm.ActivityNotifier"></bean>
                        </entry>
                </map>
        </constructor-arg>
</bean>

I've added a jar containing fr.univlille2.bpm.ActivityNotifier.class in Tomcat's lib folder and here is the relevant part of my source code (where sendmail() method has been tested)

public class ActivityNotifier implements SHandler<SEvent> {  

    public ActivityNotifier() {
        }
       
        @Override
        public void execute(SEvent event) throws SHandlerExecutionException {
                sendMail();            
        }

        @Override
        public String getIdentifier() {
                return null;
        }

        @Override
        public boolean isInterested(SEvent event) {
                Object eventObject = event.getObject();
                if (!(eventObject instanceof SFlowNodeInstance))
                        return false;
                return true;
        }
       

What's wrong here ? Do I need to declare ActivityNotifier as a bean too ? When I try to do this bonita gets stuck on a 500 error....

Thanks!

2 answers

1
+1
-1
This one is the BEST answer!

The method getIdentifier of your custom Handler must not return null but a value which should be unique. This identifier is used internally by the event service.

Comments

Submitted by aCordier on Fri, 05/23/2014 - 15:55

Thanks, just to make it clear to me: this id has to be unique per definition and returning canonical class name may be a good practice, is it ?

Submitted by aCordier on Fri, 05/23/2014 - 16:16

Anyway, my big mistake here was to add my fragment to cfg.xml instead of cfg-bonita-events-api-impl.xml

Submitted by aCordier on Mon, 05/26/2014 - 12:54

Resolved by this answer as this is the most valuable information given here

Submitted by matthieu.chaffotte on Mon, 05/26/2014 - 14:23

According to the javadoc of the method, the identifier must be unique for each instance of the handler. So you can concatenate the className or the concept of that handler with a random number. I am not aware enough about that method.

Submitted by christine.mckinty on Mon, 05/26/2014 - 17:29

I fixed the configuration file name in doc page. More updates to this page are coming soon, so keep the feedback coming, please!

Submitted by aCordier on Tue, 05/27/2014 - 18:46

Ok for now I bet on a new UID().toString() as a return for the getIdentifier() method more to come

1
0
-1

Bonjour aCordier,

Petite question au prélable, utilisez-vous la version community ou la version souscription ? et quelle 6.x ?

Je demande cela, car les Events Handlers sont uniquement configurables dans l'édition Souscription de Bonita BPM.

A ce sujet, je vous invite à découvrir l'exemple disponible dans notre documentation : http://documentation.bonitasoft.com/event-handlers

Cordialement, A très bientôt

Comments

Submitted by aCordier on Mon, 05/05/2014 - 20:07

Bonjour,

J'utilise la version SP mais quand je suis la documentation je ne parviens pas à ce résultat.

Submitted by bos2013 on Wed, 05/07/2014 - 11:44

Bonjour,

Comme vous utilisez la version SP, je vous invite à ouvrir un nouveau "case" depuis le portail client : https://customer.bonitasoft.com

N'oubliez pas d'ajouter le log de Bonita que vous trouverez dans le répertoire: Tomcat_6.2.6\logs\bonita.2014-MM-DD.log

Je suis également tombé sur une page 500 avec ma version 6.2.6 en utilisant l'exemple du site document.

PS/ Normalement, le fichier jar est à mettre dans le répertoire de la webapp de bonita.war : bonita/WEB-INF/lib Pourriez-vous faire un dernier test de vérification avant d'ouvrir le case au support Bonita ? Merci par avance.

A bientôt, LL

Submitted by aCordier on Wed, 05/07/2014 - 14:15

Pour le lib ça revient au même non ? Quoi qu'il en soit je vais faire le test et ouvrir le cas, merci. Antoine

Notifications