Event Listener Not Working Without Administrative Session | Community
Skip to main content
Tuhin_Ghosh
New Participant
June 15, 2017
Solved

Event Listener Not Working Without Administrative Session

  • June 15, 2017
  • 17 replies
  • 6864 views

Hello Everyone,

I am writing an EventListener but the onEvent() method is not getting called if I create the session by doing below:

Map<String, Object> param = new HashMap<>()
param.put(ResourceResolverFactory.SUBSERVICE, "SUBSERVICENAME")
resourceResolver = resourceResolverFactory.getServiceResourceResolver(param)
session = resourceResolver.adaptTo(Session.class)

however if I am creating the session by "repository.loginAdministrative(null)" the class is working as expected and the onEvent() is getting called. The latest example in the ACS Commons github is also getting the session by "repository.loginAdministrative(null)".
https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

But it is not advisable to use repository.loginAdministrative(null) to obtain the session, not to mention its also deprecated. I was just wondering if anyone have faced this before and have some possible solution.

Thanks and Regards,

Tuhin

P.S: My service user have all the permission it needs to do any kind of operation on node.

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

This looks like a bug. I would file a ticket to let the team know this is not working. LOoks like you are doing everything you are suppose to do.

17 replies

pavrda
New Participant
September 19, 2022

Guys, I realized the problem was in resourceResolver property. In my case when the property was local in activator, it did not work.

When the resourceResolver property is global in class, then it works.

 

Following works:

 

@Activate
public void start(BundleContext context) throws Exception {
    resourceResolver = resolverFactory.getServiceResourceResolver(null);
    session = resourceResolver.adaptTo(Session.class);
    observationManager = session.getWorkspace().getObservationManager();
    listener = new Listener(session);
    observationManager.addEventListener(listener, ...

Following does not work:

@Activate
public void start(BundleContext context) throws Exception {
    ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(null);
    session = resourceResolver.adaptTo(Session.class);
    observationManager = session.getWorkspace().getObservationManager();
    listener = new Listener(session);
    observationManager.addEventListener(listener, ...

It is weird and does not make much sense to me, but making resourceResolver class variable instead of method local solves it.

New Participant
June 16, 2022

Summer 2022 , AEM 6.5 SP9 and the same behavior.

New Participant
March 14, 2018

Hi,

I am also facing same issue. Do we have any fix for it?

New Participant
February 26, 2018

Hi Tuhin,

I am facing the same problem as you, is this problem resolved with sling evenhandler. Can you let me know any sample url which is using this.

Tuhin_Ghosh
New Participant
January 22, 2018

Hi,

Rather than using EventListener I started using the EventHandler which gives you the same functionality as event listener.

Thanks

Tuhin

New Participant
January 22, 2018

Did you fix this, I am experiencing the same issue.

Tuhin_Ghosh
New Participant
June 19, 2017

Hi Scott,

Seems like we have hit a dead end, I am using 6.2.

Reagards,

Tuhin

smacdonald2008
New Participant
June 16, 2017

Also - what AEM version are you using?

smacdonald2008
smacdonald2008Accepted solution
New Participant
June 16, 2017

This looks like a bug. I would file a ticket to let the team know this is not working. LOoks like you are doing everything you are suppose to do.

Tuhin_Ghosh
New Participant
June 15, 2017

Hi Jörg Hoh

I have added all permissions just to make sure that its not the permission issue specific to my user. But no luck.

Regards,

Tuhin