Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

samr99530769
Level 3
Level 3

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.

1 Accepted Solution
Jitendra_S_Toma
Correct answer by
Level 9
Level 9

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.

View solution in original post

1 Reply
Jitendra_S_Toma
Correct answer by
Level 9
Level 9

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.

View solution in original post