juergen 2002/10/16 05:23:59
Modified: src/webdav/server/org/apache/slide/webdav/method
UnlockMethod.java
Log:
Send an 412 response if the Lock-Token header is either missing or invalid.
(ralf)
Revision Changes Path
1.25 +58 -13
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnlockMethod.java
Index: UnlockMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnlockMethod.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- UnlockMethod.java 12 Aug 2002 12:55:02 -0000 1.24
+++ UnlockMethod.java 16 Oct 2002 12:23:58 -0000 1.25
@@ -96,6 +96,16 @@
public class UnlockMethod extends AbstractWebdavMethod {
+ /**
+ ** String constant for <code>Lock-Token header missing</code>.
+ **/
+ public static final String LOCK_TOKEN_HEADER_MISSING = "Lock-Token header
missing";
+
+ /**
+ ** String constant for <code>Lock-Token is not valid</code>.
+ **/
+ public static final String INVALID_LOCK_TOKEN = "Lock-Token is invalid";
+
// ----------------------------------------------------- Instance Variables
@@ -144,13 +154,13 @@
}
String lockTokenHeader = req.getHeader("Lock-Token");
- if (lockTokenHeader != null) {
- lockId = parseLockToken(lockTokenHeader);
- } else {
- // TODO : The call to UNLOCK is invalid
- System.out.println("Invalid call");
+ if (lockTokenHeader == null) {
+ sendError( WebdavStatus.SC_PRECONDITION_FAILED,
LOCK_TOKEN_HEADER_MISSING);
+ throw new WebdavException( WebdavStatus.SC_PRECONDITION_FAILED );
}
+ lockId = parseLockToken(lockTokenHeader);
+
}
@@ -164,11 +174,14 @@
// Prevent dirty reads
slideToken.setForceStoreEnlistment(true);
+ String errorMessage = null;
+ try {
- if (lockId != null) {
-
- try {
+ if (!canUnlock(slideToken, requestUri, lockId)) {
+ errorMessage = INVALID_LOCK_TOKEN;
+ throw new WebdavException(WebdavStatus.SC_PRECONDITION_FAILED);
+ }
lock.unlock(slideToken, requestUri, lockId);
@@ -217,14 +230,17 @@
} catch (Exception e) {
int statusCode = getErrorCode( e );
+ if (errorMessage != null) {
+ sendError(statusCode, errorMessage);
+ }
+ else {
sendError( statusCode, e );
+ }
throw new WebdavException( statusCode );
}
}
- }
-
@@ -254,5 +270,34 @@
return true;
}
+ /**
+ * Returns <code>true</code>, if the resource with the given
<code>objectUri</code>
+ * has either a lock with the given <code>lockID</code> or no lock at all.
+ *
+ * @param slideToken the SlideToken to use.
+ * @param objectUri the URI of the Object.
+ * @param lockID the lock ID to check.
+ *
+ * @return <code>true</code> if either a lock with the given
<code>lockID</code>
+ * , or no lock at all was found.
+ *
+ * @throws ServiceAccessException low level service access exception.
+ * @throws ObjectNotFoundException one of the objects referenced in
+ * the lock token were not found.
+ * @throws LockTokenNotFoundException cannot find the lock in the
+ * lock store service.
+ */
+ protected boolean canUnlock(SlideToken slideToken, String objectUri, String
lockID) throws ServiceAccessException, LockTokenNotFoundException,
ObjectNotFoundException {
+
+ Enumeration locksList = lock.enumerateLocks(slideToken, objectUri, false);
+ boolean foundLock = !locksList.hasMoreElements() ;
+ while ( !foundLock && locksList.hasMoreElements() ) {
+ NodeLock currentLock = (NodeLock) locksList.nextElement();
+ if (currentLock.getLockId().equals(lockId)) {
+ foundLock = true;
+ }
+ }
+ return foundLock;
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>