How to have more than one path in "@SlingServletPaths" | Community
Skip to main content
Level 8
April 21, 2023
Solved

How to have more than one path in "@SlingServletPaths"

  • April 21, 2023
  • 3 replies
  • 2307 views

The fact that SlingServletPaths is plural implies we can add more than one. However, the syntax seems to be undocumented.  I have tired the following:

 

value = "/some/path1,/some/path2")

value = "[/some/path1,/some/path2]")

 

neither works, only if there is one or the other does it work (for that path)

 

Any ideas?

 

@Slf4j
@Component(service = {Servlet.class})
@SlingServletPaths(value = "/some/path1")
public class SomeServlet extends SlingAllMethodsServlet {

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @tb3dock,

According to documentation:

value param expects array of String, where each element in array represents single path.

This is the example how you can use it :

@Component(service = { Servlet.class }) @SlingServletPaths(value = {"/bin/path1", "/bin/path2"}) public class PathsServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse resp) throws ServletException, IOException { // place for your code } }

 

3 replies

somen-sarkar
Community Advisor
Community Advisor
April 21, 2023

Hi,

Could you check the same with below format ?

 

@8220494(service=Servlet.class,

name="Sample Servlet",

property={

"sling.servlet.methods=" + HttpConstants.METHOD_POST,

"sling.servlet.paths="+ "/bin/path1",

"sling.servlet.paths="+ "/bin/path2"

})

 

Thanks,

Somen

Rohit_Utreja
Community Advisor
Community Advisor
April 21, 2023

@tb3dock It can be done with the following code

@Component(
service = {Servlet.class},
property = {
"sling.servlet.paths=/bin/aem-integration/tasks",
"sling.servlet.paths=/bin/aem-integration/files",
"sling.servlet.extensions=json",
"sling.servlet.methods=GET"
}
)
public class RunModeServlet extends SlingAllMethodsServlet {

Please refer to below thread for more information

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/register-sling-servlet-or-any-service-dynamically-in-aem-aem/td-p/385472

 

Hope it helps!! 

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
April 22, 2023

Hi @tb3dock,

According to documentation:

value param expects array of String, where each element in array represents single path.

This is the example how you can use it :

@Component(service = { Servlet.class }) @SlingServletPaths(value = {"/bin/path1", "/bin/path2"}) public class PathsServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse resp) throws ServletException, IOException { // place for your code } }