Passing content path to a Servlet through selectors fails -Need Suggestion

Avatar

Avatar

samr99530769

Avatar

samr99530769

samr99530769

09-02-2017

Hi All,

I have a requirement to build a latest article component which can be used across the many other site.

So I just thought of  creating a servlet which will query all the article under a path(/content/geo/article) which can be controlled by author and send me a JSON response.

Considering the caching startegy I need to pass the parameters as selectors .(Passing as query parameter will not allow me to cache the json until some new article is created)

For Example /bin.article.<limit>.<offset>.json .

Now I need to pass the pagepath lets say  /content/geo/article to servlet .Am not able to pass it as selector.Can anyone suggest me a solution for this.

Thanks,
Sambasivaraja.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jitendra_S_Toma

Avatar

Jitendra_S_Toma

Jitendra_S_Toma

09-02-2017

Hi Sameer,

In such case, we should not register our servlet with fixed path. Map your servlet with selector & resource Type (if resource is one for all article pages). And, when you are trying to call servlet, you currentPath.<selectors>.json as URL to invoke servlet.

Here is the code snippet.

@SlingServlet(resourceTypes = "/apps/page/articlePage",selectors = "article",extensions = "html",methods = "GET")public class DummyServlet extends SlingSafeMethodsServlet {@Overrideprotected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {...}}

URL would.. /content/mysite/pagearticle.article.limit.offset.html.

This is how you can invoke your servlet and pass current page path along with other parameters. Servlet would be resolved through selectors & resource type.

Answers (0)