Highlighted

Event Handling in AEM 6.4

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

Replies

Highlighted

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

Highlighted

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

Screen Shot 2018-07-19 at 2.45.37 PM.png

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

Highlighted

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

Highlighted
Highlighted

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

Highlighted

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

Highlighted

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