Skip to main content
Aug 23, 2018 5:53 PM UTC
Solved

Event Handler Not Working in AEM 6.4

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Nov 13, 2018 9:05 PM UTC

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

5 replies

arunpatidar
Community Advisor
Community Advisor
Aug 23, 2018 6:21 PM UTC
Level 2
Nov 13, 2018 5:39 PM UTC

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

Translate
Level 2
Nov 13, 2018 6:17 PM UTC
Level 2
Nov 13, 2018 6:44 PM UTC

Hey Santhi,

I have already tried please read my below blog.

Listeners and handlers are not giving changed or added property names issue in 6.4

Regards

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Nov 13, 2018 9:05 PM UTC

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

Translate