how to create a sling servlet which works across sites (with the sites URL), and cross language?

Avatar

Avatar
Affirm 5
Level 4
TB3dock
Level 4

Likes

37 likes

Total Posts

223 posts

Correct reply

5 solutions
Top badges earned
Affirm 5
Ignite 10
Boost 25
Give Back 25
Validate 10
View profile

Avatar
Affirm 5
Level 4
TB3dock
Level 4

Likes

37 likes

Total Posts

223 posts

Correct reply

5 solutions
Top badges earned
Affirm 5
Ignite 10
Boost 25
Give Back 25
Validate 10
View profile
TB3dock
Level 4

07-04-2021

We created some sling servlents following this tutorial: https://aem.redquark.org/2018/10/day-17-working-with-query-builder-api.html.  They make calls to a backend (player database), and pull in some content, and output json for the react page.  e.g. oursite.com/bin/api/oursevlet

 

This will work well for our first site (aka tenant?)

 

However, if we create a new site, with a new URL, we will want the same servlet, but with the new sites URL, e.g. ourothersite.com/bin/api/ourservlet, but this should pull in different content.

 

Presumably, we could duplicate the servlet, but it might also be possible to do a redirect or similar behind the scenes?  in this case, how would the servlet know which sites content to lookup?  We could pass in the URL as a parameter, assuming a servlet in one tenant can access content from another.

 

To a lesser extent, would translations be an issue, as the servlet would need to know which language content to look for?

View Entire Topic

Avatar

Avatar
Validate 25
MVP
Singaiah_Chintalapudi
MVP

Likes

131 likes

Total Posts

234 posts

Correct reply

39 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Ignite 5
Ignite 3
View profile

Avatar
Validate 25
MVP
Singaiah_Chintalapudi
MVP

Likes

131 likes

Total Posts

234 posts

Correct reply

39 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Ignite 5
Ignite 3
View profile
Singaiah_Chintalapudi
MVP

07-04-2021

I would use the same servlet for easy maintenance (even though you can have a redirect to a different servlet at CDN or dispatcher level)

 

  1. Same servlet and same query logic based on path (should pass in as a request param)
  2. If you are maintaining multiple sites then you've different farms tied to farm specific rewrites. Therefore, you just need to intercept this servlet request and append the path query param to the servlet
  3. This way, you've one servlet serving to both/more sites and search would be contained to those sites vs global

 

Let me know if you've any questions.

 

Thanks,

Singaiah