0

I am trying to use Sardine to query Apple iCloud Calendar. However, it seems to me Sardine is not properly parsing the response.

This is my CalDav time range query:

<?xml version="1.0" encoding="utf-8" ?>
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
  <d:prop>
        <d:getetag/>
    <c:calendar-data/>
  </d:prop>
  <c:filter>
    <c:comp-filter name="VCALENDAR">
      <c:comp-filter name="VEVENT">
        <c:time-range start="20170501T000000Z" end="20170630T000000Z"/>
      </c:comp-filter>
    </c:comp-filter>
  </c:filter>
</c:calendar-query>

When firing this query using a HTTP client (Insomnia), I get my reply with my 3 test events without any problems. Please note I removed part of the calendar data to make it shorter):

<?xml version='1.0' encoding='UTF-8'?>
<multistatus
    xmlns='DAV:'>
    <response>
        <href>/2003926771/calendars/home/DF4C980C-C189-4DAB-80CE-991A4636593D.ics</href>
        <propstat>
            <prop>
                <getetag>"C=62@U=974e7f83-44fb-4eb2-8386-46012509f5af"</getetag>
                <calendar-data
                    xmlns='urn:ietf:params:xml:ns:caldav'>
                    <![CDATA[BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:DF4C980C-C189-4DAB-80CE-991A4636593D
DTSTART;TZID=Europe/Zurich:20170522T150000
DTEND;TZID=Europe/Zurich:20170522T160000
SUMMARY:Test event
END:VEVENT
END:VCALENDAR
]]>
                </calendar-data>
            </prop>
            <status>HTTP/1.1 200 OK</status>
        </propstat>
    </response>
    <response>
        <href>/2003926771/calendars/home/4A9F9785-A8A4-4E61-A600-D5A5C041950E.ics</href>
        <propstat>
            <prop>
                <getetag>"C=115@U=974e7f83-44fb-4eb2-8386-46012509f5af"</getetag>
                <calendar-data
                    xmlns='urn:ietf:params:xml:ns:caldav'>
                    <![CDATA[BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:4A9F9785-A8A4-4E61-A600-D5A5C041950E
DTSTART;TZID=Europe/Zurich:20170601T120000
DTEND;TZID=Europe/Zurich:20170601T130000
SUMMARY:test event in June
END:VEVENT
END:VCALENDAR
]]>
                </calendar-data>
            </prop>
            <status>HTTP/1.1 200 OK</status>
        </propstat>
    </response>
    <response>
        <href>/2003926771/calendars/home/33D1A876-87E6-4165-8AE6-EDD2FA588964.ics</href>
        <propstat>
            <prop>
                <getetag>"C=114@U=974e7f83-44fb-4eb2-8386-46012509f5af"</getetag>
                <calendar-data
                    xmlns='urn:ietf:params:xml:ns:caldav'>
                    <![CDATA[BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:33D1A876-87E6-4165-8AE6-EDD2FA588964
DTSTART;TZID=Europe/Zurich:20170530T120000
DTEND;TZID=Europe/Zurich:20170530T130000
LAST-MODIFIED:20170530T071831Z
SUMMARY:another test event
END:VEVENT
END:VCALENDAR
]]>
                </calendar-data>
            </prop>
            <status>HTTP/1.1 200 OK</status>
        </propstat>
    </response>
</multistatus>

However, when I send exactly the same query through a Sardine Report, I am not able to read the calendat-data content.

In more details, when executing the code below, getAny returns an empty list. As per my google researches, this should contain a list with xml nodes under prop (with the nodes other than a few pre-defined ones that are stored under different objects under Prop, like etag).

@Override
public List<VEvent> fromMultistatus(Multistatus multistatus) {
    List<VEvent> events = new ArrayList<>(multistatus.getResponse().size());
    for (Response response : multistatus.getResponse()) {
        for (Propstat propstat : response.getPropstat()) {
            System.out.println(propstat.getProp().getAny().get(0).getFirstChild().getTextContent());                
        }
    }
    return events;
}

I even debugged the entire multistatus object, which contains the response. There's no signal of my calendar data.

Robson Hermes
  • 425
  • 5
  • 12
  • What is Sardine? – hnh May 31 '17 at 10:58
  • [Sardine](https://github.com/lookfirst/sardine) is a Java WebDav client library. I found it when looking for Java libraries to access CalDav based servers. As caldav4j seems to be a bit out of date and not maintained anymore, then decided to go "one level down" in terms of protocol and look for WebDav libraries. Found a recommendation to use Sardine in [Apache's Jack Rabbit wiki](https://wiki.apache.org/jackrabbit/WebDAV) – Robson Hermes May 31 '17 at 11:35
  • Forgot to mention, I also found it in another post where you helped another developer which was also using Sardine. [link to the post](https://stackoverflow.com/questions/38057038/using-sardines-report-method-to-query-events-from-caldav-server) – Robson Hermes May 31 '17 at 11:42

1 Answers1

0

Sorry, fault was mine. I was calling this URL in my test with Insomnia:

https://pxx-caldav.icloud.com:443/principal/calendars/

And calling this in my Sardine test:

https://pxx-caldav.icloud.com:443/principal/calendars/home/

When calling home sub-calendar (is that the right name?) I got no events.

Although this brings another question, like I could not query home sub-calendar which contained my test events, anyway this solves this specific question of why I was not retrieving my test events using Sardine.

Robson Hermes
  • 425
  • 5
  • 12
  • CalDAV unfortunately doesn't support nested calendars, there are just flat calendars in the calendar homeset. Hence no 'sub-calendars', just calendars ;-) – hnh Jun 02 '17 at 11:25