msmith 01/07/05 21:29:34
Modified: src/webdav/server/org/apache/slide/webdav/method
CopyMethod.java MoveMethod.java
Log:
Return specific status codes for non-collection COPY or MOVE. Currently,
we always use a 207 multistatus. This works, but isn't sensible, and can
cause problems for some people. (basically the same change as for DELETE
a couple of weeks ago).
Revision Changes Path
1.13 +51 -18
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- CopyMethod.java 2001/05/17 13:37:51 1.12
+++ CopyMethod.java 2001/07/06 04:29:32 1.13
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
1.12 2001/05/17 13:37:51 juergen Exp $
- * $Revision: 1.12 $
- * $Date: 2001/05/17 13:37:51 $
+ * $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 $
*
* ====================================================================
*
@@ -211,6 +211,7 @@
MacroParameters macroParameters = null;
String status = null;
+ boolean isCollection = isCollection(sourceUri);
if (overwrite) {
macroParameters = Macro.RECURSIVE_OVERWRITE_PARAMETERS;
@@ -226,19 +227,26 @@
resp.setStatus(WebdavStatus.SC_CREATED);
}
} catch (CopyMacroException e) {
- String errorMessage = generateErrorMessage(e);
- // Write it on the servlet writer
- //status = new String("HTTP/1.1 " + WebdavStatus.SC_MULTI_STATUS
- //+ " " + WebdavStatus.getStatusText
- //(WebdavStatus.SC_MULTI_STATUS));
- resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
- try {
- resp.getWriter().write(errorMessage);
- } catch(IOException ex) {
- // Critical error ... Servlet container is dead or something
- ex.printStackTrace();
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ if(isCollection) {
+ String errorMessage = generateErrorMessage(e);
+ // Write it on the servlet writer
+ resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
+ try {
+ resp.getWriter().write(errorMessage);
+ } catch(IOException ex) {
+ // Critical error ... Servlet container is dead or something
+ ex.printStackTrace();
+ 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
+ // makes clients generally behave better.
+ Enumeration nestedExceptions =
+ e.enumerateExceptions();
+ setErrorCode(resp,
+
(SlideException)nestedExceptions.nextElement());
}
} catch(DeleteMacroException e) {
resp.setStatus(WebdavStatus.SC_PRECONDITION_FAILED);
@@ -347,7 +355,32 @@
protected boolean methodNeedsTransactionSupport() {
return true;
}
-
-
+
+ /**
+ * 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(AccessDeniedException e) {
+ resp.setStatus(WebdavStatus.SC_FORBIDDEN);
+ } catch(ObjectAlreadyExistsException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(ServiceAccessException e) {
+ resp.setStatus(WebdavStatus.SC_BAD_GATEWAY);
+ } catch(LinkedObjectNotFoundException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(RevisionNotFoundException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(ObjectLockedException e) {
+ resp.setStatus(WebdavStatus.SC_LOCKED);
+ } catch(SlideException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+
}
+
1.12 +51 -28
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java
Index: MoveMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MoveMethod.java 2001/05/17 13:37:54 1.11
+++ MoveMethod.java 2001/07/06 04:29:32 1.12
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
1.11 2001/05/17 13:37:54 juergen Exp $
- * $Revision: 1.11 $
- * $Date: 2001/05/17 13:37:54 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
1.12 2001/07/06 04:29:32 msmith Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/07/06 04:29:32 $
*
* ====================================================================
*
@@ -206,6 +206,7 @@
throws WebdavException {
MacroParameters macroParameters = null;
+ boolean isCollection = isCollection(sourceUri);
if (overwrite) {
macroParameters = Macro.RECURSIVE_OVERWRITE_PARAMETERS;
@@ -220,36 +221,34 @@
} else {
resp.setStatus(WebdavStatus.SC_CREATED);
}
- } catch (DeleteMacroException e) {
- String errorMessage = generateErrorMessage(e);
- // Write it on the servlet writer
- resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
- try {
- resp.getWriter().write(errorMessage);
- } catch(IOException ex) {
- // Critical error ... Servlet container is dead or something
- ex.printStackTrace();
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
- } catch (CopyMacroException e) {
- String errorMessage = generateErrorMessage(e);
- // Write it on the servlet writer
- resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
- try {
- resp.getWriter().write(errorMessage);
- } catch(IOException ex) {
- // Critical error ... Servlet container is dead or something
- ex.printStackTrace();
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch (MacroException e) {
+ if(isCollection) {
+ String errorMessage = generateErrorMessage(e);
+ // Write it on the servlet writer
+ resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
+ try {
+ resp.getWriter().write(errorMessage);
+ } catch(IOException ex) {
+ // Critical error ... Servlet container is dead or something
+ ex.printStackTrace();
+ 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
+ // makes clients generally behave better.
+ Enumeration nestedExceptions =
+ e.enumerateExceptions();
+ setErrorCode(resp,
+
(SlideException)nestedExceptions.nextElement());
}
}
-
}
/**
+ /**
* Generate an XML error message.
*
* @param macroException Nested exception
@@ -348,7 +347,31 @@
protected boolean methodNeedsTransactionSupport() {
return true;
}
-
+
+ /**
+ * 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(AccessDeniedException e) {
+ resp.setStatus(WebdavStatus.SC_FORBIDDEN);
+ } catch(ObjectAlreadyExistsException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(ServiceAccessException e) {
+ resp.setStatus(WebdavStatus.SC_BAD_GATEWAY);
+ } catch(LinkedObjectNotFoundException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(RevisionNotFoundException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch(ObjectLockedException e) {
+ resp.setStatus(WebdavStatus.SC_LOCKED);
+ } catch(SlideException e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
}