Interface NonExistingResourceServlet

  • All Superinterfaces:
    OptingServlet, Servlet

    public interface NonExistingResourceServlet
    extends OptingServlet
    NonExistingResourceServlet is a specific servlet interface for servlets that need to handle non-existing resources. Via the OptingServlet.accepts( method the implementing servlet must check if it will handle the given non-existing path.

    Please note: This is a temporary solution until Sling provides a built-in mechanism for this use case. Not to be used by client implementations!

    This servlet will not be registered directly with Sling but rather with a distinct dispatcher servlet that is registered for the GET, HEAD, POST and PUT HTTP methods on the sling:nonexisting resource ( NonExistingDispatcherServlet).

    To give a bit control over the order, set the standard OSGi property service.ranking (Integer) on the servlet to define an integer value for the order - the implementations with the highest number are called first. The first servlet that returns true in its OptingServlet.accepts( method will handle the request.

    Example code:

      public class TesterServlet extends SlingAllMethodsServlet implements NonExistingResourceServlet {
          public boolean accepts(SlingHttpServletRequest request) {
              // get non-existing path (incl. selectors and extension!)
              String path = request.getResource().getPath();
              // return true if this servlet can handle this path
              return true;
          protected void doGet(SlingHttpServletRequest request,
                      SlingHttpServletResponse response) throws ServletException,
                      IOException {
              // handle actual GET request here
              // ...