Solved! Go to Solution.
Views
Replies
Total Likes
@kiranc13433869 - Check this
The following class for CustomEventHandler sample -
package org.test.demo.core.listeners;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Event Handler that listens to the Sling events
*/
@Component(immediate = true, service = EventHandler.class, property = {
Constants.SERVICE_DESCRIPTION + "= This event handler listens the events on page activation",
EventConstants.EVENT_TOPIC + "=org/apache/sling/api/resource/Resource/ADDED",
EventConstants.EVENT_TOPIC + "=org/apache/sling/api/resource/Resource/CHANGED",
EventConstants.EVENT_FILTER + "(&" + "(path=/content/we-retail/us/en/*/jcr:content) (|("
+ SlingConstants.PROPERTY_CHANGED_ATTRIBUTES + "=*jcr:title) " + "(" + ResourceChangeListener.CHANGES
+ "=*jcr:title)))" })
public class CustomEventHandler implements EventHandler {
/**
* Logger
*/
private static final Logger log = LoggerFactory.getLogger(CustomEventHandler.class);
@Override
public void handleEvent(Event event) {
log.info("Event is: {}", event.getTopic());
}
}
As you can see that we have service property service=EventHandler.class and EventConstants.EVENT_TOPIC registered to resource added and changed which normally happens in AEM Replication
and implemented the handleEvent() method and it is logging the topic for which this event handler is registered.
Deploy the code and activate (publish) any page. You will see following traces in the logs
org.test.demo.core.listeners.CustomEventHandler Event is: org/apache/sling/api/resource/Resource/ADDED
org.test.demo.core.listeners.CustomEventHandler Event is: org/apache/sling/api/resource/Resource/CHANGED
Do you see any errors while restarting the bundle for these specific components ?
If possible can you share the snippet of the code for event handler.
Ideally, after the installation, the event handler is not getting satisfied and hence you are forced to do it manually. For example, if your handler is using any service and if its not active immediately (immediate = true) this might cause the issue.
Can you check if everything is in the satisfied state as per below sample image?
Hope this helps!
Thanks,
Kiran Vedantam.
@kiranc13433869 - Check this
The following class for CustomEventHandler sample -
package org.test.demo.core.listeners;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Event Handler that listens to the Sling events
*/
@Component(immediate = true, service = EventHandler.class, property = {
Constants.SERVICE_DESCRIPTION + "= This event handler listens the events on page activation",
EventConstants.EVENT_TOPIC + "=org/apache/sling/api/resource/Resource/ADDED",
EventConstants.EVENT_TOPIC + "=org/apache/sling/api/resource/Resource/CHANGED",
EventConstants.EVENT_FILTER + "(&" + "(path=/content/we-retail/us/en/*/jcr:content) (|("
+ SlingConstants.PROPERTY_CHANGED_ATTRIBUTES + "=*jcr:title) " + "(" + ResourceChangeListener.CHANGES
+ "=*jcr:title)))" })
public class CustomEventHandler implements EventHandler {
/**
* Logger
*/
private static final Logger log = LoggerFactory.getLogger(CustomEventHandler.class);
@Override
public void handleEvent(Event event) {
log.info("Event is: {}", event.getTopic());
}
}
As you can see that we have service property service=EventHandler.class and EventConstants.EVENT_TOPIC registered to resource added and changed which normally happens in AEM Replication
and implemented the handleEvent() method and it is logging the topic for which this event handler is registered.
Deploy the code and activate (publish) any page. You will see following traces in the logs
org.test.demo.core.listeners.CustomEventHandler Event is: org/apache/sling/api/resource/Resource/ADDED
org.test.demo.core.listeners.CustomEventHandler Event is: org/apache/sling/api/resource/Resource/CHANGED
Views
Likes
Replies
Views
Likes
Replies