Replication is a process of activating/publishing a page and it's content from author to publish environment. AEM provide replication API to build a custom step that replicates content from the Author instance to the Publisher instance.
Replication using Replicator API
Initially, We need to create a Replicator instance by using @Reference annotation.
@Reference
private Replicator replicator;
Next, We need to create a session instance and then pass this object to replicate API. Here I have shared a sample code snippet for creating a session instance.
ResourceResolver resolver = request.getResourceResolver();
session = resolver.adaptTo(Session.class);
Finally, we need to pass the session instance and path to the replication API.
Here I have shared an example that will activate/deactivate web page based on a flag.
private void managePageActivation(Session session, String path,boolean isReplicate)
{
try {
if (isReplicate) {
replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
log.info("Page activated: ", path);
} else {
replicator.replicate(session, ReplicationActionType.DEACTIVATE, path);
log.info("Page De-activated: ", path);
}
} catch (ReplicationException e) {
log.info("Replication failed "+e.getMessage(), path);
e.printStackTrace();
}
}
In the above function will do the following things,
In my next post, I will explain how to activate/deactivate the content(asset and web page) by reading the path from an excel file.
I would like to hear your thoughts and suggestions from you to make it better.
Top comments (1)
Thanks for the post. i wanna replicate folder and its sub pages. i am sending the folder path in replicate method, but its not activating the sub pages, how can i achieve that? could u pls help