Locking unmapped URLs results in creation of that resource now, as specified in http://www.webdav.org/specs/rfc4918.html#rfc.section.9.10.4

This commit is contained in:
Sebastian Stenzel
2016-02-22 13:06:56 +01:00
parent ac4a68649e
commit 5df9f35065
4 changed files with 95 additions and 0 deletions

View File

@@ -21,6 +21,8 @@ import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.io.InputContext;
import org.apache.jackrabbit.webdav.io.OutputContext;
import org.apache.jackrabbit.webdav.lock.ActiveLock;
import org.apache.jackrabbit.webdav.lock.LockInfo;
import org.apache.jackrabbit.webdav.lock.LockManager;
import org.apache.jackrabbit.webdav.property.DavProperty;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
@@ -166,4 +168,13 @@ class DavFile extends DavNode<FileLocator> {
}
}
@Override
public ActiveLock lock(LockInfo reqLockInfo) throws DavException {
ActiveLock lock = super.lock(reqLockInfo);
if (!exists()) {
getCollection().addMember(this, new NullInputContext());
}
return lock;
}
}

View File

@@ -61,6 +61,7 @@ class DavFolder extends DavNode<FolderLocator> {
if (resource instanceof DavFolder) {
addMemberFolder((DavFolder) resource);
} else if (resource instanceof DavFile) {
assert inputContext.hasStream();
addMemberFile((DavFile) resource, inputContext.getInputStream());
} else {
throw new IllegalArgumentException("Unsupported resource type: " + resource.getClass().getName());

View File

@@ -0,0 +1,45 @@
package org.cryptomator.frontend.webdav.jackrabbitservlet;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.jackrabbit.webdav.io.InputContext;
public class NullInputContext implements InputContext {
@Override
public boolean hasStream() {
return true;
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(new byte[0]);
}
@Override
public long getModificationTime() {
return 0;
}
@Override
public String getContentLanguage() {
return null;
}
@Override
public long getContentLength() {
return 0;
}
@Override
public String getContentType() {
return null;
}
@Override
public String getProperty(String propertyName) {
return null;
}
}

View File

@@ -45,9 +45,13 @@ import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.client.methods.CopyMethod;
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
import org.apache.jackrabbit.webdav.client.methods.LockMethod;
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import org.apache.jackrabbit.webdav.lock.LockInfo;
import org.apache.jackrabbit.webdav.lock.Scope;
import org.apache.jackrabbit.webdav.lock.Type;
import org.cryptomator.filesystem.FileSystem;
import org.cryptomator.filesystem.ReadableFile;
import org.cryptomator.filesystem.WritableFile;
@@ -173,6 +177,40 @@ public class WebDavServerTest {
Assert.assertTrue(CollectionUtils.containsAll(hrefs, Arrays.asList(servletRoot + "/folder1/", servletRoot + "/folder2/", servletRoot + "/file1")));
}
/* LOCK */
@Test
public void testLockExisting() throws IOException, DavException {
final HttpClient client = new HttpClient();
// create file:
try (WritableFile writable = fs.file("foo.txt").openWritable()) {
writable.write(ByteBuffer.allocate(0));
}
// lock existing file:
LockInfo lockInfo = new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "le me", 3600, false);
final DavMethodBase lockMethod = new LockMethod(servletRoot + "/foo.txt", lockInfo);
final int lockResponse = client.executeMethod(lockMethod);
Assert.assertEquals(200, lockResponse);
lockMethod.releaseConnection();
}
@Test
public void testLockNonExisting() throws IOException, DavException {
final HttpClient client = new HttpClient();
// lock nonexisting file:
LockInfo lockInfo = new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "le me", 3600, false);
final DavMethodBase lockMethod = new LockMethod(servletRoot + "/foo.txt", lockInfo);
final int lockResponse = client.executeMethod(lockMethod);
Assert.assertEquals(201, lockResponse);
Assert.assertTrue(fs.file("foo.txt").exists());
lockMethod.releaseConnection();
}
/* MOVE */
@Test