Expand my Community achievements bar.

SOLVED

Difference between SlingAllMethodsServlet and SlingSafeMethodServlet

Avatar

Former Community Member

Hi,

While creating the servlet, which class we need to extend ? 

SlingAllMethodsServlet or SlingSafeMethodServlet ?

what is the basic difference between these two ? Can anyone explain this...

Thanks in advance.

 

 

 

 
1 Accepted Solution

Avatar

Correct answer by
Level 9

SlingSafeMethodServlet is a helper base class for read-only Servlets used in Sling. This base class is actually just a better implementation of the Servlet API HttpServlet class which accounts for extensibility. So extensions of this class have great control over what methods to overwrite.

SlingSafeMethodServlet  base class is intended for applications where data is only read. As such, this servlet by itself does not support the POST, PUT and DELETE methods. Extensions of this class should either overwrite any of the doXXX methods of this class or add support for other read-only methods only. Applications wishing to support data modification should rather use or extend the SlingAllMethodsServletwhich also contains support for the POST, PUT and DELETE methods. This latter class should also be overwritten to add support for HTTP methods modifying data.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 9

SlingSafeMethodServlet is a helper base class for read-only Servlets used in Sling. This base class is actually just a better implementation of the Servlet API HttpServlet class which accounts for extensibility. So extensions of this class have great control over what methods to overwrite.

SlingSafeMethodServlet  base class is intended for applications where data is only read. As such, this servlet by itself does not support the POST, PUT and DELETE methods. Extensions of this class should either overwrite any of the doXXX methods of this class or add support for other read-only methods only. Applications wishing to support data modification should rather use or extend the SlingAllMethodsServletwhich also contains support for the POST, PUT and DELETE methods. This latter class should also be overwritten to add support for HTTP methods modifying data.