Search in sources :

Example 56 with DavException

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

the class Move method checkPrecondition.

@Override
public void checkPrecondition(DavContext ctxt) throws DavException, ServiceException {
    super.checkPrecondition(ctxt);
    DavResource rs = ctxt.getRequestedResource();
    if (!(rs instanceof MailItemResource))
        throw new DavException("cannot move", HttpServletResponse.SC_BAD_REQUEST, null);
    col = ctxt.getDestinationCollection();
    mir = (MailItemResource) rs;
    if (!mir.isCollection()) {
        Collection srcCollection = ctxt.getRequestedParentCollection();
        if (srcCollection.getDefaultView() != MailItem.Type.UNKNOWN && srcCollection.getDefaultView() != col.getDefaultView())
            throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
    } else {
        // allow moving of collections of type document or unknown only.
        if (!(((Collection) mir).getDefaultView() == MailItem.Type.DOCUMENT || ((Collection) mir).getDefaultView() == MailItem.Type.UNKNOWN))
            throw new DavException("cannot move non-document collection", HttpServletResponse.SC_FORBIDDEN, null);
        // do not allow moving of collection if destination type is not document or unknown.            
        if (!(col.getDefaultView() == MailItem.Type.UNKNOWN || col.getDefaultView() == MailItem.Type.DOCUMENT))
            throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) DavException(com.zimbra.cs.dav.DavException) Collection(com.zimbra.cs.dav.resource.Collection)

Example 57 with DavException

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

the class Put method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException {
    String user = ctxt.getUser();
    String name = ctxt.getItem();
    if (user == null || name == null)
        throw new DavException("invalid uri", HttpServletResponse.SC_NOT_ACCEPTABLE, null);
    Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
    DavResource rs = col.createItem(ctxt, name);
    if (rs.isNewlyCreated())
        ctxt.setStatus(HttpServletResponse.SC_CREATED);
    else
        ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
    if (rs.hasEtag()) {
        ctxt.getResponse().setHeader(DavProtocol.HEADER_ETAG, rs.getEtag());
        ctxt.getResponse().setHeader(ETagHeaderFilter.ZIMBRA_ETAG_HEADER, rs.getEtag());
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) Collection(com.zimbra.cs.dav.resource.Collection)

Example 58 with DavException

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

the class Report method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    if (!ctxt.hasRequestMessage()) {
        throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    Document req = ctxt.getRequestMessage();
    Element top = req.getRootElement();
    if (top == null) {
        throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    QName topName = top.getQName();
    DavMethod report = sReports.get(topName);
    if (report == null) {
        throw new DavException.UnsupportedReport(topName);
    }
    disableJettyTimeout(ctxt);
    if (ctxt.getDepth() != DavContext.Depth.zero) {
        ctxt.getDavResponse().createResponse(ctxt);
    }
    report.handle(ctxt);
    sendResponse(ctxt);
}
Also used : DavMethod(com.zimbra.cs.dav.service.DavMethod) DavException(com.zimbra.cs.dav.DavException) QName(org.dom4j.QName) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 59 with DavException

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

the class CalendarQuery method handle.

@Override
public void handle(DavContext ctxt) throws DavException, ServiceException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_CALENDAR_QUERY)) {
        throw new DavException("msg " + query.getName() + " is not calendar-query", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    RequestProp reqProp = ctxt.getRequestProp();
    QueryContext qctxt = new QueryContext(ctxt, query, reqProp);
    if (qctxt.componentFilter == null) {
        throw new DavException("missing filter element in the request", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    DavResource rsc = ctxt.getRequestedResource();
    if (!(rsc instanceof CalendarCollection)) {
        throw new DavException("not a calendar resource", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    CalendarCollection cal = (CalendarCollection) rsc;
    TimeRange tr = qctxt.componentFilter.getTimeRange();
    if (tr == null) {
        tr = new TimeRange(rsc.getOwner());
    }
    /**
         * Even if there are no matching items, we should return a DAV:multistatus report
         * http://tools.ietf.org/html/rfc4791#section-7.8 CALDAV:calendar-query REPORT
         * The response body for a successful request MUST be a DAV:multistatus XML element (i.e., the response uses
         * the same format as the response for PROPFIND).  In the case where there are no response elements, the
         * returned DAV:multistatus XML element is empty.
         */
    qctxt.davCtxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    DavResponse resp = qctxt.davCtxt.getDavResponse();
    resp.getTop(DavElements.E_MULTISTATUS);
    for (DavResource calItem : cal.getChildren(ctxt, tr)) {
        handleCalendarItem(qctxt, calItem);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) 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)

Example 60 with DavException

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

the class Delete method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    DavResource rsc = ctxt.getRequestedResource();
    if (rsc == null)
        throw new DavException("cannot find the resource", HttpServletResponse.SC_NOT_FOUND, null);
    rsc.delete(ctxt);
    ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException)

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