Expand my Community achievements bar.

SOLVED

Call AEM Servlet based on asset path

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 



Esteban Bustamante

View solution in original post

6 Replies

Avatar

Level 3

Thanks for you reply but I am looking for more precise solution like if the asset path is /content/cms/asset/******/*****.pdf. 

Avatar

Community Advisor

you can apply resource type with the extension ".pdf"

Avatar

Community Advisor

Oh, there is no resorceType property for dam:Asset. let me check if i found something will get back to you

Avatar

Correct answer by
Community Advisor

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

 



Esteban Bustamante