Event Listener Not Working Without Administrative Session | Community
Skip to main content
Tuhin_Ghosh
Level 8
Jun 15, 2017 7:12 AM UTC
Solved

Event Listener Not Working Without Administrative Session

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.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 16, 2017 12:17 PM UTC

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
Level 4
Sep 19, 2022 12:40 PM UTC

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.

Translate
New Participant
Jun 16, 2022 5:54 PM UTC

Summer 2022 , AEM 6.5 SP9 and the same behavior.

Translate
Level 2
Mar 14, 2018 1:41 PM UTC

Hi,

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

Translate
New Participant
Feb 26, 2018 5:11 AM UTC

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.

Translate
Tuhin_Ghosh
Level 8
Jan 22, 2018 9:52 AM UTC

Hi,

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

Thanks

Tuhin

Translate
Level 4
Jan 22, 2018 9:27 AM UTC

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

Translate
Tuhin_Ghosh
Level 8
Jun 19, 2017 6:10 AM UTC

Hi Scott,

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

Reagards,

Tuhin

Translate
smacdonald2008
Level 10
Jun 16, 2017 12:17 PM UTC

Also - what AEM version are you using?

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Jun 16, 2017 12:17 PM UTC

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.

Translate
Tuhin_Ghosh
Level 8
Jun 15, 2017 10:51 PM UTC

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

Translate