Hi All,
What is the better approach to create a Servelet.
ResoureType or Path Based.
As per documentation it is ResourceType only.
But sometimes it happens that it exposes the internal Structure of AEM may be Content Structure or Component Structure.
It is ok to expose the internal Structure of AEM for creating a Servlet.
Any recommendations for this.
Solved! Go to Solution.
Views
Replies
Total Likes
@Sb2512 , You can make use of the proxy component pattern to avoid exposing the exact component location within AEM repo while using a resource type bound servlet.
Although, this is not the primary use case of using the proxy component pattern but it does give you this ability as well.
You can refer to the below documentation links to under stand how this works :
There is one similar thread comparing both.
Hope it helps!
Hi @Sb2512
As per sling documentation its recommended to go for resource type because of the following major reasons
Refer : https://sling.apache.org/documentation/the-sling-engine/servlets.html
Binding servlets by paths has several disadvantages when compared to binding by resource types, namely:
Given these drawbacks it is strongly recommended to bind servlets to resource types rather than paths.
In the specific case you highlighted we can control the resource bound one with ACLs and can prevent any potential misuse here
@Sb2512 , You can make use of the proxy component pattern to avoid exposing the exact component location within AEM repo while using a resource type bound servlet.
Although, this is not the primary use case of using the proxy component pattern but it does give you this ability as well.
You can refer to the below documentation links to under stand how this works :
If you are building apis that accept different parameters or may be upload some to process before responding back you can comfortably use path based servlet. Sling doesn't discourage path based servlets all together. But suggests usage of resource type based servlets when you intend to perform actions specific to a resource in context as it helps controlling the access based on the resource etc. Follow the links shared in other replies from our community members.
Views
Likes
Replies
Views
Likes
Replies