Expand my Community achievements bar.

SOLVED

Question--about registring Sling Servlets in different ways

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Administrator

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

View solution in original post

1 Reply

Avatar

Correct answer by
Administrator

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