use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class CalDavClient method login.
public void login(String defaultPrincipalUrl) throws IOException, DavException {
String principalUrl = getCurrentUserPrincipal();
if (principalUrl == null) {
principalUrl = defaultPrincipalUrl;
}
DavRequest propfind = DavRequest.PROPFIND(principalUrl);
propfind.addRequestProp(DavElements.E_DISPLAYNAME);
propfind.addRequestProp(DavElements.E_CALENDAR_HOME_SET);
propfind.addRequestProp(DavElements.E_SCHEDULE_INBOX_URL);
propfind.addRequestProp(DavElements.E_SCHEDULE_OUTBOX_URL);
Collection<DavObject> response = sendMultiResponseRequest(propfind);
if (response.size() != 1) {
throw new DavException(String.format("invalid response to propfind on principal url '%s'", principalUrl), null);
}
DavObject resp = response.iterator().next();
mCalendarHomeSet = new HashSet<String>();
Element homeSet = resp.getProperty(DavElements.E_CALENDAR_HOME_SET);
if (homeSet != null) {
for (Object href : homeSet.elements(DavElements.E_HREF)) {
String hrefVal = ((Element) href).getText();
mCalendarHomeSet.add(hrefVal);
}
}
if (mCalendarHomeSet.isEmpty()) {
throw new DavException("dav response from principal url does not contain calendar-home-set", null);
}
Element elem = resp.getProperty(DavElements.E_SCHEDULE_INBOX_URL);
if (elem != null && elem.element(DavElements.E_HREF) != null) {
mScheduleInbox = elem.element(DavElements.E_HREF).getText();
}
elem = resp.getProperty(DavElements.E_SCHEDULE_OUTBOX_URL);
if (elem != null && elem.element(DavElements.E_HREF) != null) {
mScheduleOutbox = elem.element(DavElements.E_HREF).getText();
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class CalDavClient method sendCalendarData.
public String sendCalendarData(Appointment appt) throws IOException, DavException {
HttpInputStream resp = sendPut(appt.href, appt.data.getBytes("UTF-8"), MimeConstants.CT_TEXT_CALENDAR, appt.etag, null);
String etag = resp.getHeader(DavProtocol.HEADER_ETAG);
ZimbraLog.dav.debug("ETags: " + appt.etag + ", " + etag);
int status = resp.getStatusCode();
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED && status != HttpStatus.SC_NO_CONTENT) {
throw new DavException("Can't send calendar data (status=" + status + ")", status);
}
if (mSchedulingEnabled)
sendSchedulingMessage(appt);
return etag;
}
Aggregations