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/ad...
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.
Solved! Go to Solution.
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.
Views
Replies
Total Likes
Did you configure the user id in Apache User Mapper Service ?
Also, debug the code and see if you are getting the resource resolver.
Views
Replies
Total Likes
Hi Rajeev,
The user is all good. Working fine for other classes. I am also getting the resource resolver. There isn't any error in the logs too.
thanks
Views
Replies
Total Likes
Did you try and put the System user in an admin group - did that work?
Did you check if your eventListener class is active when you are using System user to get session. Also, check error log if there is any error.
And if possible, use sling eventHandler instead of eventListener as mentioned at https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/j ava/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java
Views
Replies
Total Likes
Hi,
is your user capable to read the content areas, where the user is supposed to have read access to, and all nodes up to the root node? I've never faced your problem, but I could imagine, that internally some traversal is done, which requires these additional permissions.
kind regards,
Jörg
Hi Scott,
I have tried the same. It didn't work.
Regards,
Tuhin
Views
Replies
Total Likes
@Rajeev, I have tried everything, then only I have posted this question. The class is fine and active in OSGI, activate method working fine while activating the service. The URL you have mentioned is also mentioned in my question itself.
I know about Sling Event Handler, and that is an alternative. But why should a code is not working which is supposed to work that is my question.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Also - what AEM version are you using?
Views
Replies
Total Likes
Hi Scott,
Seems like we have hit a dead end, I am using 6.2.
Reagards,
Tuhin
Did you fix this, I am experiencing the same issue.
Views
Replies
Total Likes
Hi,
Rather than using EventListener I started using the EventHandler which gives you the same functionality as event listener.
Thanks
Tuhin
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Hi,
I am also facing same issue. Do we have any fix for it?
Views
Replies
Total Likes
Summer 2022 , AEM 6.5 SP9 and the same behavior.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes