Expand my Community achievements bar.

SOLVED

AEM Listeners:Error while adding Event Listener

Avatar

Level 3

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:

demo-website.core (577)] org.apache.sling.jcr.resource.internal.JcrSystemUserValidator The provided service user id 'serviceuser--demo-website.core--testSystemUser' is not a known JCR system user id and therefore not allowed in the Sling Service User Mapper.
28.09.2022 14:24:59.272 *INFO* [Background Update ranosys-website.core (577)] com.demo.website.core.listeners.JCREventHandler _ Error while adding Event Listener : Can neither derive user name nor principal names for bundle ranosys-website.core [577] and sub service testSystemUser
 
I am not able to get what is wrong in here. Can anyone guide me with what went wrong?
 
Thank you!

 

 

 

 

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());
}
}
}

 

 

 

 

 

 

 

 
 
 
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I think the system user is missing.

Please check the following article to create system user and do configurations 

https://experienceleague.adobe.com/docs/experience-manager-64/administering/security/security-servic... 



Arun Patidar

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

I think the system user is missing.

Please check the following article to create system user and do configurations 

https://experienceleague.adobe.com/docs/experience-manager-64/administering/security/security-servic... 



Arun Patidar