无法让Sardine解析CalDav响应

时间:2017-05-31 08:42:17

标签: icloud caldav sardine

我正在尝试使用沙丁鱼来查询Apple iCloud Calendar。但是,在我看来,沙丁鱼没有正确解析响应。

这是我的CalDav时间范围查询:

<?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>

使用HTTP客户端(Insomnia)触发此查询时,我的3个测试事件的回复没有任何问题。请注意我删除了部分日历数据以缩短日期数据):

<?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>

但是,当我通过沙丁鱼报告发送完全相同的查询时,我无法阅读calendat-data内容。

更多细节,在执行下面的代码时,getAny返回一个空列表。根据我的谷歌研究,这应该包含一个在prop下的xml节点的列表(除了一些预定义的节点,它们存储在Prop下的不同对象下,如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;
}

我甚至调试了包含响应的整个multistatus对象。我的日历数据没有信号。

1 个答案:

答案 0 :(得分:0)

对不起,错了是我的。我在Insomnia的测试中调用了这个URL:

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

在我的沙丁鱼测试中调用它:

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

调用home子日历时(是正确的名字?)我没有发生任何事件。

虽然这带来了另一个问题,比如我无法查询包含我的测试事件的home子日历,但无论如何这解决了为什么我没有使用沙丁鱼检索我的测试事件的具体问题。

相关问题