1
0
mirror of https://github.com/etesync/android synced 2025-01-11 08:10:58 +00:00

Process <status> in multi-get responses without <propstat> (see #475)

This commit is contained in:
Ricki Hirner 2015-04-29 20:04:56 +02:00
parent 8afc55dff3
commit fb33767e57
4 changed files with 57 additions and 6 deletions

View File

@ -200,6 +200,17 @@ public class WebDavResourceTest extends InstrumentationTestCase {
assertNotNull(member.getContent()); assertNotNull(member.getContent());
} }
public void testMultiGetWith404() throws Exception {
WebDavResource davAddressBook = new WebDavResource(davCollection, "addressbooks/default-with-404.vcf/");
try {
davAddressBook.multiGet(DavMultiget.Type.ADDRESS_BOOK, new String[]{ "notexisting" });
fail();
} catch(NotFoundException e) {
// addressbooks/default.vcf/notexisting doesn't exist,
// so server responds with 404 which causes a NotFoundException
}
}
public void testPutAddDontOverwrite() throws Exception { public void testPutAddDontOverwrite() throws Exception {
// should succeed on a non-existing file // should succeed on a non-existing file
assertEquals("has-just-been-created", davNonExistingFile.put(SAMPLE_CONTENT, PutMode.ADD_DONT_OVERWRITE)); assertEquals("has-just-been-created", davNonExistingFile.put(SAMPLE_CONTENT, PutMode.ADD_DONT_OVERWRITE));

View File

@ -288,6 +288,35 @@ exports.getBodyParts = function(conf) {
} }
}), }),
/* address-book multiget where one resource has 404 Not Found */
new RoboHydraHeadDAV({
path: "/dav/addressbooks/default-with-404.vcf/",
handler: function(req,res,next) {
if (req.method == "REPORT" && req.rawBody.toString().match(/addressbook-multiget[\s\S]+<prop>[\s\S]+<href>/m &&
req.rawBody.toString().match(/<href>\/dav\/addressbooks\/default-with-404\.vcf\/notexisting<\/href>/m))) {
res.statusCode = 207;
res.write('\<?xml version="1.0" encoding="utf-8" ?>\
<multistatus xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">\
<response>\
<href>/dav/addressbooks/default-with-404.vcf</href>\
<propstat>\
<prop>\
<resourcetype><collection/></resourcetype>\
</prop>\
<status>HTTP/1.1 200 OK</status>\
</propstat>\
</response>\
<response>\
<href>/dav/addressbooks/default-with-404.vcf/notexisting</href>\
<status>HTTP/1.1 404 Not Found</status>\
</response>\
</multistatus>\
');
}
}
}),
] ]
}; };
}; };

View File

@ -18,8 +18,11 @@ import lombok.Getter;
@Root(strict=false) @Root(strict=false)
public class DavResponse { public class DavResponse {
@Element @Element
@Getter DavHref href; DavHref href;
@ElementList(inline=true) @Element(required=false)
@Getter List<DavPropstat> propstat; String status;
@ElementList(inline=true,required=false)
List<DavPropstat> propstat;
} }

View File

@ -420,6 +420,9 @@ public class WebDavResource {
} }
} }
/**
* Process a 207 Multi-status response as defined in RFC 4918 "13. Multi-Status Response"
*/
protected void processMultiStatus(HttpResponse response) throws IOException, HttpException, DavException { protected void processMultiStatus(HttpResponse response) throws IOException, HttpException, DavException {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_MULTI_STATUS) if (response.getStatusLine().getStatusCode() != HttpStatus.SC_MULTI_STATUS)
throw new DavNoMultiStatusException(); throw new DavNoMultiStatusException();
@ -447,7 +450,7 @@ public class WebDavResource {
for (DavResponse singleResponse : multiStatus.response) { for (DavResponse singleResponse : multiStatus.response) {
URI href; URI href;
try { try {
href = location.resolve(URIUtils.parseURI(singleResponse.getHref().href, false)); href = location.resolve(URIUtils.parseURI(singleResponse.href.href, false));
} catch(Exception ex) { } catch(Exception ex) {
Log.w(TAG, "Ignoring illegal member URI in multi-status response", ex); Log.w(TAG, "Ignoring illegal member URI in multi-status response", ex);
continue; continue;
@ -459,7 +462,12 @@ public class WebDavResource {
List<String> supportedComponents = null; List<String> supportedComponents = null;
byte[] data = null; byte[] data = null;
for (DavPropstat singlePropstat : singleResponse.getPropstat()) { // in <response>, either <status> or <propstat> must be present
if (singleResponse.status != null) { // method 1 (status of resource as a whole)
StatusLine status = BasicLineParserHC4.parseStatusLine(singleResponse.status, new BasicLineParserHC4());
checkResponse(status);
} else for (DavPropstat singlePropstat : singleResponse.propstat) { // method 2 (propstat)
StatusLine status = BasicLineParserHC4.parseStatusLine(singlePropstat.status, new BasicLineParserHC4()); StatusLine status = BasicLineParserHC4.parseStatusLine(singlePropstat.status, new BasicLineParserHC4());
// ignore information about missing properties etc. // ignore information about missing properties etc.