msmith      01/06/21 22:47:27

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        DeleteMethod.java WebdavMethod.java
  Log:
  When deleting a resource, if any error occurs, we produced a 207 multi-status.
  This confuses some clients (notable MS web-folders).
  
  So, instead: If the resource is a collection, use the full multi-status
  approach, since it's probably needed.
  If it's NOT a collection, a multi-status cannot be neccesary, so we just return
  the appropriate error code directly, so that it can be understood by less...
  able clients.
  
  Revision  Changes    Path
  1.8       +48 -17    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java
  
  Index: DeleteMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DeleteMethod.java 2001/03/23 05:08:29     1.7
  +++ DeleteMethod.java 2001/06/22 05:47:27     1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v
 1.7 2001/03/23 05:08:29 remm Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/03/23 05:08:29 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v
 1.8 2001/06/22 05:47:27 msmith Exp $
  + * $Revision: 1.8 $
  + * $Date: 2001/06/22 05:47:27 $
    *
    * ====================================================================
    *
  @@ -135,21 +135,52 @@
        */
       protected void executeRequest()
       throws WebdavException {
  -    
  -    try {
  -        macro.delete(slideToken, toDelete);
  +        boolean isCollection = isCollection(toDelete); 
  +        try {
  +            macro.delete(slideToken, toDelete);
               resp.setStatus(WebdavStatus.SC_NO_CONTENT);
  -        } 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 (DeleteMacroException dme) {
  +         // If it's not a collection, we don't want to give a 207,
  +            // because it's silly, and it confuses many clients (such as
  +            // MS Web Folders).
  +         if(isCollection) {
  +                String errorMessage = generateErrorMessage(dme);
  +                // 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 {
  +                Enumeration nestedExceptionsList =
  +                    dme.enumerateExceptions();
  +        
  +                SlideException ex =
  +                    (SlideException) nestedExceptionsList.nextElement();
  +                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.23      +25 -4     
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java
  
  Index: WebdavMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- WebdavMethod.java 2001/05/29 02:38:25     1.22
  +++ WebdavMethod.java 2001/06/22 05:47:27     1.23
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v
 1.22 2001/05/29 02:38:25 remm Exp $
  - * $Revision: 1.22 $
  - * $Date: 2001/05/29 02:38:25 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v
 1.23 2001/06/22 05:47:27 msmith Exp $
  + * $Revision: 1.23 $
  + * $Date: 2001/06/22 05:47:27 $
    *
    * ====================================================================
    *
  @@ -544,7 +544,28 @@
           return result;
       }
       
  -    
  +    /**
  +     * Test if a resource given by a path is a collection
  +     */
  +    protected boolean isCollection(String path) {
  +        NodeRevisionDescriptors revisionDescriptors;
  +        try {
  +            revisionDescriptors = content.retrieve(slideToken, path);
  +            
  +            if (revisionDescriptors.hasRevisions()) {
  +                NodeRevisionDescriptor revisionDescriptor =
  +                    content.retrieve(slideToken, revisionDescriptors);
  +                return(isCollection(revisionDescriptor));
  +            }
  +            else
  +                return true;
  +        } catch(SlideException e) { // Probably means the revision didn't
  +                                    // exist, so return true.
  +            return true;
  +        }
  +     }
  +                
  +         
       /**
        * Tests if a resource is a collection.
        */
  
  
  

Reply via email to