Class SlingAllMethodsServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
- Direct Known Subclasses:
AbstractAccessServlet,AbstractPostServlet
SlingSafeMethodsServlet by support for the POST,
PUT and DELETE methods.
Implementors note: The methods in this class are all declared to throw the exceptions according to the intentions of the Servlet API rather than throwing their Sling RuntimeException counter parts. This is done to easy the integration with traditional servlets.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoDelete(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP DELETE request.protected voiddoPost(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP POST request.protected voiddoPut(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP PUT request.protected @NotNull StringBuffergetAllowedRequestMethods(@NotNull Map<String, Method> declaredMethods) Helper method called bySlingSafeMethodsServlet.doOptions(SlingHttpServletRequest, SlingHttpServletResponse)to calculate the value of the Allow header sent as the response to the HTTP OPTIONS request.protected booleanisMethodValid(Method method, String className) Returnstrueifmethodis notnulland the method is not defined in the class named byclassName.protected booleanmayService(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) Tries to handle the request by calling a Java method implemented for the respective HTTP request method.Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doGet, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
-
Constructor Details
-
SlingAllMethodsServlet
public SlingAllMethodsServlet()
-
-
Method Details
-
doPost
protected void doPost(@NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP POST request.This default implementation reports back to the client that the method is not supported.
Implementations of this class should overwrite this method with their implementation for the HTTP POST method support.
- Parameters:
request- The HTTP requestresponse- The HTTP response- Throws:
javax.servlet.ServletException- Not thrown by this implementation.IOException- If the error status cannot be reported back to the client.
-
doPut
protected void doPut(@NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP PUT request.This default implementation reports back to the client that the method is not supported.
Implementations of this class should overwrite this method with their implementation for the HTTP PUT method support.
- Parameters:
request- The HTTP requestresponse- The HTTP response- Throws:
javax.servlet.ServletException- Not thrown by this implementation.IOException- If the error status cannot be reported back to the client.
-
doDelete
protected void doDelete(@NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException Called by themayService(SlingHttpServletRequest, SlingHttpServletResponse)method to handle an HTTP DELETE request.This default implementation reports back to the client that the method is not supported.
Implementations of this class should overwrite this method with their implementation for the HTTP DELETE method support.
- Parameters:
request- The HTTP requestresponse- The HTTP response- Throws:
javax.servlet.ServletException- Not thrown by this implementation.IOException- If the error status cannot be reported back to the client.
-
mayService
protected boolean mayService(@NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException Tries to handle the request by calling a Java method implemented for the respective HTTP request method.This implementation first calls the base class implementation and only if the base class cannot dispatch will try to dispatch the supported methods POST, PUT and DELETE and returns
trueif any of these methods is requested. Otherwisefalseis just returned.- Overrides:
mayServicein classSlingSafeMethodsServlet- Parameters:
request- The HTTP requestresponse- The HTTP response- Returns:
trueif the requested method (request.getMethod()) is known. Otherwisefalseis returned.- Throws:
javax.servlet.ServletException- Forwarded from any of the dispatched methodsIOException- Forwarded from any of the dispatched methods
-
getAllowedRequestMethods
@NotNull protected @NotNull StringBuffer getAllowedRequestMethods(@NotNull @NotNull Map<String, Method> declaredMethods) Helper method called bySlingSafeMethodsServlet.doOptions(SlingHttpServletRequest, SlingHttpServletResponse)to calculate the value of the Allow header sent as the response to the HTTP OPTIONS request.This implementation overwrites the base class implementation adding support for the POST, PUT and DELETE methods in addition to the methods returned by the base class implementation.
- Overrides:
getAllowedRequestMethodsin classSlingSafeMethodsServlet- Parameters:
declaredMethods- The public and protected methods declared in the extension of this class.- Returns:
- A
StringBuffercontaining the list of HTTP methods supported.
-
isMethodValid
Returnstrueifmethodis notnulland the method is not defined in the class named byclassName.This method may be used to make sure a method is actually overwritten and not just the default implementation.
- Parameters:
method- The Method to checkclassName- The name of class assumed to contained the initial declaration of the method.- Returns:
trueifmethodis notnulland the methods declaring class is not the given class.
-