CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

adobe/aem-cloud-service

All AEM as a Cloud Service skills: component development, Workflow model design, development, triggering, launchers, debugging, and triaging, Dispatcher config authoring, advisory, incident response, performance tuning, and security hardening, Rapid Development Environment (RDE) deployment, log inspection, snapshots, and troubleshooting via `aio aem rde`, Jackrabbit Oak query/index tuning (property, Lucene index definitions), and extracting/inventorying JCR queries (XPath, SQL2, QueryBuilder) across a codebase.

Quality

85%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

patterns.mdskills/content-distribution/replication/references/

Replication Patterns

Pattern 1: Auto-Publish on Content Fragment Save

@Component(service = EventHandler.class,
    property = EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_CHANGED)
public class AutoPublishContentFragmentHandler implements EventHandler {
    @Reference private Replicator replicator;
    @Reference private ResourceResolverFactory resolverFactory;

    @Override
    public void handleEvent(Event event) {
        String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
        if (path != null && path.startsWith("/content/dam") && isContentFragment(path)) {
            try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(
                    Map.of(ResourceResolverFactory.SUBSERVICE, "contentPublisher"))) {
                Session session = resolver.adaptTo(Session.class);
                replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
            } catch (Exception e) {
                LOG.error("Auto-publish failed for {}", path, e);
            }
        }
    }
}

Pattern 2: External Cache Purge After Publication

@Component(service = EventHandler.class,
    property = EventConstants.EVENT_TOPIC + "=com/day/cq/replication")
public class ExternalCachePurgeHandler implements EventHandler {
    @Reference private HttpClient httpClient;

    @Override
    public void handleEvent(Event event) {
        String action = (String) event.getProperty("action");
        if ("Activate".equals(action) || "Deactivate".equals(action)) {
            String[] paths = (String[]) event.getProperty("paths");
            if (paths != null) {
                for (String path : paths) {
                    purgeExternalCache(path);
                }
            }
        }
    }

    private void purgeExternalCache(String path) {
        try {
            HttpPost request = new HttpPost("https://cdn.example.com/purge");
            request.setHeader("Content-Type", "application/json");
            request.setEntity(new StringEntity("{\"path\":\"" + path + "\"}"));
            httpClient.execute(request);
        } catch (Exception e) {
            LOG.error("Cache purge failed for {}", path, e);
        }
    }
}

Pattern 3: Service User Setup for Replication

OSGi service user mapping config (ui.config/.../org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-myapp.cfg.json):

{
  "user.mapping": [
    "com.myapp.core:contentPublisher=myapp-replication-service"
  ]
}

Obtain the resolver in code:

@Reference private ResourceResolverFactory resolverFactory;

private ResourceResolver getServiceResolver() throws LoginException {
    return resolverFactory.getServiceResourceResolver(
        Map.of(ResourceResolverFactory.SUBSERVICE, "contentPublisher"));
}

The principal myapp-replication-service must have jcr:read + crx:replicate on /content, provisioned via Repo Init scripts.

skills

content-distribution

replication

README.md

SKILL.md

README.md

tile.json