Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Event Handler Not Working in AEM 6.4

gauravp49120709
Level 1
Level 1

******************************************************************************************************************************************************************************

Hi,

We have implemented an Event Handler registered as below:

    import org.apache.felix.scr.annotations.Component;

    import org.apache.felix.scr.annotations.Properties;

    import org.apache.felix.scr.annotations.Property;

    import org.apache.felix.scr.annotations.Reference;

    import org.apache.felix.scr.annotations.Service;

    import org.apache.sling.api.SlingConstants;

    import org.apache.sling.api.resource.ResourceResolverFactory;

    import org.apache.sling.api.resource.observation.ResourceChangeListener;

    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;

   

   

    /**

     * This is a node observer class which would observe the path /content/we-retail

     * for any addition or updation of nodes (type = cq:PageContent).

     * @author

     */

   

    @Component(label = "Test Event Listener", immediate = true, metatype =

        false, enabled = true)

    @Properties({

       

       /* @Property(name = EventConstants.EVENT_TOPIC, value = ReplicationAction.EVENT_TOPIC)

})*/

@Property(name = EventConstants.EVENT_TOPIC, value =

{"org/apache/sling/api/resource/Resource/ADDED",

"org/apache/sling/api/resource/Resource/CHANGED"}),

        @Property(name = EventConstants.EVENT_FILTER, value = "(&" +

"(path=/content/we-retail/us/en/*/jcr:content) (|(" + SlingConstants

.PROPERTY_CHANGED_ATTRIBUTES + "=*jcr:title) "

            + "(" + ResourceChangeListener.CHANGES + "=*jcr:title)))")

    })

   

    @Service(EventHandler.class)

    public class TestEventHandler implements EventHandler {

   

        private static final Logger LOG = LoggerFactory.getLogger(TestEventHandler.class);

   

        /*

         * Reference of ResourceResolverFactory object.

         */

        @Reference

        private ResourceResolverFactory resourceResolverFactory;

   

        /*

         * (non-Javadoc)

         * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)

         */

        @Override

        public void handleEvent(Event event) {

LOG.info("Hi event is called ......");

        }

   

    } 

   

Issue is: Our handleEvent doesn't get trapped when change the property value for jcr:title on any page under the path: /content/we-retail/us/en

AEM version is: 6.4

sling version used is : org.apache.sling.api

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

This works on AEM 6.4. Please follow all steps in the article - including creating a system user and using the Sling Mapping Service - Creating an Event Listener for Adobe Experience Manager 6.4

View solution in original post

0 Replies
toimrank
Level 3
Level 3

Hey,

I tried all above mentioned things in the Vanilla instance and found below result:

First Link: Below link didn't get work in my case, Listener didn't get invoked.

aem63app-repo/SampleJCREvent.java at master · arunpatidar02/aem63app-repo · GitHub

Second below link worked in my case with one exception: It is not giving the the property got changed under mentioned resource as given below screen shot.

aem63app-repo/TestEventHandler.java at master · arunpatidar02/aem63app-repo · GitHub

eventhandler.PNG

Please let me know in case of any solution found. If I got something will post the same here for sure.

Thanks

smacdonald2008
Correct answer by
Level 10
Level 10

This works on AEM 6.4. Please follow all steps in the article - including creating a system user and using the Sling Mapping Service - Creating an Event Listener for Adobe Experience Manager 6.4

View solution in original post