I'm trying to debug a existing code where it's supposed to trigger when "Event.PROPERTY_CHANGED+Event.PROPERTY_ADDED" events happened but I don't think it's triggering.
Any ideas on how to help debug the code? (I want my breakpoint inside "onEvent" function to stop the execution)
Some info/observations:
protected void activate() {
try {
session = commonService.getSession(); //this is a custom service created by 3rd party
observationManager = session.getWorkspace().getObservationManager();
final String[] types = { "dam:Asset", "dam:AssetContent", "nt:unstructured", "nt:folder" };
final String path = "/content/dam/files";
final int events1 = Event.PROPERTY_CHANGED | Event.PROPERTY_ADDED | Event.NODE_ADDED;
observationManager.addEventListener(this, events1, path, true, null, types, false);
} catch(Exception e) {
log.error("bad stuff happened",e);
}
}
public void onEvent(EventIterator eventIterator) {
while (eventIterator.hasNext()){
Event event = eventIterator.nextEvent();
//insert more code here
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @jayv25585659 ,
If I understand correctly the problem might be in your
session = commonService.getSession();
The third-party session might not have enough user permission in your content path.
For better and fully proven code you can use a service-user and give that user permission[Read access] on the particular content node. The sample code will be like this,
@Reference
private SlingRepository repository;
@Activate
protected void activate() {
Session session = repository.loginService("your-service-user-name", null);
// Write your logic
}
@Deactivate
protected void deactivate() throws RepositoryException {
Session session = repository.loginService("your-service-user-name", null);
try {
if (observationManager != null)
observationManager.removeEventListener(this);
} finally {
if (session != null) session.logout();
}
}
Hello @jayv25585659 -
You can additionally try :
could you please also look for possible logging errors in error log?
Hello @jayv25585659
Service is Active?
Can you please check, if the Service is Active and (immediate=true) is set on the Listener?
https://medium.com/@toimrank/aem-handler-and-listener-12b6c8b5a3d3
Also, the signature of the activate() is different. Don't know if it matters, as Event Listener is old way of doing things, haven't worked on it for a while.
User has necessary access?
Please check the access levels of the user. If in doubt, add the user to administrators group and try triggering the events
Hello @jayv25585659 ,
If I understand correctly the problem might be in your
session = commonService.getSession();
The third-party session might not have enough user permission in your content path.
For better and fully proven code you can use a service-user and give that user permission[Read access] on the particular content node. The sample code will be like this,
@Reference
private SlingRepository repository;
@Activate
protected void activate() {
Session session = repository.loginService("your-service-user-name", null);
// Write your logic
}
@Deactivate
protected void deactivate() throws RepositoryException {
Session session = repository.loginService("your-service-user-name", null);
try {
if (observationManager != null)
observationManager.removeEventListener(this);
} finally {
if (session != null) session.logout();
}
}