Custom event not firing | Community
Skip to main content
TheBigRed
Level 4
January 15, 2016
Solved

Custom event not firing

  • January 15, 2016
  • 21 replies
  • 6379 views

As per the following AEM article. I created nodes as said. Also added the timeout exception.

https://helpx.adobe.com/experience-manager/using/events.html

Here is the error log:

 

15.01.2016 12:08:36.601 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent STOPPING 15.01.2016 12:08:36.635 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle Service [com.adobe.aem.events.SimpleDSComponent,4085, [java.lang.Runnable, javax.jcr.observation.EventListener]] ServiceEvent UNREGISTERING 15.01.2016 12:08:36.656 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent STOPPED 15.01.2016 12:08:36.663 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent UNRESOLVED 15.01.2016 12:08:36.664 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent UPDATED 15.01.2016 12:08:36.668 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED 15.01.2016 12:08:36.670 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent RESOLVED 15.01.2016 12:08:36.671 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent STARTING 15.01.2016 12:08:36.672 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle BundleEvent STARTED 15.01.2016 12:08:36.713 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.eventhandler-bundle Service [com.adobe.aem.events.SimpleDSComponent,4092, [java.lang.Runnable, javax.jcr.observation.EventListener]] ServiceEvent REGISTERED 15.01.2016 12:08:36.757 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.granite.repository Service [4093, [org.apache.jackrabbit.oak.spi.commit.Observer]] ServiceEvent REGISTERED 15.01.2016 12:08:36.794 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.granite.repository Service [4094, [org.apache.jackrabbit.api.jmx.EventListenerMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:36.829 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.granite.repository Service [4095, [org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:36.871 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.granite.repository Service [4096, [org.apache.jackrabbit.oak.plugins.observation.filter.FilterConfigMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:36.909 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.granite.repository Service [4097, [java.lang.Runnable]] ServiceEvent REGISTERED 15.01.2016 12:08:36.914 *INFO* [Background Update com.adobe.aem.events.eventhandler-bundle (456)] com.adobe.aem.events.SimpleDSComponent Observing property changes to [nt:unstructured, sling:Folder] nodes under /content/dam/claim 15.01.2016 12:08:36.916 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent STOPPING 15.01.2016 12:08:36.948 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle Service [com.adobe.aem.events.SimpleDSComponent,4092, [java.lang.Runnable, javax.jcr.observation.EventListener]] ServiceEvent UNREGISTERING 15.01.2016 12:08:36.986 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4093, [org.apache.jackrabbit.oak.spi.commit.Observer]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.021 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4094, [org.apache.jackrabbit.api.jmx.EventListenerMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.056 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4095, [org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.091 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4096, [org.apache.jackrabbit.oak.plugins.observation.filter.FilterConfigMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.130 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4097, [java.lang.Runnable]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.141 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent STOPPED 15.01.2016 12:08:37.154 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent UNRESOLVED 15.01.2016 12:08:37.157 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent RESOLVED 15.01.2016 12:08:37.158 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent STARTING 15.01.2016 12:08:37.159 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle BundleEvent STARTED 15.01.2016 12:08:37.197 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.eventhandler-bundle Service [com.adobe.aem.events.SimpleDSComponent,4098, [java.lang.Runnable, javax.jcr.observation.EventListener]] ServiceEvent REGISTERED 15.01.2016 12:08:37.239 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4099, [org.apache.jackrabbit.oak.spi.commit.Observer]] ServiceEvent REGISTERED 15.01.2016 12:08:37.276 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4100, [org.apache.jackrabbit.api.jmx.EventListenerMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:37.316 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4101, [org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:37.356 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4102, [org.apache.jackrabbit.oak.plugins.observation.filter.FilterConfigMBean]] ServiceEvent REGISTERED 15.01.2016 12:08:37.394 *INFO* [FelixFrameworkWiring] com.adobe.granite.repository Service [4103, [java.lang.Runnable]] ServiceEvent REGISTERED 15.01.2016 12:08:37.400 *INFO* [FelixFrameworkWiring] com.adobe.aem.events.SimpleDSComponent Observing property changes to [nt:unstructured, sling:Folder] nodes under /content/dam/claim 15.01.2016 12:08:37.403 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED 15.01.2016 12:08:37.750 *INFO* [Apache Sling Resource Resolver Finalizer Thread] com.adobe.granite.repository Service [4099, [org.apache.jackrabbit.oak.spi.commit.Observer]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.785 *INFO* [Apache Sling Resource Resolver Finalizer Thread] com.adobe.granite.repository Service [4100, [org.apache.jackrabbit.api.jmx.EventListenerMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.823 *INFO* [Apache Sling Resource Resolver Finalizer Thread] com.adobe.granite.repository Service [4101, [org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.860 *INFO* [Apache Sling Resource Resolver Finalizer Thread] com.adobe.granite.repository Service [4102, [org.apache.jackrabbit.oak.plugins.observation.filter.FilterConfigMBean]] ServiceEvent UNREGISTERING 15.01.2016 12:08:37.902 *INFO* [Apache Sling Resource Resolver Finalizer Thread] com.adobe.granite.repository Service [4103, [java.lang.Runnable]] ServiceEvent UNREGISTERING

 

 

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

Hi BigRed - i did more testing. 

Try this code - this will work. I went back to dependency injection to get session and it now works. Taken from this example: https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

 

I also see the event as Joerg points out.

@Component(metatype=true)
@Service
public class SimpleDSComponent implements Runnable,EventListener {
    
    private Logger log = LoggerFactory.getLogger(this.getClass());
    
    private BundleContext bundleContext;
    
    
    @Reference
    private SlingRepository repository;
    
  //Inject a Sling ResourceResolverFactory
    @Reference
    private ResourceResolverFactory resolverFactory;
    
    private Session session;
    
    private ObservationManager observationManager;
    
  //Inject a Sling ResourceResolverFactory to create a Session requited by the EventHandler
 
    
    public void run() {
        log.info("Running...");
    }
    
    
    //Place app logic here to define the AEM Custom Event Handler
    protected void activate(ComponentContext ctx) {
        this.bundleContext = ctx.getBundleContext();
        
        try
        {
                   
            //Invoke the adaptTo method to create a Session 
            // ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
             session = repository.loginAdministrative(null);
             
            // Setup the event handler to respond to a new claim under content/claim.... 
                observationManager = session.getWorkspace().getObservationManager();
                 final String[] types = { "nt:unstructured","sling:Folder" };
                 final String path = "/content/claim"; // define the path
                 observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false);
                 log.info("Observing property changes to {} nodes under {}", Arrays.asList(types), path);
                          
         }
        catch(Exception e)
        {
            e.printStackTrace(); 
         }
        }

         protected void deactivate(ComponentContext componentContext) throws RepositoryException {
             
             if(observationManager != null) {
                 observationManager.removeEventListener(this);
             }
             if (session != null) {
                 session.logout();
                 session = null;
               }
         }

        //Define app logic that is fired when the event occurs - simply track the time 
        //when the event occurred. 
         public void onEvent(EventIterator itr) {
             
             //Calendar cal = Calendar.getInstance();
            //cal.getTime();
            //SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
             
            //log the time when the event occurred 
             log.info("A new node was added to content/claim ");
                         
         }
}

See http://localhost:4502/system/console/events: 

21 replies

edubey
Level 10
January 15, 2016

Can you elaborate more on this. It will help community to solve this...

I couldn't see errors in log file you shared.

smacdonald2008
Level 10
January 15, 2016

What aem version are you using?

TheBigRed
TheBigRedAuthor
Level 4
January 15, 2016

smacdonald2008 wrote...

What aem version are you using?

 


6.1

TheBigRed
TheBigRedAuthor
Level 4
January 15, 2016

edubey wrote...

Can you elaborate more on this. It will help community to solve this...

I couldn't see errors in log file you shared.

 

 

I have a use for manipulating a property field on upload

was hoping to use this method instead of workflow route.
Simply just testing event article out before I make changes.

The article claims it's supposed to log a time/date when I create nt:unstructured or sling:folder

nodes under the /content/claim

Thanks.

smacdonald2008
Level 10
January 15, 2016

Article is marked as 5.6. We will test on 6.1

smacdonald2008
Level 10
January 15, 2016

Try modifying the package that the custom event handler is in. I changed to this package: com.community

I got it working with that package. I think the package com.adobe.cq was conflicting with other ones. I will test on 6 and 6.1. 

I will also update the article to reflect new package and testing on newer AEM versions. 

I just got this output:

15.01.2016 14:57:56.028 *INFO* [ObservationManager] com.community.SimpleDSComponent A new node was added to content/claim 
 

joerghoh
Adobe Employee
Adobe Employee
January 15, 2016

Hi,

this should work with 6.1 as well; have you actually created such a node ("nt:unstructured" or "sling:Folder") below /content/claim?

Jörg

smacdonald2008
Level 10
January 15, 2016

Also try using this code too - replace the code in your OSGi bundle with this code... . 

// Setup the event handler to respond to a new claim under content/claim.... 
                observationManager = session.getWorkspace().getObservationManager();
                 final String[] types = { "nt:unstructured","sling:Folder" };
                 final String path = "/content/claim"; // define the path
                 observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false);
                 log.info("Observing property changes to {} nodes under {}", Arrays.asList(types), path);

TheBigRed
TheBigRedAuthor
Level 4
January 15, 2016

smacdonald2008 wrote...

Also try using this code too - replace the code in your OSGi bundle with this code... . 

// Setup the event handler to respond to a new claim under content/claim.... 
                observationManager = session.getWorkspace().getObservationManager();
                 final String[] types = { "nt:unstructured","sling:Folder" };
                 final String path = "/content/claim"; // define the path
                 observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false);
                 log.info("Observing property changes to {} nodes under {}", Arrays.asList(types), path);

 


Okay this worked. Thanks Scott!

Now my problem is this seems to only fire once. I set timeout exception as well.

I need it to constantly watch over this folder to change some properties in crdxe.

Is this the wrong use case?

TheBigRed
TheBigRedAuthor
Level 4
January 18, 2016

Any help on this please with 6.1?

Thanks for all the support.