Hello All,
Any thoughts on how can we call a servlet based on the asset path, say /content/dam/cms/assetpath.
If I want to load a servlet if we hit any asset under this path.
Thanks,
Sateesh K.
Solved! Go to Solution.
Views
Replies
Total Likes
Technically you can register to any resource, but you cannot register a servlet by resourceType and specify the filter on it, instead, you could use a Sling servlet Filter, I would recommend exploring the Sling Filter first. Answering your question, the resource type to register an asset is "dam/Asset".
Another option could be to use a Workflow + WF Launcher to make sure a workflow is executed only under that asset.
Just for reference, this is how you will register the servlet for all the resources which are assets:
(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes="dam/Asset",
methods=HttpConstants.METHOD_GET,
extensions="txt")
@ServiceDescription("Simple Demo Servlet")
public class MyServlet extends SlingSafeMethodsServlet {
..
..
..
Then, you will invoke the servlet like this:
http://localhost:4502/content/dam/myasset.jpg.txt
Hope it helps
You can try with resource type servlet with selectors.
An example you will find here: https://aemsimplifiedbynikhil.wordpress.com/2020/10/16/calling-post-servlet-using-resourcetypesselec...
Sling servlet: Path vs Resource Type: https://medium.com/@toimrank/aem-sling-servlet-ca9e5926a384
Thanks for you reply but I am looking for more precise solution like if the asset path is /content/cms/asset/******/*****.pdf.
you can apply resource type with the extension ".pdf"
what will be the resourcetype of the asset here.
Oh, there is no resorceType property for dam:Asset. let me check if i found something will get back to you
Technically you can register to any resource, but you cannot register a servlet by resourceType and specify the filter on it, instead, you could use a Sling servlet Filter, I would recommend exploring the Sling Filter first. Answering your question, the resource type to register an asset is "dam/Asset".
Another option could be to use a Workflow + WF Launcher to make sure a workflow is executed only under that asset.
Just for reference, this is how you will register the servlet for all the resources which are assets:
(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes="dam/Asset",
methods=HttpConstants.METHOD_GET,
extensions="txt")
@ServiceDescription("Simple Demo Servlet")
public class MyServlet extends SlingSafeMethodsServlet {
..
..
..
Then, you will invoke the servlet like this:
http://localhost:4502/content/dam/myasset.jpg.txt
Hope it helps
Views
Likes
Replies