juergen     2002/08/01 06:30:08

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        UpdateMethod.java
  Log:
  Fixed bug:
  In case of an error, a 207 mutlistatus should only be send if a Depth header is 
supplied.
  (ralf)
  
  Revision  Changes    Path
  1.11      +72 -12    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UpdateMethod.java
  
  Index: UpdateMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UpdateMethod.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- UpdateMethod.java 26 Jun 2002 05:00:01 -0000      1.10
  +++ UpdateMethod.java 1 Aug 2002 13:30:08 -0000       1.11
  @@ -82,6 +82,7 @@
   import org.apache.slide.common.RequestedPropertiesImpl;
   import org.apache.slide.common.PropertyParseException;
   import org.apache.slide.common.SlideException;
  +import org.apache.slide.common.NestedSlideException;
   import org.apache.slide.structure.SubjectNode;
   import org.apache.slide.structure.ObjectNode;
   import org.apache.slide.content.NodeProperty;
  @@ -272,23 +273,59 @@
           // Prevent dirty reads
           slideToken.setForceStoreEnlistment(true);
           
  -        try {
               Element multistatusElement = new Element(E_MULTISTATUS, 
NamespaceCache.DEFAULT_NAMESPACE);
               
  +        try {
               update(updateSourcePath, updateLabelName, resourcePath, getDepth(), 
multistatusElement);
  +        }
  +        catch (NestedSlideException nestedSlideException) {
  +            
  +            if ( (req.getHeader(H_DEPTH) == null) || 
(req.getHeader(H_DEPTH).length() == 0) ) {
  +                // do not send a 207 multistatus if the depth header is not set
  +                SlideException exception = 
(SlideException)nestedSlideException.enumerateExceptions().nextElement();
  +                resp.setStatus(getErrorCode(exception));  // special handling needed
  +                throw new WebdavException(getErrorCode(exception), false); // abort 
the TA
  +            }
  +        }
               
  +        try {
               resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
               resp.setContentType(TEXT_XML_UTF_8);
               new XMLOutputter(XML_REPONSE_INDENT, true).
                   output(new Document(multistatusElement), resp.getWriter());
           }
           catch (Exception e) {
  -            e.printStackTrace();
               resp.setStatus( getErrorCode(e) );  // special handling needed
  -            throw new WebdavException( WebdavStatus.SC_ACCEPTED, false ); // abort 
the TA
  +            throw new WebdavException(getErrorCode(e), false); // abort the TA
  +        }
  +    }
  +    
  +    /**
  +     * Updates the resource identified by <code>resourcePath</code>
  +     * with the properties and the content either of the resource identified
  +     * <code>updateSourcePath</code> or the version with the label
  +     * <code>updateLabelName</code> (only one of these parameters is set).
  +     * If <code>depth</code> is > 0, the operation is applied recursivly
  +     * to all children of the destination resource.
  +     *
  +     * @param      updateSourcePath    the URI of update source.
  +     * @param      updateLabelName     the label of the version used for the update.
  +     * @param      resourcePath        the URI of update destination.
  +     * @param      depth               the depth to use. If > 0, the update is
  +     *                                 applied recursivly.
  +     * @param      multistatusElement  the <code>&lt;multistatus&gt;</code> element
  +     *                                 to append the <code>&lt;response&gt;</code>
  +     *                                 elements to.
  +     */
  +    protected void update(String updateSourcePath, String updateLabelName, String 
resourcePath, int depth, Element multistatusElement) throws NestedSlideException {
  +        NestedSlideException nestedSlideException = new NestedSlideException(null);
  +        update(updateSourcePath, updateLabelName, resourcePath, depth, 
multistatusElement, nestedSlideException);
  +        if ( ! nestedSlideException.isEmpty() ) {
  +            throw nestedSlideException;
           }
       }
       
  +    
       /**
        * Updates the resource identified by <code>resourcePath</code>
        * with the properties and the content either of the resource identified
  @@ -306,7 +343,7 @@
        *                                 to append the <code>&lt;response&gt;</code>
        *                                 elements to.
        */
  -    protected void update(String updateSourcePath, String updateLabelName, String 
resourcePath, int depth, Element multistatusElement) {
  +    protected void update(String updateSourcePath, String updateLabelName, String 
resourcePath, int depth, Element multistatusElement, NestedSlideException 
nestedSlideException) {
           
           Element responseElement = new Element(E_RESPONSE, 
NamespaceCache.DEFAULT_NAMESPACE);
           multistatusElement.addContent(responseElement);
  @@ -337,8 +374,11 @@
               
               appendRequestedProps(resourcePath, responseElement);
           }
  -        catch (Exception e) {
  -            handleException(e, statusElement, responseElement);
  +        catch (SlideException e) {
  +            handleException(e, statusElement, responseElement, 
nestedSlideException);
  +        }
  +        catch (JDOMException e) {
  +            handleException(e, statusElement, responseElement, 
nestedSlideException);
           }
           
           // process children recursivly
  @@ -348,7 +388,8 @@
                          updateLabelName,
                              ((ObjectNode)childrenEnum.nextElement()).getUri(),
                          depth-1,
  -                       multistatusElement);
  +                       multistatusElement,
  +                       nestedSlideException);
               }
           }
       }
  @@ -406,11 +447,30 @@
        * Sets the appropriate status text and appends a &lt;responsedescription&gt;
        * element if a precondition has been violated.
        *
  -     * @param      exception        the Exception that occurred.
  +     * @param      exception             the JDOMException that occurred.
        * @param      statusElement    the &lt;status&gt; element.
        * @param      responseElement  the &lt;response&gt; element.
  +     * @param      nestedSlideException  the NestedSlideException to add the 
exception to.
        */
  -    private void handleException(Exception exception, Element statusElement, 
Element responseElement) {
  +    private void handleException(JDOMException exception, Element statusElement, 
Element responseElement, NestedSlideException nestedSlideException) {
  +        handleException(new SlideException("Nested exception: " + exception),
  +                        statusElement,
  +                        responseElement,
  +                        nestedSlideException);
  +    }
  +    
  +    /**
  +     * Sets the appropriate status text and appends a &lt;responsedescription&gt;
  +     * element if a precondition has been violated.
  +     *
  +     * @param      exception             the SlideException that occurred.
  +     * @param      statusElement         the &lt;status&gt; element.
  +     * @param      responseElement       the &lt;response&gt; element.
  +     * @param      nestedSlideException  the NestedSlideException to add the 
exception to.
  +     */
  +    private void handleException(SlideException exception, Element statusElement, 
Element responseElement, NestedSlideException nestedSlideException) {
  +        
  +        nestedSlideException.addException(exception);
   
           int errorCode = getErrorCode(exception);
           statusElement.setText(HTTP_VERSION + " " + errorCode  + " " +
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to