Question--about registring Sling Servlets in different ways | Community
Skip to main content
New Participant
May 22, 2016
Solved

Question--about registring Sling Servlets in different ways

  • May 22, 2016
  • 1 reply
  • 1256 views

Hi All,

As per the documentation[0], we can create/register sling servlet in 4 ways.

1) Using Sling Annotation (@Slingservlet).

2) The @Properties and @Property annotations

3)Registration by Path

4) Registration by Resource Type

Could you please let me know  what is the difference between those? Advantage with each one and under what circumstances we have to use each one.

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

Thanks

k Chaianya

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 kautuk_sahni

Hi 

Please have a look at this community article for your help:-

Link:- https://hashimkhan.in/aem-adobecq5-code-templates/servlets/

//

There is reason why resourceType is much more preferential and suggested for writing SlingServlets. Below are the few reasons I could think of:

  1. While defining a path , you must be specific what all paths are allowed to be used in the ServletResource OSGi service. If you define something randomly, your servlet might not be fucntional. Only a limited paths are allowed and the rest are blocked unless you open them up. This is resolved using resourceType.
  2. You may have also configure the dispatcher , if you use some random path for your servlet. This might be a potential security threat and a needless configuration.
  3. You might also have to specify the paths to your consumers for your servlet and any change in that path could have a serious affect. This might not be the case when you use resourceType
  4.  the Sling Engine will take care of permissions for you. Users who cannot access a particular resource will not be able to invoke the servlet.

I hope this will be helpful to you.

Thanks and Regards

Kautuk Sahni

1 reply

kautuk_sahni
kautuk_sahniAccepted solution
Employee
May 24, 2016

Hi 

Please have a look at this community article for your help:-

Link:- https://hashimkhan.in/aem-adobecq5-code-templates/servlets/

//

There is reason why resourceType is much more preferential and suggested for writing SlingServlets. Below are the few reasons I could think of:

  1. While defining a path , you must be specific what all paths are allowed to be used in the ServletResource OSGi service. If you define something randomly, your servlet might not be fucntional. Only a limited paths are allowed and the rest are blocked unless you open them up. This is resolved using resourceType.
  2. You may have also configure the dispatcher , if you use some random path for your servlet. This might be a potential security threat and a needless configuration.
  3. You might also have to specify the paths to your consumers for your servlet and any change in that path could have a serious affect. This might not be the case when you use resourceType
  4.  the Sling Engine will take care of permissions for you. Users who cannot access a particular resource will not be able to invoke the servlet.

I hope this will be helpful to you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni