Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

What is the recommended way to retrieve content fragment ETag in AEM cloud without using Sites HTTP API?

Avatar

Level 1

I'm trying to retrieve the ETag of a content fragment in AEM as a cloud service for validation purposes. I would prefer not to use the Sites HTTP API (/adobe/sites/cf/fragment/{fragmentId} GET endpoint) as it introduces overhead from authentication and network latency. The AEM Content Fragment Core API (import com.adobe.cq.dam.cfm.ContentFragment) doesn't seem to expose any method to access the ETag.

 

Is there any recommended way to access the ETag or similar metadata using AEM's Java-based APIs?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 4

Hi @Imperfecto ,

 

You can generate a custom ETag-like value by computing a hash from key metadata properties of the CF. This can be done by accessing the underlying ValueMap or JCR properties such as jcr:title, cq:lastModified, or any other relevant fields by Resource Resolver and using them to compute a hash. This hash can serve as an ETag, allowing you to detect changes and perform validations without the overhead of HTTP requests or relying on the Sites HTTP API.

 

Let me know if it works or you need more help.

 

Thanks.

 

 

Avatar

Community Advisor

Hi @Imperfecto,

Unfortunately, you are right - the ContentFragment interface from the AEM Content Fragment Core API (com.adobe.cq.dam.cfm.ContentFragment) does not expose the ETag directly, and there’s no out-of-the-box method in the public Java APIs to retrieve an ETag the same way the HTTP API does.

Here are some possible workarounds - not perfect, but might help depending on your use case:

1. AEM typically calculates ETags using internal logic based on the last modification timestamp or binary checksum.

If your purpose is to do change detection, you might simulate your own ETag by hashing:

  • jcr:lastModified

  • Fragment element values

  • Metadata properties

Resource cfResource = resolver.getResource("/content/dam/your/fragment/path");
ValueMap vm = cfResource.getValueMap();
Calendar lastModified = vm.get("jcr:lastModified", Calendar.class);

// Optional: hash the actual element values if you want a more detailed "etag"

Generate an MD5/SHA hash of those values - that can act as a pseudo-ETag.

2. If you're trying to know when something changed, and not necessarily retrieve the ETag itself, you can set up a ResourceChangeListener on the /content/dam path to detect changes to fragments, and cache/track accordingly.

hope that helps!


Santosh Sai

AEM BlogsLinkedIn