From: James William Dumay Date: Tue, 6 May 2008 15:40:22 +0000 (+0000) Subject: MRM-781 Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav X-Git-Tag: archiva-r676265~156 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=584bd356c2e7ee6b6aa720e49016f926e48bd754;p=archiva.git MRM-781 Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav * 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 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java index 089bb5997..d33abbb9b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java @@ -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); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java index a26756dab..9570421e6 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java @@ -66,6 +66,4 @@ public class ArchivaDavLocatorFactory implements DavLocatorFactory final String repository = RepositoryPathUtil.getRepositoryName(path); return new ArchivaDavResourceLocator(prefix, path, repository, this); } - - } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java index 7d58bbdec..0bf34a0fe 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java @@ -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; } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java index 9f8c68a33..803242323 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java @@ -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 index 000000000..b6c13dfe0 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/BrowserRedirectException.java @@ -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 James William Dumay + */ +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; + } +} diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocatorTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocatorTest.java index 04a480d29..b7730c94d 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocatorTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocatorTest.java @@ -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 3a712125c..af97ca1f1 100644 --- a/pom.xml +++ b/pom.xml @@ -162,6 +162,11 @@ 1.5 + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0-alpha-3 +