Accessing OOTB Service/Servlet from Sling Servlets | Community
Skip to main content
New Participant
November 24, 2017
Solved

Accessing OOTB Service/Servlet from Sling Servlets

  • November 24, 2017
  • 8 replies
  • 4816 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

8 replies

New Participant
November 25, 2017

try this-

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

dispatcher.include(request, response);

smacdonald2008
smacdonald2008Accepted solution
New Participant
November 24, 2017
New Participant
November 24, 2017

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?

smacdonald2008
New Participant
November 24, 2017

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.

New Participant
November 24, 2017

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.

smacdonald2008
New Participant
November 24, 2017

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

New Participant
November 24, 2017

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?

smacdonald2008
New Participant
November 24, 2017

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