Sling Servlets
Part 05 - Types of Servlets
Types of Sling Servlets
There are two classes in Sling API which can be inherited to define our custom functionality. These two classes are -
- SlingSafeMethodsServlet [org.apache.sling.api.servlets.SlingSafeMethodsServlet]
- SlingAllMethodsServlet [org.apache.sling.api.servlets.SlingAllMethodsServlet]
Let us discuss these types one by one
SlingSafeMethodsServlet
This 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's HttpServlet class which accounts for extensibility.
So extensions of this class have great control over what methods to override.
If any of the default HTTP methods are to be implemented just override the respective doXXX (doGet(), doHead() etc.) method.
This 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 override any of the doXXX methods of this class or add support for other read-only methods only.
SlingAllMethodsServlet
This is a helper base class for data modifying Servlets used in Sling. This class extends the SlingSafeMethodsServlet by support for the POST, PUT and DELETE methods. Thus, if we want to modify some data then we should use this base class.
Conclusion
In this blog post, we learnt about the types of Sling Servlets - SlingSafeMethodsServlet and SlingAllMethodServlet along with their code examples. You can find the complete code on my GitHub.
Comments
Post a Comment