incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r885697 - /sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java
Date Tue, 01 Dec 2009 09:24:23 GMT
Author: fmeschbe
Date: Tue Dec  1 09:24:23 2009
New Revision: 885697

URL: http://svn.apache.org/viewvc?rev=885697&view=rev
Log:
SLING-1211 Streamline service method and add support for direct reply to the OPTIONS request
on the Dav root.

Modified:
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java

Modified: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java?rev=885697&r1=885696&r2=885697&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java
(original)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingSimpleWebDavServlet.java
Tue Dec  1 09:24:23 2009
@@ -51,47 +51,66 @@
     @Override
     public void init() throws ServletException {
         super.init();
-        
+
         setResourceConfig(resourceConfig);
     }
-    
+
     @Override
     protected void service(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())) {
 
-        if (pinfo == null || "/".equals(pinfo)) {
-            // 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)
+            // 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);
-            }
-
-        } else {
 
-            super.service(request, response);
+            }
         }
-
     }
 
     @Override
     public Repository getRepository() {
         return repository;
     }
-    
+
 }



Mime
View raw message