我正在尝试使用沙丁鱼查询Apple iCloud日历。但是,在我看来,沙丁鱼没有正确解析响应。无法让沙丁鱼解析CalDav响应
这是我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客户端(失眠)这个查询,我得到我和我的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>"[email protected]=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>"[email protected]=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>"[email protected]=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
对象。没有我的日历数据信号。
什么是沙丁鱼? – hnh
[沙丁鱼](https://github.com/lookfirst/sardine)是一个Java WebDav客户端库。 我在找Java库来访问基于CalDav的服务器时发现它。由于caldav4j似乎有些过时并且不再被维护,于是决定在协议方面“下一级”并寻找WebDav库。在[Apache's Jack Rabbit wiki](https://wiki.apache.org/jackrabbit/WebDAV)中发现了一个使用Sardine的建议。 –
忘了提及,我还在另一篇文章中发现了它,在这篇文章中,您帮助了另一位也在使用沙丁鱼的开发人员。 [链接到帖子](https://stackoverflow.com/questions/38057038/using-sardines-report-method-to-query-events-from-caldav-server) –