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
BedrockMission!

Learn More

View all

Sign in to view all badges

why do sling servlets only work with with a path of /bin/demo/xxx?

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

06-04-2021

I copied a sling servlet which had the path of /bing/demo/querybuilder

 

@Component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=Query Builder servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/demo/querybuilder" })
 
In creating our own sling servlets, we tried to change the path (e.g. to "/api/xxx/yy"), but no path other than /bin/demo/ seems to work. What is magical about this path?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct Reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct Reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

06-04-2021

Hi @TB3dock 

 

There is an OSGi Configuration named Apache Sling Servlet/Script Resolver and Error Handler in the felix console.

It has a property called "Execution Paths(servletresolver.paths)" which holds a list of absolute paths under which the servlet is accessible as a Resource.

By default bin is allowed in the resolver path which is why it works.

 

If you want your servlet with /api path to be accessible you will need to allow the path in the resolver paths. Please see the screenshot below:

 

asutosh_j3_0-1617731121541.png

It is recommended to use resource type based servlet over path based now. Please refer the link below:

https://sling.apache.org/documentation/the-sling-engine/servlets.html

 

Hope this helps!

Thanks!

Answers (1)

Answers (1)

Avatar

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
rush_pawan
Level 7

06-04-2021

hello, it is mainly for security and processing of request correctly, as i noticed. but apart from /bin you can also implement your servlet using resource type and selector like below

 

@SlingServlet(resourceTypes = "site/components/mypage",
selectors = "myselector",
extensions = "html",
methods = "GET",
metatype =true)

 

Thanks!!