Author: dkuleshov
Date: 2011-06-01 03:25:19 -0400 (Wed, 01 Jun 2011)
New Revision: 4468
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestLock.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java
Log:
EXOJCR-1358: fixed MOVE, MKCOL, COPY and some other methods responses statuses when trying
to access non-existing workspaces
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -528,14 +528,13 @@
}
else
{
- Session session = session(repoName, workspaceName(repoPath), null);
+ Session session = session(repoName, srcWorkspace, null);
if (session.getRootNode().hasNode(TextUtil.relativizePath(repoPath)))
{
return Response.status(HTTPStatus.PRECON_FAILED)
.entity("Item exists on destination path, while overwriting is
forbidden").build();
}
-
}
if (depth.getStringValue().equalsIgnoreCase("infinity"))
@@ -545,14 +544,12 @@
{
Session session = session(repoName, destWorkspace, lockTokens);
return new
CopyCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).copy(
- session,
- srcNodePath, destNodePath);
+ session, srcNodePath, destNodePath);
}
Session destSession = session(repoName, destWorkspace, lockTokens);
return new
CopyCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).copy(
- destSession,
- srcWorkspace, srcNodePath, destNodePath);
+ destSession, srcWorkspace, srcNodePath, destNodePath);
}
else if (depth.getIntValue() == 0)
@@ -577,6 +574,11 @@
{
return
Response.status(HTTPStatus.BAD_REQUEST).entity(exc.getMessage()).build();
}
+ catch (NoSuchWorkspaceException e)
+ {
+ log.error("NoSuchWorkspaceException " + e.getMessage(), e);
+ return Response.status(HTTPStatus.CONFLICT).entity(e.getMessage()).build();
+ }
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
@@ -774,7 +776,7 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (Exception exc)
@@ -864,7 +866,7 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
@@ -886,7 +888,7 @@
{
// to trace if an item on destination path exists
boolean itemExisted = false;
-
+
if (log.isDebugEnabled())
{
log.debug("MOVE " + repoName + "/" + repoPath);
@@ -915,7 +917,7 @@
{
return Response.status(HTTPStatus.BAD_GATEWAY).entity("Bad
Gateway").build();
}
-
+
destPath = normalizePath(repoIndex == -1 ? destPath :
destPath.substring(repoIndex + repoName.length() + 1));
String destWorkspace = workspaceName(destPath);
@@ -937,10 +939,9 @@
}
else
{
- Session session = session(repoName, workspaceName(repoPath), null);
+ Session session = session(repoName, srcWorkspace, null);
String uri =
-
uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(workspaceName(repoPath)).build()
- .toString();
+
uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(srcWorkspace).build().toString();
Response prpfind = new PropFindCommand().propfind(session, destNodePath,
body, depth.getIntValue(), uri);
if (prpfind.getStatus() != HTTPStatus.NOT_FOUND)
{
@@ -954,14 +955,14 @@
if (srcWorkspace.equals(destWorkspace))
{
Session session = session(repoName, srcWorkspace, lockTokens);
- return new
MoveCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).move(session,
- srcNodePath, destNodePath);
+ return new
MoveCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).move(
+ session, srcNodePath, destNodePath);
}
Session srcSession = session(repoName, srcWorkspace, lockTokens);
Session destSession = session(repoName, destWorkspace, lockTokens);
- return new
MoveCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).move(srcSession,
- destSession, srcNodePath, destNodePath);
+ return new
MoveCommand(uriInfo.getBaseUriBuilder().path(getClass()).path(repoName),
itemExisted).move(
+ srcSession, destSession, srcNodePath, destNodePath);
}
else
{
@@ -969,6 +970,11 @@
}
}
+ catch (NoSuchWorkspaceException e)
+ {
+ log.error("NoSuchWorkspaceException " + e.getMessage(), e);
+ return Response.status(HTTPStatus.CONFLICT).entity(e.getMessage()).build();
+ }
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
@@ -1058,7 +1064,7 @@
}
catch (NoSuchWorkspaceException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (PreconditionException exc)
{
@@ -1176,7 +1182,7 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (NoSuchNodeTypeException exc)
@@ -1373,7 +1379,8 @@
* @return current session
* @throws Exception {@link Exception}
*/
- protected Session session(String repoName, String wsName, List<String>
lockTokens) throws Exception
+ protected Session session(String repoName, String wsName, List<String>
lockTokens) throws Exception,
+ NoSuchWorkspaceException
{
ManageableRepository repo = this.repositoryService.getRepository(repoName);
SessionProvider sp = sessionProviderService.getSessionProvider(null);
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -349,6 +349,66 @@
assertEquals(content, getContentBase);
}
+ /**
+ * Here we're testing the case when we are trying to copy a resource C to a path
/A/B/C
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html#rfc.section.9.8.5>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testCopyResourceToNonExistingWorkspace() throws Exception
+ {
+ String folderName = "new folder";
+ session.getRootNode().addNode(folderName, "nt:folder");
+ session.save();
+
+ String content = TestUtils.getFileContent();
+ String filename = TestUtils.getFileName();
+ InputStream inputStream = new ByteArrayInputStream(content.getBytes());
+ TestUtils.addContent(session, filename, inputStream, defaultFileNodeType,
"");
+ String destFilename = TextUtil.unescape("/" + folderName +
TestUtils.getFileName(), '%');
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ // add destination header with incorrect data
+ headers.add(ExtHttpHeaders.DESTINATION, WORKSPACE + "_" + destFilename);
+
+ ContainerResponse response = service(WebDAVMethods.COPY, getPathWS() + filename,
host, headers, null);
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+
+ // add overwrite header to check the behavior
+ headers.add(ExtHttpHeaders.OVERWRITE, "T");
+ response = service(WebDAVMethods.COPY, getPathWS() + filename, host, headers,
null);
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+
+ // clean up
+ session.getRootNode().getNode(folderName).remove();
+ }
+
+ /**
+ * Here we're testing the case when we are trying to copy a collection B to a path
/A/B
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html#rfc.section.9.8.5>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testCopyCollectionToNonExistingWorkspace() throws Exception
+ {
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ // add destination header with incorrect data
+ headers.add(ExtHttpHeaders.DESTINATION, WORKSPACE + "_" + "/" +
"test");
+
+ ContainerResponse response =
+ service(WebDAVMethods.COPY, getPathWS() + TestUtils.getFolderName(), host,
headers, null);
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+
+ // add overwrite header to check the behavior
+ headers.add(ExtHttpHeaders.OVERWRITE, "T");
+ response = service(WebDAVMethods.COPY, getPathWS() + TestUtils.getFolderName(),
host, headers, null);
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+ }
+
@Override
protected String getRepositoryName()
{
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestLock.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestLock.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestLock.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -191,6 +191,20 @@
((Node)session.getItem(path)).unlock();
}
+ /**
+ * Here we're testing the case when we are trying to lock a resource C at a path
/A/B/C
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testLockForNonExistingWorkspace() throws Exception
+ {
+ ContainerResponse response =
+ service(WebDAVMethods.LOCK, getPathWS() + "_" + path, "",
null, lockRequestBody.getBytes());
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+ }
+
@Override
protected String getRepositoryName()
{
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -81,10 +81,17 @@
}
- @Override
- protected String getRepositoryName()
+ /**
+ * Here we're testing the case when we are trying to create a collection B at a
path /A/B
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html#rfc.section.9.3.1>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testMkColInNonExistingWorkspace() throws Exception
{
- return null;
+ String folder = TestUtils.getFolderName();
+ ContainerResponse response = service(WebDAVMethods.MKCOL, getPathWS() +
"_" + folder, "", null, null);
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
}
public void testConflict() throws Exception
@@ -94,4 +101,9 @@
assertEquals(HTTPStatus.CONFLICT, response.getStatus());
}
+ @Override
+ protected String getRepositoryName()
+ {
+ return null;
+ }
}
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -304,6 +304,25 @@
assertFalse(session.getRootNode().hasNode(TextUtil.relativizePath(filename)));
}
+ /**
+ * Here we're testing the case when we are trying to move a resource C to a path
/A/B/C
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html#rfc.section.9.3.1>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testMoveToNonCollectionToNonExistingWorkspace() throws Exception
+ {
+ String filename = TestUtils.getFileName();
+ String destFilename = TestUtils.getFileName();
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(ExtHttpHeaders.DESTINATION, host + getPathWS() + destFilename);
+
+ ContainerResponse response = service(WebDAVMethods.MOVE, getPathWS() +
"_" + filename, host, headers, null);
+
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+ }
+
@Override
protected String getRepositoryName()
{
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -469,6 +469,21 @@
}
+ /**
+ * Here we're testing the case when we are trying to get some resource C property
to a path /A/B/C
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testPropFindForNonExistingWorkspace() throws Exception
+ {
+ String file = TestUtils.getFileName();
+
+ ContainerResponse response =
+ service(WebDAVMethods.PROPFIND, getPathWS() + "_" + file,
"", null, null);
+ assertEquals(HTTPStatus.CONFLICT, response.getStatus());
+ }
+
@Override
protected String getRepositoryName()
{
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java 2011-06-01
06:42:07 UTC (rev 4467)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java 2011-06-01
07:25:19 UTC (rev 4468)
@@ -62,6 +62,22 @@
}
+ /**
+ * Here we're testing the case when we are trying to put some resource C to a path
/A/B/C
+ * and a A collection does not exist. According to the <a
href=http://www.webdav.org/specs/rfc4918.html>
+ * RFC 4918</a> section we are to receive 409(conflict) HTTP status.
+ * @throws Exception
+ */
+ public void testPutToNonExistingWorkspace() throws Exception
+ {
+ String content = TestUtils.getFileContent();
+ String path = TestUtils.getFileName();
+ ContainerResponse containerResponse =
+ service(WebDAVMethods.PUT, getPathWS() + "_" + path, "",
null, content.getBytes());
+ assertEquals(HTTPStatus.CONFLICT, containerResponse.getStatus());
+
+ }
+
public void testPutFileContentTypeHeader() throws Exception
{
String content = TestUtils.getFileContent();