AEM 6.5.11 - Replication Path Transformer is not working
We are using AEM 6.5.11. Architecture considers 1 Author connected to 2 Publishers, each Publisher connected to a corresponding dispatcher with a load balancer application gateway seating in front to balance out the load between the 2 dispatchers. There is no CDN in the ecosystem.
We are using Resource Resolver Factory settings for URL shortening to eliminate /content/mysite, /content/experience-fragments, and /content/dam/mysite from the URL paths on Publisher as well as on dispatcher.
The obvious side-effect is, on replication, the change is not taking effect on the end site as cache invalidation is not working due to shortening URLs. The dispatcher flush is not able to find the long path for invalidation and hence not able to invalidate it for updating from Publisher in the next request. Since we do not have CDN in consideration, I am not using custom ContentBuilder, rather I am using ReplicationPathTransformer to manipulate the path if the path contains "mysite" (so that other projects sharing the same instance don't get affected). I see the bundle Activated and the Replication Transformer class has been assigned Service ID. So I assume that it is loaded well. However, on replicating from the author, nothing gets triggered on Publisher project logs (which is getting updated properly) at DEBUG level.
We are not using ACS Commons as of now in our project, so not thinking of ACS Dispatcher Flush rules.
package xyz.core.service.impl;
import javax.jcr.Session;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.replication.Agent;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationPathTransformer;
import xyz.core.service.OsgiConfigurationService;
import xyz.core.utils.UrlUtil;
@Component(
service = MySiteReplicationPathTransformer.class,
name = "MySiteReplicationPathTransformer",
immediate = true)
public class MySiteReplicationPathTransformer implements ReplicationPathTransformer {
@OSGiService
OsgiConfigurationService osgiService;
public static final String MYSITE_PREFIX = "mysite";
/** The Logger */
private static final Logger LOGGER = LoggerFactory.getLogger(MySiteReplicationPathTransformer.class);
private String stripPageUrl;
private String stripFrgmntUrl;
private String stripAssetUrl;
@Override
public String transform(Session session, String replicationPath,
ReplicationAction replicationAction, Agent agent) {
LOGGER.debug("MySite Replication Path Transformer has been triggered successfully.");
if (StringUtils.isNotEmpty(replicationPath)
&& (StringUtils.contains(replicationPath, MYSITE_PREFIX))) {
LOGGER.debug("Replication Path Transformer: Source Path: {}", replicationPath);
if (null != osgiService) {
stripPageUrl = osgiService.getProperty(UrlUtil.STRING_PID_PROP,
UrlUtil.STRING_STRIPASSET_PROP, StringUtils.EMPTY);
stripFrgmntUrl = osgiService.getProperty(UrlUtil.STRING_PID_PROP,
UrlUtil.STRING_STRIPASSET_PROP, StringUtils.EMPTY);
stripAssetUrl = osgiService.getProperty(UrlUtil.STRING_PID_PROP,
UrlUtil.STRING_STRIPASSET_PROP, StringUtils.EMPTY);
}
// Content Pages
if (StringUtils.contains(replicationPath, stripPageUrl)) {
replicationPath = replicationPath.replaceAll(stripPageUrl, StringUtils.EMPTY);
// Experience Fragments
} else if (StringUtils.contains(replicationPath, stripFrgmntUrl)) {
replicationPath = replicationPath.replaceAll(stripFrgmntUrl, StringUtils.EMPTY);
// Digital Assets
} else if (StringUtils.contains(replicationPath, stripAssetUrl)) {
replicationPath = replicationPath.replaceAll(stripAssetUrl, StringUtils.EMPTY);
}
LOGGER.debug("Replication Path Transformer: Processed Path: {}", replicationPath);
}
return replicationPath;
}
@Override
public boolean accepts(Session session,
ReplicationAction replicationAction, Agent agent) {
/*
* Check if the agent is a dispatcher agent
* if it is the agent you are targeting, return true
*/
if (replicationAction.getType().equals(ReplicationActionType.ACTIVATE)
|| replicationAction.getType().equals(ReplicationActionType.DELETE)) {
return true;
}
return false;
}
}