Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Event Handling in AEM 6.4

Avatar

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
rachanam1547401
Level 3

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

19-07-2018

Hi,

you can use JCR events.

AEM 6.3 Event problem

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

19-07-2018

Agree with Arun - JCR Events are lower level API then Sling Events.

Avatar

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
rachanam1547401
Level 3

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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

Avatar

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
rachanam1547401
Level 3

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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

Service Users in AEM

Avatar

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
rachanam1547401
Level 3

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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

Avatar

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 3
rachanam1547401
Level 3

Likes

14 likes

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
rachanam1547401
Level 3

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