Expand my Community achievements bar.

SOLVED

Sling Servlets

Avatar

Level 5

    Hi All,

        Can someone please tell me what is the difference between SlingAllMethodsServlet  and SlingSafeMethodServlet ?

We use them when writing servlets but i am not sure which should be given preference.

Thanks

Jai

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Jai,

Basically, SlingAllMethodsServlet is another layer of interface which extends SlingSafeMethodServlet which has doPost, doDelete and doPut operations for the request, response.

Refer [1] and [2] for more details on each interface

[1] https://sling.apache.org/apidocs/sling5/org/apache/sling/api/servlets/SlingSafeMethodsServlet.html

[2] https://sling.apache.org/apidocs/sling5/org/apache/sling/api/servlets/SlingAllMethodsServlet.html

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi Jai,

Basically, SlingAllMethodsServlet is another layer of interface which extends SlingSafeMethodServlet which has doPost, doDelete and doPut operations for the request, response.

Refer [1] and [2] for more details on each interface

[1] https://sling.apache.org/apidocs/sling5/org/apache/sling/api/servlets/SlingSafeMethodsServlet.html

[2] https://sling.apache.org/apidocs/sling5/org/apache/sling/api/servlets/SlingAllMethodsServlet.html

Avatar

Employee

Hi Jai, 

to add to the reply from bsloki, if your servlet will only ever be called with GET requests, then use SlingSafeMethodsServlet. If your servlet will be called with POST(and GET) requests, then use SlingAllMethodsServlet. 

From the documentation: 

SlingSafeMethodsServlet: Helper base class for read-only Servlets used in Sling

SlingAllMethodsServlet: Helper base class for data modifying Servlets used in Sling

 

Basically, if your servlet is not modifying anything in the repository, then use SlingSafeMethodsServlet.

Regards,

Opkar 

Avatar

Level 10

Hi Jai,

In Addition to that, also please check this development article that based on SlingAllMethodsServlet:

Submitting Adobe CQ form data to Java Sling Servletshttps://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html.

For deeper understanding of Sling in AEM, please go-through the recorded May session of ASK the AEM Expertshttp://scottsdigitalcommunity.blogspot.com/2015/05/may-session-of-aem-ask-community-experts.html , that will cover sling concepts in depth.

Thanks,
Ratna Kumar.

Avatar

Level 5

Thanks a ton for the responses!!!