Search in sources :

Example 61 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class ExpandProperty method handle.

@Override
public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_EXPAND_PROPERTY))
        throw new DavException("msg " + query.getName() + " is not expand-property", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResource rs = ctxt.getRequestedResource();
    ctxt.setDavCompliance(DavProtocol.getComplianceString(rs.getComplianceList()));
    ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    Element resp = ctxt.getDavResponse().getTop(DavElements.E_MULTISTATUS).addElement(DavElements.E_RESPONSE);
    expandProperties(ctxt, rs, query, resp);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element)

Example 62 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class FreeBusyQuery method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_FREE_BUSY_QUERY))
        throw new DavException("msg " + query.getName() + " is not free-busy-query", HttpServletResponse.SC_BAD_REQUEST, null);
    Element trElem = query.element(DavElements.E_TIME_RANGE);
    if (trElem == null)
        throw new DavException("need time-range", HttpServletResponse.SC_BAD_REQUEST, null);
    TimeRange timeRange = new TimeRange(trElem);
    DavResource rs = ctxt.getRequestedResource();
    if (!(rs instanceof CalendarCollection))
        throw new DavException("not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    try {
        String freebusy = ((CalendarCollection) rs).getFreeBusyReport(ctxt, timeRange);
        HttpServletResponse resp = ctxt.getResponse();
        resp.setContentType(MimeConstants.CT_TEXT_CALENDAR);
        resp.getOutputStream().write(freebusy.getBytes("UTF-8"));
        ctxt.responseSent();
    } catch (ServiceException se) {
        throw new DavException("can't get freebusy report", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, se);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) ServiceException(com.zimbra.common.service.ServiceException) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 63 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class AclReports method handle.

@Override
public void handle(DavContext ctxt) throws DavException, ServiceException {
    ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    Element query = ctxt.getRequestMessage().getRootElement();
    if (query.getQName().equals(DavElements.E_PRINCIPAL_PROPERTY_SEARCH))
        handlePrincipalPropertySearch(ctxt, query);
    else if (query.getQName().equals(DavElements.E_ACL_PRINCIPAL_PROP_SET))
        handleAclPrincipalPropSet(ctxt, query);
    else if (query.getQName().equals(DavElements.E_PRINCIPAL_MATCH))
        handlePrincipalMatch(ctxt, query);
    else if (query.getQName().equals(DavElements.E_PRINCIPAL_SEARCH_PROPERTY_SET))
        handlePrincipalSearchPropertySet(ctxt, query);
    else
        throw new DavException("msg " + query.getName() + " is not an ACL report", HttpServletResponse.SC_BAD_REQUEST);
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element)

Example 64 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class AddressbookQuery method handle.

public void handle(DavContext ctxt) throws DavException, ServiceException {
    DavResource rsc = ctxt.getRequestedResource();
    if (!(rsc instanceof AddressbookCollection))
        throw new DavException("not an addressbook resource", HttpServletResponse.SC_BAD_REQUEST, null);
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_QUERY))
        throw new DavException("msg " + query.getName() + " is not addressbook-query", HttpServletResponse.SC_BAD_REQUEST, null);
    Element f = query.element(DavElements.CardDav.E_FILTER);
    if (f == null)
        throw new DavException("msg " + query.getName() + " is missing filter", HttpServletResponse.SC_BAD_REQUEST, null);
    Filter filter = new Filter.PropFilter((Element) f.elementIterator().next());
    Collection<AddressObject> contacts = filter.match(ctxt, ((AddressbookCollection) rsc));
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    resp.createResponse(ctxt);
    for (AddressObject c : contacts) {
        resp.addResource(ctxt, c, reqProp, false);
    }
}
Also used : AddressbookCollection(com.zimbra.cs.dav.resource.AddressbookCollection) DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) Filter(com.zimbra.cs.dav.carddav.Filter) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) AddressObject(com.zimbra.cs.dav.resource.AddressObject)

Example 65 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class CalendarMultiget method handle.

public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_CALENDAR_MULTIGET))
        throw new DavException("msg " + query.getName() + " is not calendar-multiget", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResponse resp = ctxt.getDavResponse();
    ArrayList<String> hrefs = new ArrayList<String>();
    for (Object obj : query.elements(DavElements.E_HREF)) if (obj instanceof Element)
        hrefs.add(((Element) obj).getText());
    long ts = System.currentTimeMillis();
    DavResource reqResource = ctxt.getRequestedResource();
    if (!(reqResource instanceof CalendarCollection))
        throw new DavException("requested resource is not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    CalendarCollection calResource = (CalendarCollection) reqResource;
    long now = System.currentTimeMillis();
    ZimbraLog.dav.debug("GetRequestedResource: " + (now - ts) + "ms");
    RequestProp reqProp = ctxt.getRequestProp();
    for (DavResource rs : calResource.getAppointmentsByUids(ctxt, hrefs)) resp.addResource(ctxt, rs, reqProp, false);
    ts = now;
    now = System.currentTimeMillis();
    ZimbraLog.dav.debug("multiget: " + (now - ts) + "ms");
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

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