Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Set up PageEvent Handler/Listener

Avatar

Level 1

Hello AEM Community

Im currently working on setting up a event handler for page creations and deletions on aem to then call one of our vendors API.

Ive been basing my work on a module we already have that listens to replication events.

So far i was able to reproduce that behavior on my module and trigger the code upon replications. However, i only need the calls to the API on Page Publications and deletions.

Ive been trying to find how to diferentiate between replications and page deletions and activations.

So far, it seems that AEM handles crx replications and page publications as the same type of event "type= ACTIVATION".

If i delete a page, it does set the type as "DELETE" so i can work with that to call  the API but for the page publications im lost since as i mentioned, AEM looks like it handles CRX replications and pages publications as the same type.

After some research, i found the PageEvent API and I tried to set up a Page Event Listener but it is not getting triggered upon publications or deletions of pages, so im not sure that if what im trying to do its possible or maybe my componet is located on a wrong part of the project to listen for Page Events.

Thanks beforehand

9 Replies

Avatar

Employee Advisor

What is the difference between "CRX replication" and "page publication" from your point of view?

Avatar

Level 1

Hello.

So, for example, if i go to crx and i replicate any of the files we already have being html, css or js, i get a replicate type=ACTIVATE event.

However, we only want to catch whenever a new page is created or deleted.

Not sure if that answers your question

Avatar

Level 10

Have you written code that uses the PageEvent API:

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/in..."The Adobe AEM Quickstart and Web Application."

This is certainly the API to use to capture page changes.

Can you post it so the community can see if its properly set up to help solve your issue?

Avatar

Level 1

yes, ill post what i have currently.

I dont see an option to edit the original post so ill post it here.

Component(

   configurationPolicy = ConfigurationPolicy.REQUIRE,
   immediate = true,
   service = EventHandler.class)

@Designate(ocd = APIConfiguration.class)

public class CustomEventListener implements EventHandler {

   private static final Logger LOGGER = LoggerFactory.getLogger(CustomEventListener.class);

  
  public void handleEvent(final Event event) {

   LOGGER.debug("handling event");
   PageEvent pgEvent = PageEvent.fromEvent(event);
   LOGGER.debug(pgEvent.toString());
   LOGGER.debug(pgEvent.toEvent().toString());


   }

}

on my config class i have:

@ObjectClassDefinition(

   name = "API Connection Details",
   description = "APIConnection Details")

public @interface APIConfiguration {

   @AttributeDefinition(

   name = EventConstants.EVENT_TOPIC,
   description = "Page Action Event"
   )

  String page_topics() default PageEvent.EVENT_TOPIC;
}

So whenever i either create a new page or delete it from AEM Dashboard the code doesnt get triggered.

It only works if add the replication topic to the config class.

Avatar

Employee Advisor

When you want to track creation or deletion of pages (and ignore all activation and deactivation stuff) on a single instance, you can use eventing for it.

Create a page in your AEM instance then check localhost:4502/system/console/events for the event describing the page creation.

Avatar

Level 1

ok, seems that the topic would be: org/apache/sling/api/resource/Resource/ADDED for page additions

And org/apache/sling/api/resource/Resource/REMOVED

Avatar

Level 1

I set both topics on the configuration file

topics config.png

but i still dont get the event triggered upon page addition or deletion even tho i can see the event with the topic being generated correctly on /system/console/events

Avatar

Level 1

any idea why it wont tigger even if the topics are bindend to the module?

Avatar

Level 10

Debug the code to check if it get's registered and listens to the topics or not? If not, then possibly you're running into some API versions/library versions conflicts.

check if this helps - java - AEM 6.3 - Creating Event handler using OSGi R6 annotations - Stack Overflow

this one uses SCR annotations - Adobe CQ Help | Creating Replication Event Handlers for Adobe Experience Manager