Page activation event handling | Community
Skip to main content
sathishreddy
New Participant
January 3, 2020
Solved

Page activation event handling

  • January 3, 2020
  • 2 replies
  • 3827 views

Hi,

I am trying to invoke event handler after page activation. Event handler is invoking for all activation's(like image,file and page) but I need to invoke handler when I activate pages from specific paths. I am using OSGI annotations not felix. Below is my code snippet 

@8220494(immediate = true, service = EventHandler.class, property = {

EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "(" + ReplicationAction.PROPERTY_PATH + "=/content/mypage/*)"

})
public class SimpleDSComponent implements Runnable, EventHandler {

private Logger log = LoggerFactory.getLogger(this.getClass());

public void handleEvent(Event event) {
String n[] = event.getPropertyNames();
log.info("Replication action: {} on {}", event.getProperty(ReplicationAction.PROPERTY_TYPE), event.getProperty(ReplicationAction.PROPERTY_PATH));
// log.info("Event occurred: {}", event.getProperty(WorkflowEvent.EVENT_TYPE));
log.info("Event properties: ");
for(String s : n) {
log.info(s + " = " + event.getProperty(s));
}
ReplicationAction action = ReplicationAction.fromEvent(event);
if(action != null) {
log.info("Replication action {} occured on {} ", action.getType().getName(), action.getPath());
}
log.info("");
}

 

When I use event filter handler is not invoking for any activation. I am suspecting event filter definition is wrong.

 

Can you please help me out how can I write filter with multiple paths.

 

Thanks,

Sathish

 

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

Hi,

It should work, I tried with below, it worked for me

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ReplicationEvent2.java

 

2 replies

arunpatidar
arunpatidarAccepted solution
New Participant
January 5, 2020

Hi,

It should work, I tried with below, it worked for me

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ReplicationEvent2.java

 

Arun Patidar
sathishreddy
New Participant
January 5, 2020

Hi Arun,

 

Thank you for your Reply.

 

Now handler is activating but it is activating for all pages and images irrespective of path. How can I restrict it. 

@8220494(immediate = true, service = EventHandler.class, property = {

EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "path=/content/mypage/en/help/*"

})

 

Thanks,

Sathish

New Participant
January 3, 2020

Try once by replacing EventConstants.EVENT_FILTER + "(" + ReplicationAction.PROPERTY_PATH + "=/content/mypage/*)"

to 

EventConstants.EVENT_FILTER + "=(" + ReplicationAction.PROPERTY_PATH + "=/content/mypage/*)"

or

EventConstants.EVENT_FILTER + "=(" + SlingConstants.PROPERTY_PATH) + "=/content/mypage/*)"

 

Regards

Albin I

https://www.albinsblog.com