protected void doService()

in src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java [77:127]


    protected void doService(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        // According to the spec the path info is either null or
        // a string starting with a slash. Thus a string of length 1
        // will be a string containing just the slash, which should not
        // be handled by the base class
        final String pinfo = request.getPathInfo();
        if (pinfo != null && pinfo.length() > 1) {

            // regular request, have the SimpleWebDAVServlet handle the request
            super.service(request, response);

        } else if ("OPTIONS".equals(request.getMethod())) {

            // OPTIONS request on the root, answer with the Allow header
            // without DAV-specific headers
            response.setContentLength(0);
            response.setStatus(HttpServletResponse.SC_OK);
            response.setHeader("Allow", "OPTIONS, GET, HEAD");

        } else {

            // request to the "root", redirect to the default workspace if
            // directly addressing the servlet and if the default workspace name
            // is not null (in which case we'd need to login to find out the
            // actual workspace name, SLING-256)
            SlingRepository slingRepo = (SlingRepository) getRepository();
            if (slingRepo.getDefaultWorkspace() == null) {

                // if we don't have a default workspace to redirect to, we
                // cannot handle the request and fail with not found
                response.sendError(
                    HttpServletResponse.SC_NOT_FOUND,
                    "JCR workspace name required, please add it to the end of the URL"
                        + " (for the Jackrabbit embedded repository the default name is 'default') ");

            } else {

                // else redirect to the same URI with the default workspace
                // appended
                String uri = request.getRequestURI();
                if (pinfo == null) {
                    uri += "/";
                }
                uri += slingRepo.getDefaultWorkspace();
                response.sendRedirect(uri);

            }
        }
    }