Search in sources :

Example 66 with DavException

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();
    }
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element)

Example 67 with DavException

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;
}
Also used : DavException(com.zimbra.cs.dav.DavException) HttpInputStream(com.zimbra.cs.service.UserServlet.HttpInputStream)

Aggregations

DavException (com.zimbra.cs.dav.DavException)67 ServiceException (com.zimbra.common.service.ServiceException)27 Element (org.dom4j.Element)25 Account (com.zimbra.cs.account.Account)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 DavResource (com.zimbra.cs.dav.resource.DavResource)15 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)15 ArrayList (java.util.ArrayList)14 Provisioning (com.zimbra.cs.account.Provisioning)11 Document (org.dom4j.Document)9 DavResponse (com.zimbra.cs.dav.service.DavResponse)8 MailItem (com.zimbra.cs.mailbox.MailItem)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)7 ZMailbox (com.zimbra.client.ZMailbox)6 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)6 IOException (java.io.IOException)6 Collection (com.zimbra.cs.dav.resource.Collection)5 Folder (com.zimbra.cs.mailbox.Folder)5 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)4 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)3