Sling Servlets | Community
Skip to main content
Jai1122
New Participant
October 16, 2015
Solved

Sling Servlets

  • October 16, 2015
  • 4 replies
  • 1735 views

    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

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 Lokesh_Shivalingaiah

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

4 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
New Participant
October 16, 2015

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

Employee
October 16, 2015

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 

Ratna_Kumar
New Participant
October 16, 2015

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.

Jai1122
Jai1122Author
New Participant
October 16, 2015

Thanks a ton for the responses!!!