Can you please to solve the null pointer exception in the handle event method.
Environment: AEMASCS
Below is the sample code which will execute when the content is published in this path(/content/dam).
paths is throwing the null pointer exception.
SlingConstants.PROPERTY_PATH = path
@Component(immediate = true, service = EventHandler.class, property = {
Constants.SERVICE_DESCRIPTION + "= This event handler listens the events on page activation",
EventConstants.EVENT_TOPIC + "=org/apache/sling/distribution/agent/package/distributed",
EventConstants.EVENT_FILTER + "=(&(distribution.paths=/content/dam/*) (|(distribution.type=ADD)(distribution.type=DELETE)))",
})
public class TestHandler implements EventHandler {
public void handleEvent(Event event) {
log.info("Testing on DEV...");
String[] paths = (String[]) event.getProperty(SlingConstants.PROPERTY_PATH);
}
Please help me.
Views
Replies
Total Likes
@Nishma I tried the same scenario in AEMaaCS and it worked for us. Please refer to below code snippet
@Component(immediate = true, property = { "event.topics=org/apache/sling/distribution/importer/package/imported",
"event.filter=(|(distribution.type=ADD)(distribution.type=DELETE))" })
public class AkamaiSlingDistributionEventHandler implements EventHandler {
public static final String DISTRIBUTION_PATHS = "distribution.paths";
@Override
public void handleEvent(Event event) {
if (event.getProperty(DISTRIBUTION_PATHS) != null) {
String[] pagePath = (String[]) event.getProperty(DISTRIBUTION_PATHS);
}
}
@Jagadeesh_Prakash Thanks for the response. Just want to check how you validated in your local server. since it will trigger when content distribution is configured. I'm unable to configure in the local server.
@Nishma There is no special configurations needed to do in local to test it. It should get triggered when ever there is any page or asset replication is done.
Or you can test in cloud dev environment as well
Views
Replies
Total Likes
@Jagadeesh_Prakash when ever we are publishing the assert sling content distribution will trigger(that setup i was unable to do in local). so i tried in dev environment by publishing the assert but still it is not triggering. Please suggest me. I got struck.
@Component(immediate = true, service = EventHandler.class, property = {
Constants.SERVICE_DESCRIPTION + "= This event handler listens the events on page activation",
EventConstants.EVENT_TOPIC + "=org/apache/sling/distribution/importer/package/imported",
EventConstants.EVENT_FILTER + "=(&(distribution.paths=/content/dam/test/*) (|(distribution.type=ADD)(distribution.type=DELETE)))",
})
public class TestHandler implements EventHandler {
private static final Logger log = LoggerFactory.getLogger(TestHandler.class);@Override
public void handleEvent(Event event) {
log.info("Testing on DEV...");
}}
Views
Replies
Total Likes
@Nishma Please check the logs in publisher and not in the author.
Views
Replies
Total Likes
@Nishma If still you are facing issue, try below one. But i recommand the previous post which worked for me and below code was working in local but not in the AEMcs environment.
Note: I removed some code. Please improvise and try according to your requirement
@Component(
service = EventHandler.class, configurationPolicy = ConfigurationPolicy.REQUIRE,
property = {EventConstants.EVENT_TOPIC+"=" + ReplicationAction.EVENT_TOPIC})
public class ReplicationListenerOnAuthor implements Runnable, EventHandler {
private BundleContext bundleContext;
@Override
public void handleEvent(Event event) {
if (isAuthor()) {
final ReplicationActionType replicationType = ReplicationAction.fromEvent(event).getType();
if (replicationType == ReplicationActionType.ACTIVATE || replicationType == ReplicationActionType.DEACTIVATE || replicationType == ReplicationActionType.DELETE)
{ // service call here
}
}
}
@Override
public void run() {
log.debug("{} Running...", this.getClass().getName());
}
@Activate
protected void activate(ComponentContext componentContext) {
bundleContext = componentContext.getBundleContext();
}
@Deactivate
protected void deactivate() {
bundleContext = null;
}
}
Views
Replies
Total Likes
Views
Likes
Replies