juergen 01/07/17 06:46:22
Modified: src/webdav/server/org/apache/slide/webdav/method
CopyMethod.java
Log:
1) added more response code handling (423, 403, 409, ...)
2) in case of an error throw an exception to rollback the transaction in the calling
layer
Revision Changes Path
1.14 +47 -29
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java
Index: CopyMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CopyMethod.java 2001/07/06 04:29:32 1.13
+++ CopyMethod.java 2001/07/17 13:46:21 1.14
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
1.13 2001/07/06 04:29:32 msmith Exp $
- * $Revision: 1.13 $
- * $Date: 2001/07/06 04:29:32 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
1.14 2001/07/17 13:46:21 juergen Exp $
+ * $Revision: 1.14 $
+ * $Date: 2001/07/17 13:46:21 $
*
* ====================================================================
*
@@ -121,7 +121,7 @@
*/
public CopyMethod(GenericServlet servlet, NamespaceAccessToken token,
HttpServletRequest req, HttpServletResponse resp) {
- super(servlet, token, req, resp);
+ super(servlet, token, req, resp);
}
@@ -156,9 +156,9 @@
if (destinationUri.indexOf(":") != (-1)) {
destinationUri = destinationUri.substring(destinationUri.indexOf(":"));
}
-
-
+
+
if (destinationUri.startsWith(":")) {
int firstSeparator = destinationUri.indexOf("/");
if (firstSeparator < 0) {
@@ -172,7 +172,7 @@
String contextPath = req.getContextPath();
if ((contextPath != null) &&
- (destinationUri.startsWith(contextPath))) {
+ (destinationUri.startsWith(contextPath))) {
destinationUri = destinationUri.substring(contextPath.length());
}
@@ -180,7 +180,7 @@
if (pathInfo != null) {
String servletPath = req.getServletPath();
if ((servletPath != null) &&
- (destinationUri.startsWith(servletPath))) {
+ (destinationUri.startsWith(servletPath))) {
destinationUri = destinationUri
.substring(servletPath.length());
}
@@ -211,7 +211,7 @@
MacroParameters macroParameters = null;
String status = null;
- boolean isCollection = isCollection(sourceUri);
+ boolean isCollection = isCollection(sourceUri);
if (overwrite) {
macroParameters = Macro.RECURSIVE_OVERWRITE_PARAMETERS;
@@ -227,7 +227,7 @@
resp.setStatus(WebdavStatus.SC_CREATED);
}
} catch (CopyMacroException e) {
- if(isCollection) {
+ if(isCollection) {
String errorMessage = generateErrorMessage(e);
// Write it on the servlet writer
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
@@ -236,20 +236,34 @@
} catch(IOException ex) {
// Critical error ... Servlet container is dead or something
ex.printStackTrace();
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ throw new
WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
}
} else {
// Returning 207 on non-collection requests is generally
- // considered bad. So let's not do it, since this way
+ // considered bad. So let's not do it, since this way
// makes clients generally behave better.
- Enumeration nestedExceptions =
- e.enumerateExceptions();
- setErrorCode(resp,
-
(SlideException)nestedExceptions.nextElement());
+ Enumeration nestedExceptions = e.enumerateExceptions();
+ setErrorCode(resp, (SlideException)nestedExceptions.nextElement());
}
+ //
+ // make sure the transaction is aborted
+ // throw any WebDAV exception to indicate the transaction wants to be
aborted
+ //
+ throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
} catch(DeleteMacroException e) {
- resp.setStatus(WebdavStatus.SC_PRECONDITION_FAILED);
+ Enumeration nestedExceptions = e.enumerateExceptions();
+ SlideException sl = (SlideException)nestedExceptions.nextElement();
+ if (sl instanceof ObjectLockedException) {
+ resp.setStatus(WebdavStatus.SC_LOCKED);
+ }
+ else {
+ resp.setStatus(WebdavStatus.SC_PRECONDITION_FAILED);
+ }
+ //
+ // make sure the transaction is aborted
+ // throw any WebDAV exception to indicate the transaction wants to be
aborted
+ //
+ throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
}
}
@@ -343,10 +357,10 @@
printer.writeElement("d", "href", XMLPrinter.CLOSING);
printer.writeElement("d", "status", XMLPrinter.OPENING);
printer.writeText("HTTP/1.1 " + statusCode + " "
- + WebdavStatus.getStatusText(statusCode));
+ + WebdavStatus.getStatusText(statusCode));
printer.writeElement("d", "status", XMLPrinter.CLOSING);
}
-
+
/**
@@ -355,19 +369,23 @@
protected boolean methodNeedsTransactionSupport() {
return true;
}
-
- /**
- * Set return status based on exception type.
- */
- private void setErrorCode(HttpServletResponse resp, SlideException ex) {
+
+ /**
+ * Set return status based on exception type.
+ */
+ private void setErrorCode(HttpServletResponse resp, SlideException ex) {
try {
throw ex;
} catch(ObjectNotFoundException e) {
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
+ } catch(ConflictException e) {
+ resp.setStatus(WebdavStatus.SC_CONFLICT);
+ } catch(ForbiddenException e) {
+ resp.setStatus(WebdavStatus.SC_FORBIDDEN);
} catch(AccessDeniedException e) {
resp.setStatus(WebdavStatus.SC_FORBIDDEN);
} catch(ObjectAlreadyExistsException e) {
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ resp.setStatus(WebdavStatus.SC_PRECONDITION_FAILED);
} catch(ServiceAccessException e) {
resp.setStatus(WebdavStatus.SC_BAD_GATEWAY);
} catch(LinkedObjectNotFoundException e) {
@@ -379,8 +397,8 @@
} catch(SlideException e) {
resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
}
- }
-
+ }
+
}
-
+