Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

ResourceChangeListener not working at /content/usergenerated/asi/jcr

Avatar

Community Advisor

Hi,

I've written ResourceChangeListener to listen to "ADDED, REMOVED, CHANGED" event and code deployed on version AEM 6.3, 6.4.
The listener is working fine for any path under /content but not working  for /content/usergenerated/asi/jcr.

Anyone have any idea about why it doesn't work for this specific path?

Regards,

Himanshu

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
6 Replies

Avatar

Community Advisor

Hi,

Could you please share more details? or sample code? You may check permission under /content/usergenerated/asi/jcr

Thanks

Arun



Arun Patidar

Avatar

Community Advisor

Hi,

Please find below the sample code.

import java.util.List;

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

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

import org.osgi.service.component.annotations.Component;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

/**

* User Generated Data replicator

*/

@Component(service = ResourceChangeListener.class, property = { ResourceChangeListener.PATHS + "=" + "/content",

ResourceChangeListener.CHANGES + "=" + "ADDED", ResourceChangeListener.CHANGES + "=" + "REMOVED",

ResourceChangeListener.CHANGES + "=" + "CHANGED" })

public class UGCDataReplicator implements ResourceChangeListener {

private Logger log = LoggerFactory.getLogger(this.getClass());

@Override

public void onChange(List<ResourceChange> resourceChanges) {

log.debug("Changed Resources " + resourceChanges);

}

}

And, about the permission there shouldn't be any concern cos' this code is being executed on Author with logged in as Admin user.

Regards,

Himanshu

Avatar

Level 2

activating the service immediately, try to include this property in @component

immediate = true

Avatar

Community Advisor

Hi,

Yes, you are right. Your code looks ok and I also tried. But ResourceChangeListener is not working under that path.

However JCR Events working as expected on the same path.

I am not sure what could be the reason.

Thanks

Arun



Arun Patidar

Avatar

Community Advisor

Hi,

Could you please provide sample code for JCR event based on OSGI R6 annotation?

Regards,

Himanshu

Avatar

Correct answer by
Community Advisor