From: James William Dumay Date: Wed, 4 Jun 2008 00:29:27 +0000 (+0000) Subject: MRM-781 - Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav X-Git-Tag: archiva-r676265~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=93334278f22dec9aaf6b8f8e923d16619a8d8bfe;p=archiva.git MRM-781 - Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav * Changed so that non-existant parent directories are only created on PUT and not on MKCOL. This allows better litmus compliance. * Added MkColMethodWebRequest which implements the MkCol method for HttpUnit * Unit tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@662933 13f79535-47bb-0310-9956-ffa450edef68 --- 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 71ae2c27c..d73f4f194 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 @@ -78,6 +78,8 @@ import org.apache.jackrabbit.webdav.lock.SimpleLockManager; public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable { + private static final String HTTP_PUT_METHOD = "PUT"; + private Logger log = LoggerFactory.getLogger( ArchivaDavResourceFactory.class ); /** @@ -321,7 +323,7 @@ public class ArchivaDavResourceFactory File rootDirectory = new File( managedRepository.getRepoRoot() ); File destDir = new File( rootDirectory, logicalResource.getPath() ).getParentFile(); - if ( !destDir.exists() ) + if ( request.getMethod().equals(HTTP_PUT_METHOD) && !destDir.exists() ) { destDir.mkdirs(); String relPath = PathUtil.getRelative( rootDirectory.getAbsolutePath(), destDir ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java index 32ef17d20..05c0db18d 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletDeployTest.java @@ -23,9 +23,11 @@ import com.meterware.httpunit.PutMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; +import java.io.File; import java.io.InputStream; import javax.servlet.http.HttpServletResponse; +import org.apache.maven.archiva.webdav.httpunit.MkColMethodWebRequest; /** @@ -53,6 +55,23 @@ public class RepositoryServletDeployTest assertFileContents( "artifact.jar\n", repoRootInternal, "path/to/artifact.jar" ); } + public void testMkColWithMissingParentCollectionFails() + throws Exception + { + setupCleanRepo( repoRootInternal ); + + String putUrl = "http://machine.com/repository/internal/path/to/"; + + WebRequest request = new MkColMethodWebRequest( putUrl ); + + WebResponse response = sc.getResponse( request ); + + assertEquals(HttpServletResponse.SC_CONFLICT, response.getResponseCode()); + + File mkColLocalPath = new File(repoRootInternal, "path/to/"); + assertFalse(mkColLocalPath.exists()); + } + protected void assertResponseCreated( WebResponse response ) { assertNotNull( "Should have recieved a response", response ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/httpunit/MkColMethodWebRequest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/httpunit/MkColMethodWebRequest.java new file mode 100644 index 000000000..c2353a686 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/httpunit/MkColMethodWebRequest.java @@ -0,0 +1,39 @@ +package org.apache.maven.archiva.webdav.httpunit; + +/* + * Copyright 2008 jdumay. + * + * Licensed 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. + * under the License. + */ + +import com.meterware.httpunit.HeaderOnlyWebRequest; +import java.net.URL; + +/** + * MkColMethodWebRequest + * See RFC-2518 Section 8.3 + * @author James William Dumay + */ +public class MkColMethodWebRequest extends HeaderOnlyWebRequest +{ + public MkColMethodWebRequest( String urlString ) + { + super(urlString); + } + + @Override + public String getMethod() { + return "MKCOL"; + } +}