我正在尝试使用 Sardine 查询 Apple iCloud 日历。但是,在我看来,沙丁鱼没有正确解析响应。
这是我的 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
我什至调试了包含响应的整个对象。我的日历数据没有信号。