]> source.dussan.org Git - archiva.git/commitdiff
MRM-781 Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav
authorJames William Dumay <jdumay@apache.org>
Tue, 6 May 2008 15:40:22 +0000 (15:40 +0000)
committerJames William Dumay <jdumay@apache.org>
Tue, 6 May 2008 15:40:22 +0000 (15:40 +0000)
* I broke MRM-440, so this restores that functionality
* Locked down the enforcer plugin version so that Maven does not go looking for it everytime we build

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@653817 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/BrowserRedirectException.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocatorTest.java
pom.xml

index 089bb59973240f18937f9aa6c0c0384de06bdcfc..d33abbb9bccd2fe98a4aa16dffe9bbda5b8bfc34 100644 (file)
@@ -23,10 +23,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ConfigurationEvent;
 import org.apache.maven.archiva.configuration.ConfigurationListener;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.webdav.ArchivaDavLocatorFactory;
-import org.apache.maven.archiva.webdav.ArchivaDavResourceFactory;
-import org.apache.maven.archiva.webdav.ArchivaDavSessionProvider;
-import org.apache.maven.archiva.webdav.UnauthorizedDavException;
+import org.apache.maven.archiva.webdav.*;
 import org.apache.jackrabbit.webdav.server.AbstractWebdavServlet;
 import org.apache.jackrabbit.webdav.*;
 import org.codehaus.plexus.redback.system.SecuritySystem;
@@ -121,7 +118,12 @@ public class RepositoryServlet
             webdavResponse.setHeader("WWW-Authenticate", getAuthenticateHeaderValue(e.getRepositoryName()));
             webdavResponse.sendError(e.getErrorCode(), e.getStatusPhrase());
         }
-        catch (DavException e) {
+        catch (BrowserRedirectException e)
+        {
+            response.sendRedirect(e.getLocation());
+        }
+        catch (DavException e)
+        {
             if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
                 final String msg = "Should throw " + UnauthorizedDavException.class.getName();
                 log.error(msg);
index a26756dabf2e77140fc0a5e5c7e759d0d02aa83d..9570421e612396af5c63d6c86d52fc26f8a54683 100644 (file)
@@ -66,6 +66,4 @@ public class ArchivaDavLocatorFactory implements DavLocatorFactory
         final String repository = RepositoryPathUtil.getRepositoryName(path);
         return new ArchivaDavResourceLocator(prefix, path, repository, this);
     }
-
-
 }
index 7d58bbdecc7178a38942efb2f9e647f58e2b310e..0bf34a0fead80e1d082491e36f95e7c1ac7b2941 100644 (file)
@@ -129,7 +129,14 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
             {
                 throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get resource for method " + request.getMethod());
             }
+
             setHeaders(locator, response);
+
+            //compatibility with MRM-440 to ensure browsing the repository works ok
+            if (resource.isCollection() && !resource.getLocator().getResourcePath().endsWith("/"))
+            {
+                throw new BrowserRedirectException(resource.getHref());
+            }
         }
         return resource;
     }
index 9f8c68a335689bb413096782da47eab69679846a..80324232379dc6db6e5b9332c596ef2a0a42768c 100644 (file)
@@ -43,14 +43,18 @@ public class ArchivaDavResourceLocator implements DavResourceLocator, Repository
         this.prefix = prefix;
         this.repositoryId = repositoryId;
         this.davLocatorFactory = davLocatorFactory;
+        this.resourcePath = resourcePath;
+
+        String escapedPath = Text.escapePath(resourcePath);
+        String hrefPrefix = prefix;
 
-        // remove trailing '/' that is not part of the resourcePath except for the root item.
-        if (resourcePath.endsWith("/") && !"/".equals(resourcePath)) {
-            resourcePath = resourcePath.substring(0, resourcePath.length()-1);
+        //Ensure no extra slashes when href is joined
+        if (hrefPrefix.endsWith("/") && escapedPath.startsWith("/"))
+        {
+            hrefPrefix = hrefPrefix.substring(0, hrefPrefix.length()-1);
         }
-        this.resourcePath = resourcePath;
 
-        href = prefix + Text.escapePath(resourcePath);
+        href = hrefPrefix + escapedPath;
     }
 
     public String getRepositoryId()
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/BrowserRedirectException.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/BrowserRedirectException.java
new file mode 100644 (file)
index 0000000..b6c13df
--- /dev/null
@@ -0,0 +1,43 @@
+package org.apache.maven.archiva.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.jackrabbit.webdav.DavException;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class BrowserRedirectException extends DavException
+{
+    final String location;
+
+    public BrowserRedirectException(String location)
+    {
+        super(HttpServletResponse.SC_MOVED_PERMANENTLY);
+        this.location = location;
+    }
+
+    public String getLocation()
+    {
+        return location;
+    }
+}
index 04a480d29e624ea2f08050e8461ecff371dd1ab3..b7730c94dc6ba14b1373e776e3bb3d76393ed153 100644 (file)
@@ -40,7 +40,7 @@ public class ArchivaDavResourceLocatorTest extends TestCase
         throws Exception
     {
         String prefix = "http://myproxy/";
-        String href = "repository/internal";
+        String href = "/repository/internal";
         ArchivaDavResourceLocator locator = (ArchivaDavResourceLocator)factory.createResourceLocator(prefix, href);
 
         assertEquals("internal", locator.getRepositoryId());
@@ -49,8 +49,8 @@ public class ArchivaDavResourceLocatorTest extends TestCase
         assertEquals("http://myproxy/", locator.getPrefix());
         assertEquals("http://myproxy/repository/internal", locator.getHref(false));
         assertEquals("http://myproxy/repository/internal/", locator.getHref(true));
-        assertEquals("repository/internal", locator.getResourcePath());
-        assertEquals("repository/internal", locator.getRepositoryPath());
+        assertEquals("/repository/internal", locator.getResourcePath());
+        assertEquals("/repository/internal", locator.getRepositoryPath());
     }
 
     public void testLocatorWithHrefThatContainsPrefix()
@@ -81,8 +81,8 @@ public class ArchivaDavResourceLocatorTest extends TestCase
         assertEquals("", locator.getWorkspaceName());
         assertEquals("", locator.getWorkspacePath());
         assertEquals("http://myproxy/", locator.getPrefix());
-        assertEquals("http://myproxy//", locator.getHref(false));
-        assertEquals("http://myproxy//", locator.getHref(true));
+        assertEquals("http://myproxy/", locator.getHref(false));
+        assertEquals("http://myproxy/", locator.getHref(true));
         assertEquals("/", locator.getResourcePath());
         assertEquals("/", locator.getRepositoryPath());
     }
diff --git a/pom.xml b/pom.xml
index 3a712125c33d235c75248deff1833930fd17087e..af97ca1f1320c95e024b03b491c6ab34a733c665 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <jdkLevel>1.5</jdkLevel>
           </configuration>
         </plugin>
+               <plugin>
+                 <groupId>org.apache.maven.plugins</groupId>
+                 <artifactId>maven-enforcer-plugin</artifactId>
+                 <version>1.0-alpha-3</version>
+               </plugin>
       </plugins>
     </pluginManagement>
   </build>