From 933e6a72db747a7055cc91d3dbadd828c305a64b Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 26 Jul 2010 13:32:03 +0000 Subject: [PATCH] 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 --- .../exchange/dav/DavExchangeSession.java | 5 ++- src/test/davmail/caldav/TestCaldav.java | 35 +++++++++++++++++++ .../exchange/TestExchangeSessionContact.java | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 53f93537..05493a1c 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -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; } diff --git a/src/test/davmail/caldav/TestCaldav.java b/src/test/davmail/caldav/TestCaldav.java index 6cde1fbe..58e73bac 100644 --- a/src/test/davmail/caldav/TestCaldav.java +++ b/src/test/davmail/caldav/TestCaldav.java @@ -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 = + "\n" + + " \n" + + " \n" + + " \n" + + " "+ StringUtil.xmlEncode(folderName)+"\n" + + " Calendar description\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " "; + + 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()); + } } diff --git a/src/test/davmail/exchange/TestExchangeSessionContact.java b/src/test/davmail/exchange/TestExchangeSessionContact.java index ed38edda..392ce6f5 100644 --- a/src/test/davmail/exchange/TestExchangeSessionContact.java +++ b/src/test/davmail/exchange/TestExchangeSessionContact.java @@ -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));