I am trying to hook to the rollout event of a page to a live copy. I am experimenting with the EvenListener but I am unable to get it to work. This is my code:
@Component(metatype = true)
@Service
public class MyCustomListener implements EventListener {
private static final Logger LOG = LoggerFactory.getLogger("logger");
@Reference
private ResourceResolverFactory resolverFactory;
private Session session;
private ObservationManager observationManager;
public void run() {
LOG.info("Running...");
}
//Place app logic here to define the AEM Custom Event Handler
protected void activate(ComponentContext ctx) {
try {
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(AutoClosableResourceResolverFactory.getCredentials());
session = resourceResolver.adaptTo(Session.class);
observationManager = session.getWorkspace().getObservationManager();
final String[] types = {"cq:Page", "nt:unstructured"};
final String path = "/"; // 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) {
LOG.error("unable to register session", e);
}
}
protected void deactivate(ComponentContext componentContext) throws RepositoryException {
if (observationManager != null) {
observationManager.removeEventListener(this);
}
if (session != null) {
session.logout();
session = null;
}
}
@Override
public void onEvent(EventIterator eventIterator) {
System.out.println();
}
}
My debug point in the onEvent method never gets called. Am I doing something wrong?
NOTES:
- my session or resource resolver are NOT null.
- AEM 6.3.1.0
Views
Replies
Total Likes
You are using Felix SRC annotations. Look at the SimpleResourceListener that uses DS annotations here - Creating an Adobe Experience Manager 6.3 Project using Adobe Maven Archetype 12
Views
Replies
Total Likes
At Adobe Experience Manager Help | Creating an Adobe Experience Manager Event Listener that tags pages they also use felix scr annotations, am I missing something?
Views
Replies
Total Likes
Hi,
We got this working as Scott mentioned above that we are using SimpleResourceListener class that uses DS annotations.
We will be releasing this article on early next week i.e., Monday or Tuesday!!
Watch this thread for more updates.
Thanks,
Ratna
Views
Replies
Total Likes
See here -- it will be posted here - Scott's Digital Community: Creating an AEM JCR Event Listener using a Maven Archetype 12 Project
Views
Replies
Total Likes
Hi,
In 6.3 we have an event listener working fine. Few thoughts on what we have done, in case it helps :
We have @Component, @Properties & @Service Annotations being used.
@Service
public class Sample implements ResourceChangeListener {
@Reference
private ResourceResolverFactory resourceResolverFactory;
protected ResourceResolver resourceResolver;
public void onChange(List<ResourceChange> changes) {
// Get the session object from the service user and the required logic.
}
Views
Replies
Total Likes
It works but only if I use the following code to retrieve a session:
observationSession = repository.loginAdministrative(null);
If I use the following my onEvent method is never called:
ResourceResolver serviceResourceResolver = resolverFactory.getServiceResourceResolver(AutoClosableResourceResolverFactory.getCredentials());
Any ideas? NOTE: we use the service user for our entire application (it has all rights)
Views
Replies
Total Likes
Seems to be a bug - i would whitelist the bundle and use that call. I see the same behaviour.
Views
Replies
Total Likes
Is your code picking up the correct service user?
Views
Replies
Total Likes
It is, we use the same method all over our code-base to modify all kind of node structures. smacdonald2008 seems to have the same issue.
Views
Replies
Total Likes
I am going to test deeper. It does seem to be a permission issue at some level. That is why i whitelisted the bundle - thereby giving permission for the code to use the admin call.
Views
Replies
Total Likes
I've read your article by now, is this bug being looked into, so I can use a serviceResourceResolver instead of the admin one?
Views
Replies
Total Likes
I triple checked this morning - while this code compiles -
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "eventwrite");
ResourceResolver resolver = null;
try {
//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
adminSession = resolver.adaptTo(Session.class);
adminSession.getWorkspace().getObservationManager().addEventListener(
Its not logging events. The only way it currently works is to use the admin call and whitelist the bundle.
I give system user all permissions and even tried adding them to the admin group. Still did not work.
Views
Replies
Total Likes
Any idea if this will be fixed in a hotfix or something?
Views
Replies
Total Likes
You can log a ticket - its possible Eng is not aware of this. To log a ticket - see Peter Nash thread in the pinned threads at the start of the community.
Views
Replies
Total Likes
I have the same issue too. Please let me know if there is a fix for this or alternate approach (without Admin credentials).
Appreciate your help!
Views
Replies
Total Likes
As we stated - there does not appear to be a way - i tested a lot using a System user. THe only way that worked was to WhiteList the bundle. You can log a bug to bring this issue to the Attention of AEM Eng team.
Views
Replies
Total Likes
I had a similar issue. It turns out in my case that the events were being fired and processed correctly but the Java debugger wasn't stopping inside the onEvent method. Unfortunately, I have had to use logging to troubleshoot rather than the debugger.
Views
Replies
Total Likes
Views
Likes
Replies