Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

SlingSafeMethodsServlet: Why use this over HttpServlet?

kabelol26243436
Level 3
Level 3

Good day all. Some help understanding the above will be really appreciated.

I have a class that extends HttpServlet instead of SlingSafeMethodsServlet. I use @SlingServlet to expose a URL endpoint.

@SlingServlet(paths = "/apps/myapp") MyServlet extends HttpServlet { ... }

Everything works as expected of a servlet.

Looking at the source for SlingSafeMethodsServlet there aren't any obvious differences between SlingSafeMethodsServlet and HttpServlet. In fact the implementation of methods in SlingSafeMethodsServlet and SlingAllMethodsServlet are simply calls to HttpServlet methods. Have I not looked closely enough?

What are the concrete cases/examples of when you'd want to or have to extend SlingSafeMethodsServlet/SlingAllMethodsServlet instead of HttpServlet?

 

Edit: From SlingSafeMethodsServlet source

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

What does this mean exactly? Simply that it only allows for read methods "doGet" (write operations are to be found in SlingAllMethodsServlet)? Is that the entire extent of the difference between SlingSafeMethodsServlet and HttpServlet?

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10
1 Reply
smacdonald2008
Correct answer by
Level 10
Level 10