Expand my Community achievements bar.

Event Handler not working on second time

Avatar

Level 5

Hi Team,

I am trying to create a event handler for deleting a page.First time ,  its calling up... but second time its not calling handleEvent() method..any clue??

10 Replies

Simple code snippet:

@Component(immediate = true)

@Service

@Property(name = EventConstants.EVENT_TOPIC, value = "com/day/cq/wcm/core/page")

public class SimpleResourceListener implements EventHandler{

  public SimpleResourceListener(){

  System.out.println("inside construc");

  }

  private Logger log =LoggerFactory.getLogger(this.getClass());

  public void handleEvent(Event event) {

  // TODO Auto-generated method stub

  System.out.println("inside hanlder");

  }

Now when I create a page, this handler reacts and logs the string "inside handler". Now when I activate the page second or third time, the Event handler does not react

Avatar

Level 10

Does the Event handler fire when you create a 2nd page?

Avatar

Level 10

Also - what AEM version are you using and how are you getting the Session?

No , Event is firing on first time only ...AEM 6.0 SP2

If restart the bundle ... its firing a event...but not on second time again...

Avatar

Level 7

I tried your code on 6.3.. The handlers are getting triggered correctly. When you say " I activate the page second or third time, the Event handler does not react", do you make any change before activating the page again?

When there is no change, activation is never really triggered, so corresponding event handle should not be called anyway

Avatar

Level 5

viveksachdeva

Hi , Sorry .. I am not trying to replicate the page  ...

I wanna trigger a event when i try to create a page or delete a page ...

So first time event is calling properly but not second time...

Example :

test - cq:page - working

test1-cq:page - not working

Avatar

Level 10

In the HELPX article - it states. Have you configured your event handler to not timeout?

Blacklist

Event handling in Sling by default may timeout your event handler. To configure your event handler to ignore a timeout, perform these tasks:

  1. Go to http://:/system/console/configMgr.
  2. Select Configuration.
  3. Select "Apache Felix Event Admin Implementation".
  4. You should see a list for ignore timeout, specify your package in that list.

Sorry ...I forgot to update the latest status on this...

I am able to get the events once I configured a package to ignore a timeout..

Avatar

Level 10

That is great! I am going to update this article soon for use on 6.3.