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

AEM 6.3 - registering Servlets with paths

Avatar

Avatar
Validate 10
Level 3
brendanf9753525
Level 3

Likes

35 likes

Total Posts

58 posts

Correct Reply

6 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 10
Level 3
brendanf9753525
Level 3

Likes

35 likes

Total Posts

58 posts

Correct Reply

6 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile
brendanf9753525
Level 3

10-04-2018

Hi all,

I have a servlet that I am trying to register at the /feed path. It will be a servlet that takes GET requests and returns out some data.

My servlet has this path at the top when registering it.

@SlingServlet(paths = "/feed", methods = "GET", metatype = true)

I also went into the Apache Sling Servlet/Script Resolver and Error Handler and added the /feed/ path as one of the allowed scripts.

1462510_pastedImage_0.png

However, whenever I visit localhost:4502/feed, I get a 403 forbidden error. I see that it gets to my class and path, but it throws a 403 regardless.

However, If I move the servlet to /bin/feed, I can visit it successfully without a 403 error.

Is there a way to have servlets registered at paths without having the /bin/ path in front of them? I am pretty new to java servlets so any advice/suggestions would definitely go a long way.

Thanks

Brendan.

Replies

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

10-04-2018

I personally have only used syntax like:

@SlingServlet(paths="/bin/mySearchServlet", methods = "POST", metatype=true)

public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {

Why is using /bin an issue?

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

10-04-2018

Also - keep in mind - if you are using new DS OSGi annotations - then the syntax is

@Component(service=Servlet.class,

        property={

                Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

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

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

           })

public class SimpleServlet extends SlingAllMethodsServlet {

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

10-04-2018

Avatar

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile
Jineet_Vora
Level 4

02-12-2019

Per Apache Sling, there are different ways to register a servlet path.
If you want at first level then you have to register a servlet as '/feed.servlet' and then in 'Apache Sling Servlet/Script Resolver and Error Handler' configuration add '/feed.servlet' as your servlet execution path. Note that '.servlet' is expected and mandatory for first level servlet.
If you want to keep at second/more than one level then in the configuration, you have to specify the sub-tree like '/feed/' which will expect a servlet at any of the /feed/ sub-tree e.g. '/feed/fetchData' or '/feed/postData'


If you have given path as '/feed' or '/feed/' in configuration and calling the servlet with http://localhost:4502/feed , it won't work because Apache Sling expects a resource in this case and not a servlet execution script. A servlet script will only be executed in above two scenarios I mentioned.

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

583 likes

Total Posts

564 posts

Correct Reply

218 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

583 likes

Total Posts

564 posts

Correct Reply

218 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

02-12-2019

Hello Brendan,

It seems like you want to add some sugar coat your Sling Servlet Resolver script/path. Please check out this article where it will provide a solution on how you can write endpoints/paths in a more controlled way. It will reveal to you a strategy to hide all the extensions, selectors, paths, etc by doing this the Apache Rewriter Flag.

https://sourcedcode.com/sugar-coating-servlet-scripts-and-paths

I hope this helps!