I am working on Listeners in AEM.
I wrote this code for JCREventHandler, I created system user for the same and added new configuration in Apache sling Service User Mapper Service Amendment.
But on running the code and on adding new node in apps/demo-website. I don't get the required result.
Also in error log I get:
package com.demo.website.core.listeners;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
@Component(immediate = true,service= EventListener.class)
public class JCREventHandler implements EventListener{
private static final Logger log = LoggerFactory.getLogger(JCREventHandler.class);
private Session session;
@Reference
SlingRepository slingRepository;
@Activate
public void activate() throws Exception {
log.info("Try block");
try {
log.info("inside try block");
String[] nodetypes={"cq:Page"};
session = slingRepository.loginService("testSystemUser",null);
session.getWorkspace().getObservationManager().addEventListener(
this, //handler
Event.PROPERTY_ADDED | Event.NODE_ADDED, //int code for event type
"/apps/demo-website", //path
true,
null, //UUIDs filter
nodetypes, //nodetypes filter
true);
} catch (RepositoryException e){
log.info(" \n Error while adding Event Listener : {} ",e.getMessage());
}
}
public void onEvent(EventIterator eventIterator) {
try {
log.info("abc");
while (eventIterator.hasNext()){
log.info("efg");
log.info("\n Path : {} ",eventIterator.nextEvent().getPath());
log.info("Hii");
}
} catch(Exception e){
log.error("\n Error while processing events : {} ",e.getMessage());
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
I think the system user is missing.
Please check the following article to create system user and do configurations
I think the system user is missing.
Please check the following article to create system user and do configurations
Views
Like
Replies