Caldav: fix MKCALENDAR http status code: return 201 instead of 207

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1279 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-26 13:32:03 +00:00
parent 3d460c64c0
commit 933e6a72db
3 changed files with 38 additions and 4 deletions

View File

@ -995,9 +995,8 @@ public class DavExchangeSession extends ExchangeSession {
}
};
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method);
// ok or already exists
if (status != HttpStatus.SC_MULTI_STATUS && status != HttpStatus.SC_METHOD_NOT_ALLOWED) {
throw DavGatewayHttpClientFacade.buildHttpException(method);
if (status == HttpStatus.SC_MULTI_STATUS) {
status = method.getResponseStatusCode();
}
return status;
}

View File

@ -23,10 +23,12 @@ import davmail.DavGateway;
import davmail.Settings;
import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import davmail.util.StringUtil;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
@ -161,4 +163,37 @@ public class TestCaldav extends AbstractDavMailTestCase {
assertEquals(events.size(), responses.length);
}
public void testCreateCalendar() throws IOException {
String folderName = "test & accentué";
String encodedFolderpath = URIUtil.encodePath("/users/" + session.getEmail() + "/calendar/"+folderName+ '/');
// first delete calendar
session.deleteFolder("calendar/"+folderName);
String body =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
" <C:mkcalendar xmlns:D=\"DAV:\"\n" +
" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\n" +
" <D:set>\n" +
" <D:prop>\n" +
" <D:displayname>"+ StringUtil.xmlEncode(folderName)+"</D:displayname>\n" +
" <C:calendar-description xml:lang=\"en\">Calendar description</C:calendar-description>\n" +
" <C:supported-calendar-component-set>\n" +
" <C:comp name=\"VEVENT\"/>\n" +
" </C:supported-calendar-component-set>\n" +
" </D:prop>\n" +
" </D:set>\n" +
" </C:mkcalendar>";
SearchReportMethod method = new SearchReportMethod(encodedFolderpath, body) {
@Override
public String getName() {
return "MKCALENDAR";
}
};
httpClient.executeMethod(method);
assertEquals(HttpStatus.SC_CREATED, method.getStatusCode());
GetMethod getMethod = new GetMethod(encodedFolderpath);
httpClient.executeMethod(getMethod);
assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
}
}

View File

@ -176,7 +176,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("true", contact.get("private"));
assertEquals("http://fburl", contact.get("url"));
assertEquals("http://fburl", contact.get("fburl"));
assertEquals("true", contact.get("haspicture"));
assertNotNull(session.getContactPhoto(contact));