AEM 6.3 Event problem | Community
Skip to main content
March 24, 2017

AEM 6.3 Event problem

  • March 24, 2017
  • 5 replies
  • 8378 views

Hi,

I would need some help regarding the AEM events for the 6.3 beta.

So far we used simple EventHandlers to observe repository changes. Unfortunately the support for the ChangedAttributeNames etc values within the event seems to be gone.

When I realized this I tried to implement the documentation suggested ResourceChangeListener, unfortunately the event is missing the attribute change informations too. Last option was to implement a JCR event listener that works fine as long I register this listener to the observerManager of a session that I got via

session = repository.login( new SimpleCredentials( ... ) )

this for I need login credentials within the code what is pretty uncomfortable.

This shows me that the jcr event contains the information pretty well but this is not added to the sling events properly.

Additionally to this we needed to adapt our code to use

resolver = resourceResolverFactory.getServiceResourceResolver( paramMap )

instead of the old administrative resourceResolver call.

So my idea was to combine both and register the eventListener to the observerManager of the serviceResolver session.

After some debugging I realized that the session I get via the repository login call is working for this while the session of the service resource resolver is not because it gets closed and seems to be just a temporary one, what seems kill the workspace and the observermanager.

So is it possible somehow to avoid this problem somehow? Or maybe is it possible to set the path value of the observed node by additionally specifying a special attribute to be observed instead?

 

thx,

Sven

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

Level 3
May 22, 2018

Why was this never addressed? We're having the same problem over a year later.

arunpatidar
Community Advisor
Community Advisor
May 22, 2018

Hi,

You can try below to get Session using below to observe JCR events.

session = repository.loginService("subservice-name", null);

More Info SlingRepository (Apache Sling 7 API)

Thanks

Arun

Arun Patidar
Level 3
May 22, 2018

Sorry, I'm not sure if I'm misunderstanding, but the problem I'm seeing that's similar is I don't see the property changed / property added messages from Events. It appears to have been removed in AEM 6.3.              

arunpatidar
Community Advisor
Community Advisor
May 22, 2018

Hi,

I am able to listen property changes in AEM 6.3

I have added JCR events like below:

protected void activate(ComponentContext context) throws Exception {

  session = repository.loginService("readService",null);

  observationManager = session.getWorkspace().getObservationManager();

  observationManager.addEventListener(this, Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED, "/content/AEM63App/fr/jcreventpage", true, null,

  new String[]{"cq:PageContent","nt:unstructured"} , true);

  //logger.debug("*************added JCR event listener");

  }

Could you please tell me what you are trying?

Arun Patidar
Level 3
May 22, 2018

You're using the EventListener, it looks like. Like the user above I tried a ResourceListener like this. I tried this code from Stack Overflow as a sanity check.

When I debug this the addedPropertyNames and changedPropertyNames properties of "change" are null. I would expect to see what changed here.

Level 3
May 22, 2018

So like I said in my own thread I opened​, I'm having trouble with the ResourceChangeListener. I haven't tried an EventListener yet. I'm worried that I'll go to the trouble of implementing it and land in the same place.

Level 3
May 22, 2018

arunp99088702​ - I just tried a sample of an EventListener and it worked. I was able to see which property changed. In their sample code ACS Commons warns against using this often, it seems, saying...

This is why I've been trying to get the ResourceChangeListener to work. Plus it seems more precise.     

arunpatidar
Community Advisor
Community Advisor
May 22, 2018

I try to get changed property using ResourceChangeListener

but according to documentation getChangedPropertyNames() is deprecated.

ResourceChange (Apache Sling 9 API)

I am not sure if there is any alternative to this method or use JCR Events Listeners instead of ResourceChangeListener

Arun Patidar
smacdonald2008
Level 10
May 23, 2018

Sometimes it seems things are noted deprecated without any replacement. It may be in that state for a long time. In some cases - you may need to still use that as there is no replacement method.

Level 3
June 7, 2018

I think this is what's throwing me off. When I think of deprecated I think of things that will be removed in the future. Not things that are being removed immediately. This feels like a documentation error on Adobe's part if I'm being honest. When I did the upgrade from 6.1 to 6.3 I explicitly looked for things that were being removed and dealt with those first. This wasn't noted as something that was being removed.