Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

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

Avatar

Level 9

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 {

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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
    }
}

 

View solution in original post

3 Replies

Avatar

Level 6

Hi,

Could you check the same with below format ?

 

@component(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

Avatar

Community Advisor

@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-...

 

Hope it helps!! 

Avatar

Correct answer by
Community Advisor

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
    }
}