


rachanam1547401
rachanam1547401
19-07-2018
Hi,
We have various event handlers which are not working in 6.4 since various attributes(resourceChangedAttributes etc.) are removed from Sling Events. I was wondering if Adobe I/O Event handling can be a potential solution?? Has anyone tried this ?
Thanks,
Rachna
Arun_Patidar
MVP
Arun_Patidar
MVP
19-07-2018
smacdonald2008
smacdonald2008
19-07-2018
Agree with Arun - JCR Events are lower level API then Sling Events.
rachanam1547401
rachanam1547401
19-07-2018
Thanks both!
JCR Events has an issue when it comes to getting admin session, it's not allowing to get session using standard sys users way, and it requires to use deprecated method repository.loginAdministrative(null) & whitelisting the bundle to get the session;
I was thinking to go for higher level Page topics or Adobe I/O events for aem, any idea which is better compare to JCR events as deprecation is strongly discouraged as far as I know! I wanted to try Adobe I/O and it supports custom osgi events too.
Thanks,
Rachna
Arun_Patidar
MVP
Arun_Patidar
MVP
19-07-2018
Hi,
You can try below to get Session using below to observe JCR events.
session = repository.loginService("subservice-name", null);
you need to create subservice to use system user and create mapping through web console
e.g.
session = repository.loginService("readService", null);
this will create session with training-user
aem63app-repo/SampleJCRUGD.java at master · arunpatidar02/aem63app-repo · GitHub
Thanks
Arun
rachanam1547401
rachanam1547401
20-07-2018
Thanks Arun,
I have tried above option and after deploying it to 6.4, seems like I am getting null pointer exception when I am trying to get the session using repository.loginService("readService", null); and getting null value for the repository.
I have initialised repository using following line.
@Reference
private SlingRepository repository;
Thanks,
Rachna
Arun_Patidar
MVP
Arun_Patidar
MVP
20-07-2018
Hi Rachna,
did you created system user and provide all access and subservience for your bundle?
for me it works fine in 6.4
rachanam1547401
rachanam1547401
20-07-2018
Yes but it throws NP Exception because it doesn't get access to repository so when it tries to access .loginService on null object, it throws NPE
Thanks,
Rachna
Arun_Patidar
MVP
Arun_Patidar
MVP
20-07-2018
Hi
Can you check your imports?
Can you try getting subservience session from resourceResolverfactory just for test, it won't work for JCR events.
public Session getSubserviceSession() { | |
Session session = null; | |
Map<String, Object> paramMap = new HashMap<String, Object>(); | |
paramMap.put(ResourceResolverFactory.SUBSERVICE, "readService"); | |
try { | |
resourceResolver = resourceFactory.getServiceResourceResolver(paramMap); | |
// logger.debug("User id inside {}", resourceResolver.getUserID()); | |
session = resourceResolver.adaptTo(Session.class); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
logger.debug("getSubserviceSession : Unable to Login : " + e); | |
} | |
return session; | |
} | |
you can find the complete code for above example at below?
aem63app-repo/HandleSessionsImpl.java at master · arunpatidar02/aem63app-repo · GitHub
rachanam1547401
rachanam1547401
20-07-2018
Hi Arun,
thanks for the message.
Please find imports which I am using.
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.Session;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
Yes you are right, it doesn't work for JCR events.
Thanks,
Rachna