Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Accessing OOTB Service/Servlet from Sling Servlets

Avatar

Level 2

Is there a way to access OOTB Sling service or servlet from an custom sling servlet? For instance, if I want to access OOTB servlet -  http://localhost:4502/bin/wcm/contentfinder/asset/view.json/content/dam from an Sling servlet and process results on top of that, how to access the service by path itself?

Note:  Looking for a solution without using HttpClient (in a REST way) ot by @Reference as I need to access through Path only.

1 Accepted Solution

Avatar

Correct answer by
Level 10
8 Replies

Avatar

Level 10

To invoke another AEM Service from a Sling Servlet - you use @Reference.

Avatar

Level 2

smacdonald2008 Thanks for the reply but I will not be able to use @Reference because I know only the path by which we can access the service (/bin/wcm/contentfinder/asset/view.json/content/dam). There should be some way to access the service right?

Avatar

Level 10

If you only know the path to a servlet - only possible way is to invoke it using HTTP.

Avatar

Level 2

The concerns I see with HTTP approach is authorization i.e., to access it on author environment.

Below is the requirement we are trying to fulfill - By OOTB, content finder images are loaded from /content/dam but the requirement is to filter this. We need to load the images only 2 folders with in /content/dam.

By analyzing the ootb code, we realized that we can read images only from one folder by modifying  /libs/wcm/extensions/contentfinder/images.js file.

We can update URL at "url": "/bin/wcm/contentfinder/asset/view.json/content/dam{/appspecfolder}" to the desired folder but we are unable to provide multiple folder paths here.

So our approach is to replace this service with a custom servlet and internally call the OOTB service twice and merge the results and use that to populate content finder.

Please let me know if there is a better way to solve this. Thanks in advance.

Avatar

Level 10

Creating custom Sling Servets in a valid approach. Most of the examples we have of Servlets - we use AJAX to invoke the servlet. BUt you can invoke it using supported HTTP methods.

Avatar

Level 2

Cool smacdonald2008, Is there any community article reference where service is being called from servlet through "path" but not by @Reference? and works in author environment seamlessly?

Avatar

Correct answer by
Level 10

Avatar

Level 3

try this-

RequestDispatcher dispatcher = request.getRequestDispatcher("/bin/wcm/contentfinder/asset/view.json/content/dam", opts);

dispatcher.include(request, response);