From 93334278f22dec9aaf6b8f8e923d16619a8d8bfe Mon Sep 17 00:00:00 2001 From: James William Dumay Date: Wed, 4 Jun 2008 00:29:27 +0000 Subject: [PATCH] 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 --- .../webdav/ArchivaDavResourceFactory.java | 4 +- .../webdav/RepositoryServletDeployTest.java | 19 +++++++++ .../httpunit/MkColMethodWebRequest.java | 39 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/httpunit/MkColMethodWebRequest.java 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"; + } +} -- 2.39.5