lookfirst / sardine

an easy to use webdav client for java
Other
583 stars 186 forks source link

Copying files on locked folders gives no indication that the copying was not successful #210

Closed jojomay24 closed 1 year ago

jojomay24 commented 9 years ago

Consider following pseudo - code snippet:

Sardine sardine = SardineFactory.begin();
String token = sardine.lock("http://.../someRemoteDir/");
sardine.put("http://.../someRemoteDir/testFile", fileContentAsByteArray);
sardine.unlock("http://.../someRemoteDir/",token);

Since the webdav directory "someRemoteDir" is locked, the subsequent sardine.put does not copy data into that directory, which is correct behaviour. However, sardine does not throw any Exception neither does it return success/failure since it is a void method. As consequence, the programmer has no chance to somehow realize that the sardine.put(...) did not yield the expected result. and the file was not copied. May be an exception would be a good idea?

dkocher commented 9 years ago

It is expected to throw a HttpResponseException.

jojomay24 commented 9 years ago

I researched a little more, what really happens is: Since the directory is locked, the apache responds with Http 207 Multi-Status. This MultiStatus response contains 2 elements: One is a Http 424 failed dependency, another is a Http 423 Locked. However, since the main response is a 2xx Status, I suppose this is the reason why there is no HttpResponseException. According to webdav rfc 4918,chapter 13, "the recipient needs to consult the contents of the multistatus response body for further information about the success or failure of the method execution". See an XML excerpt as an example for such an multistatus response:

Hypertext Transfer Protocol
    HTTP/1.1 207 Multi-Status\r\n
        [Expert Info (Chat/Sequence): HTTP/1.1 207 Multi-Status\r\n]
            [Message: HTTP/1.1 207 Multi-Status\r\n]
            [Severity level: Chat]
            [Group: Sequence]
        Request Version: HTTP/1.1
        Status Code: 207
        Response Phrase: Multi-Status
    Date: Fri, 15 May 2015 13:14:52 GMT\r\n
    Server: Apache/2.4.7 (Ubuntu)\r\n
    Content-Length: 736\r\n
        [Content length: 736]
    Connection: close\r\n
    Content-Type: text/xml; charset="utf-8"\r\n
    \r\n
    [HTTP response 4/4]
    [Prev request in frame: 29]
    [Prev response in frame: 30]
eXtensible Markup Language
    <?xml
        version="1.0"
        encoding="utf-8"
        ?>
    <D:multistatus
        xmlns:D="DAV:">
        <D:response>
            <D:href>
                /webdav/testFiles/file0.txt
                </D:href>
            <D:status>
                HTTP/1.1 424 Failed Dependency
                </D:status>
            <D:responsedescription>
                An error occurred on another resource, preventing the requested operation on this resource.
                </D:responsedescription>
            </D:response>
        <D:response>
            <D:href>
                /webdav/testFiles
                </D:href>
            <D:status>
                HTTP/1.1 423 Locked
                </D:status>
            <D:responsedescription>
                A validation error has occurred on the parent resource, preventing the operation on the resource specified by the Request-URI. The error was: This resource is locked and an
"If:" header was not supplied to allow access to the resource.
                </D:responsedescription>
            </D:response>
        </D:multistatus>

best regards, alex

agxs commented 9 years ago

I'm having a similar issue where DELETEs are returning a 207 status code, but no exception is thrown. The problem seems to be in this class:

https://github.com/lookfirst/sardine/blob/master/src/main/java/com/github/sardine/impl/handler/ValidatingResponseHandler.java

where it's just considering any 2xx response as a success.