ResourceChangeListener onChange event not getting trigger | Community
Skip to main content
Level 2
April 23, 2019

ResourceChangeListener onChange event not getting trigger

  • April 23, 2019
  • 1 reply
  • 8807 views

Hi All,

the following code for onChange used to work in AEM 6.2 but after we migrated to 6.3 , I see onChange is not getting fired, not sure what is going wrong.

@Component(immediate = true)

@Service
@Properties(value = { @Property(name = ResourceChangeListener.PATHS, value = { CommunityConstants.CONTENT_ROOT_PATH }),

   @Property(name = ResourceChangeListener.CHANGES, value = { "ADDED", "CHANGED" }, propertyPrivate = true) })

public class xyz implements ResourceChangeListener {

@Reference
private ResourceResolverFactory resourceResolverFactory;

@Reference
private ContentModelService contentModelService;

@Override
public void onChange(@Nonnull List<ResourceChange> changes) {

//some logic here

}

}

Please help me to understand it further.

Many Thanks,

Kranthi

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

1 reply

joerghoh
Adobe Employee
Adobe Employee
April 23, 2019

Some basic checks first:

* Please check that the bundle containing this service is active.

* Please check that the component "xyz" is active (check on the Components list in the OSGI webconsole).

Jörg

smacdonald2008
Level 10
April 23, 2019

Issue is how session is obtained. You need to use a system user and give correct permissions. This works....

Component(immediate=true,

service= EventListener.class)

public class SimpleResourceListener implements EventListener{

 

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

     private Session adminSession;

     

    

     @Reference

     org.apache.sling.jcr.api.SlingRepository repository;

     

     @Activate

     public void activate(ComponentContext context) throws Exception {

     log.info("activating ExampleObservation");

     try {

         adminSession = repository.loginService("datawrite",null);

         adminSession.getWorkspace().getObservationManager().addEventListener(

          this, //handler

          Event.PROPERTY_ADDED|Event.NODE_ADDED, //binary combination of event types

          "/apps/example", //path

          true, //is Deep?

          null, //uuids filter

          null, //nodetypes filter

          false);

     

         

     } catch (RepositoryException e){

      log.error("unable to register session",e);

      throw new Exception(e);

     }

    }

    @Deactivate

    public void deactivate(){

     if (adminSession != null){

      adminSession.logout();

     }

    }

     

    public void onEvent(EventIterator eventIterator) {

      try {

        while (eventIterator.hasNext()){

          log.info("something has been added : {}", eventIterator.nextEvent().getPath());

        }

       } catch(RepositoryException e){

       log.error("Error while treating events",e);

      }

     }

    }

Level 2
April 25, 2019

Can you share your Apache Sling Service User Mapper service configuration:

It should be in below format because in point 4 above you shared is not correct format

Correct Format is below:

service-name:[sub-service-name]=system-user


Service-name: The service-name is the symbolic name of the bundle providing the service.

Sub-Service-Name:A Service may be comprised of multiple parts, so each part of the service may be further identified by a Subservice Name. This field is optional.

System-User :This will be the name of system user having access to get the resource.

com.demo.aem:dataService=dataUser


I still see  org.apache.sling.resourceresolver FrameworkEvent ERROR (java.lang.NullPointerException) in error.log file.

arunpatidar26

here is my Apache Sling Service User Mapper Service

com.xyz.help.content-engine-core-bundle:vulpe=vulpe

here vulpe is the system user