Example usage for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS

List of usage examples for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS.

Prototype

int SC_MULTI_STATUS

To view the source code for org.apache.commons.httpclient HttpStatus SC_MULTI_STATUS.

Click Source Link

Document

<tt>207 Multi-Status</tt> (WebDAV - RFC 2518) or <tt>207 Partial Update OK</tt> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?)

Usage

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send calendar response for request./*  w  w  w.j  a  v  a 2s.  c om*/
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void sendFolderOrItem(CaldavRequest request) throws IOException {
    String folderPath = request.getFolderPath();
    // process request before sending response to avoid sending headers twice on error
    ExchangeSession.Folder folder = session.getFolder(folderPath);
    List<ExchangeSession.Contact> contacts = null;
    List<ExchangeSession.Event> events = null;
    List<ExchangeSession.Folder> folderList = null;
    if (request.getDepth() == 1) {
        if (folder.isContact()) {
            contacts = session.getAllContacts(folderPath);
        } else if (folder.isCalendar() || folder.isTask()) {
            events = session.getAllEvents(folderPath);
            if (!folderPath.startsWith("/public")) {
                folderList = session.getSubCalendarFolders(folderPath, false);
            }
        }
    }

    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    appendFolderOrItem(response, request, folder, null);
    if (request.getDepth() == 1) {
        if (folder.isContact()) {
            appendContactsResponses(response, request, contacts);
        } else if (folder.isCalendar() || folder.isTask()) {
            appendEventsResponses(response, request, events);
            // Send sub folders for multi-calendar support under iCal, except for public folders
            if (folderList != null) {
                for (ExchangeSession.Folder subFolder : folderList) {
                    appendFolderOrItem(response, request, subFolder,
                            subFolder.folderPath.substring(subFolder.folderPath.indexOf('/') + 1));
                }
            }
        }
    }
    response.endMultistatus();
    response.close();
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Fake PROPPATCH response for request.//w  w  w . ja v  a 2s  . c  om
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void patchCalendar(CaldavRequest request) throws IOException {
    String displayname = request.getProperty("displayname");
    String folderPath = request.getFolderPath();
    if (displayname != null) {
        String targetPath = request.getParentFolderPath() + '/' + displayname;
        if (!targetPath.equals(folderPath)) {
            session.moveFolder(folderPath, targetPath);
        }
    }
    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    // ical calendar folder proppatch
    if (request.hasProperty("calendar-color") || request.hasProperty("calendar-order")) {
        response.startPropstat();
        if (request.hasProperty("calendar-color")) {
            response.appendProperty("x1:calendar-color", "x1=\"http://apple.com/ns/ical/\"", null);
        }
        if (request.hasProperty("calendar-order")) {
            response.appendProperty("x1:calendar-order", "x1=\"http://apple.com/ns/ical/\"", null);
        }
        response.endPropStatOK();
    }
    response.endMultistatus();
    response.close();
}

From source file:com.zimbra.qa.unittest.TestCalDav.java

public void checkPropFindSupportedCalendarComponentSet(Account user, String fullurl, String shorturl,
        String[] compNames) throws Exception {
    PropFindMethod method = new PropFindMethod(fullurl);
    addBasicAuthHeaderForUser(method, user);
    HttpClient client = new HttpClient();
    TestCalDav.HttpMethodExecutor executor;
    String respBody;/* ww  w.  ja va 2  s .  c  o  m*/
    method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    method.setRequestEntity(new ByteArrayRequestEntity(propFindSupportedCalendarComponentSet.getBytes(),
            MimeConstants.CT_TEXT_XML));
    executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
    respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    Document doc = W3cDomUtil.parseXMLToDoc(respBody);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(TestCalDav.NamespaceContextForXPath.forCalDAV());
    XPathExpression xPathExpr;
    String text;
    NodeList result;
    xPathExpr = xpath.compile("/D:multistatus/D:response/D:href/text()");
    result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
    text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
    assertEquals("HREF", shorturl.replaceAll("@", "%40"), text);
    xPathExpr = xpath.compile("/D:multistatus/D:response/D:propstat/D:status/text()");
    text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
    assertEquals("status", "HTTP/1.1 200 OK", text);
    xPathExpr = xpath
            .compile("/D:multistatus/D:response/D:propstat/D:prop/C:supported-calendar-component-set/C:comp");
    result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
    assertEquals("Number of comp nodes under supported-calendar-component-set", compNames.length,
            result.getLength());
    List<String> names = Arrays.asList(compNames);
    for (int ndx = 0; ndx < result.getLength(); ndx++) {
        org.w3c.dom.Element child = (org.w3c.dom.Element) result.item(ndx);
        String name = child.getAttribute("name");
        assertNotNull("comp should have a 'name' attribute", name);
        assertTrue(String.format("comp 'name' attribute '%s' should be one of the expected names", name),
                names.contains(name));
    }
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Report items listed in request./* w w  w . j a  va2s.  c om*/
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void reportItems(CaldavRequest request) throws IOException {
    String folderPath = request.getFolderPath();
    List<ExchangeSession.Event> events;
    List<String> notFound = new ArrayList<String>();

    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    if (request.isMultiGet()) {
        int count = 0;
        int total = request.getHrefs().size();
        for (String href : request.getHrefs()) {
            DavGatewayTray.debug(new BundleMessage("LOG_REPORT_ITEM", ++count, total));
            DavGatewayTray.switchIcon();
            String eventName = getEventFileNameFromPath(href);
            try {
                // ignore cases for Sunbird
                if (eventName != null && eventName.length() > 0 && !"inbox".equals(eventName)
                        && !"calendar".equals(eventName)) {
                    ExchangeSession.Item item;
                    try {
                        item = session.getItem(folderPath, eventName);
                    } catch (HttpNotFoundException e) {
                        // workaround for Lightning bug
                        if (request.isBrokenLightning() && eventName.indexOf('%') >= 0) {
                            item = session.getItem(folderPath,
                                    URIUtil.decode(StringUtil.encodePlusSign(eventName)));
                        } else {
                            throw e;
                        }

                    }
                    appendItemResponse(response, request, item);
                }
            } catch (SocketException e) {
                // rethrow SocketException (client closed connection)
                throw e;
            } catch (Exception e) {
                wireLogger.debug(e.getMessage(), e);
                DavGatewayTray.warn(new BundleMessage("LOG_ITEM_NOT_AVAILABLE", eventName, href));
                notFound.add(href);
            }
        }
    } else if (request.isPath(1, "users") && request.isPath(3, "inbox")) {
        events = session.getEventMessages(request.getFolderPath());
        appendEventsResponses(response, request, events);
    } else {
        // TODO: handle contacts ?
        if (request.vTodoOnly) {
            events = session.searchTasksOnly(request.getFolderPath());
        } else if (request.vEventOnly) {
            events = session.searchEventsOnly(request.getFolderPath(), request.timeRangeStart,
                    request.timeRangeEnd);
        } else {
            events = session.searchEvents(request.getFolderPath(), request.timeRangeStart,
                    request.timeRangeEnd);
        }
        appendEventsResponses(response, request, events);
    }

    // send not found events errors
    for (String href : notFound) {
        response.startResponse(encodePath(request, href));
        response.appendPropstatNotFound();
        response.endResponse();
    }
    response.endMultistatus();
    response.close();
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send principals folder.//from  w  w w  .  j  a  v a 2  s. c  o  m
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void sendPrincipalsFolder(CaldavRequest request) throws IOException {
    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    response.startResponse(encodePath(request, request.getPath()));
    response.startPropstat();

    if (request.hasProperty("current-user-principal")) {
        response.appendHrefProperty("D:current-user-principal",
                encodePath(request, "/principals/users/" + session.getEmail()));
    }
    response.endPropStatOK();
    response.endResponse();
    response.endMultistatus();
    response.close();
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send user response for request./*from  www  .ja v a2  s.  c om*/
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void sendUserRoot(CaldavRequest request) throws IOException {
    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    response.startResponse(encodePath(request, request.getPath()));
    response.startPropstat();

    if (request.hasProperty("resourcetype")) {
        response.appendProperty("D:resourcetype", "<D:collection/>");
    }
    if (request.hasProperty("displayname")) {
        response.appendProperty("D:displayname", request.getLastPath());
    }
    if (request.hasProperty("getctag")) {
        ExchangeSession.Folder rootFolder = session.getFolder("");
        response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"",
                base64Encode(rootFolder.ctag));
    }
    response.endPropStatOK();
    if (request.getDepth() == 1) {
        appendInbox(response, request, "inbox");
        appendOutbox(response, request, "outbox");
        appendFolderOrItem(response, request, session.getFolder(request.getFolderPath("calendar")), "calendar");
        appendFolderOrItem(response, request, session.getFolder(request.getFolderPath("contacts")), "contacts");
    }
    response.endResponse();
    response.endMultistatus();
    response.close();
}

From source file:com.zimbra.qa.unittest.TestCalDav.java

/**
 *  dav - sending http error 302 because: wrong url - redirecting to:
 *  http://pan.local:7070/dav/dav1@pan.local/Calendar/d123f102-42a7-4283-b025-3376dabe53b3.ics
 *  com.zimbra.cs.dav.DavException: wrong url - redirecting to:
 *  http://pan.local:7070/dav/dav1@pan.local/Calendar/d123f102-42a7-4283-b025-3376dabe53b3.ics
 *      at com.zimbra.cs.dav.resource.CalendarCollection.createItem(CalendarCollection.java:431)
 *      at com.zimbra.cs.dav.service.method.Put.handle(Put.java:49)
 *      at com.zimbra.cs.dav.service.DavServlet.service(DavServlet.java:322)
 *///from www  .j  a  v  a2 s  .  c o  m
@Test
public void testCreateUsingClientChosenName() throws ServiceException, IOException {
    Account dav1 = users[1].create();
    String davBaseName = "clientInvented.now";
    String calFolderUrl = getFolderUrl(dav1, "Calendar");
    String url = String.format("%s%s", calFolderUrl, davBaseName);
    HttpClient client = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    addBasicAuthHeaderForUser(putMethod, dav1);
    putMethod.addRequestHeader("Content-Type", "text/calendar");

    putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleEvent(dav1), MimeConstants.CT_TEXT_CALENDAR));
    if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
        HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_CREATED);
    } else {
        HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_MOVED_TEMPORARILY);
        // Not testing much in this mode but...
        return;
    }

    doGetMethod(url, dav1, HttpStatus.SC_OK);

    PropFindMethod propFindMethod = new PropFindMethod(getFolderUrl(dav1, "Calendar"));
    addBasicAuthHeaderForUser(propFindMethod, dav1);
    TestCalDav.HttpMethodExecutor executor;
    String respBody;
    Element respElem;
    propFindMethod.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    propFindMethod.addRequestHeader("Depth", "1");
    propFindMethod.setRequestEntity(
            new ByteArrayRequestEntity(propFindEtagResType.getBytes(), MimeConstants.CT_TEXT_XML));
    executor = new TestCalDav.HttpMethodExecutor(client, propFindMethod, HttpStatus.SC_MULTI_STATUS);
    respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    respElem = Element.XMLElement.parseXML(respBody);
    assertEquals("name of top element in propfind response", DavElements.P_MULTISTATUS, respElem.getName());
    assertTrue("propfind response should have child elements", respElem.hasChildren());
    Iterator<Element> iter = respElem.elementIterator();
    boolean hasCalendarHref = false;
    boolean hasCalItemHref = false;
    while (iter.hasNext()) {
        Element child = iter.next();
        if (DavElements.P_RESPONSE.equals(child.getName())) {
            Iterator<Element> hrefIter = child.elementIterator(DavElements.P_HREF);
            while (hrefIter.hasNext()) {
                Element href = hrefIter.next();
                calFolderUrl.endsWith(href.getText());
                hasCalendarHref = hasCalendarHref || calFolderUrl.endsWith(href.getText());
                hasCalItemHref = hasCalItemHref || url.endsWith(href.getText());
            }
        }
    }
    assertTrue("propfind response contained entry for calendar", hasCalendarHref);
    assertTrue("propfind response contained entry for calendar entry ", hasCalItemHref);
    doDeleteMethod(url, dav1, HttpStatus.SC_NO_CONTENT);
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send caldav response for / request.// w  w  w.  j  a  v a2 s.  co  m
 *
 * @param request Caldav request
 * @throws IOException on error
 */
public void sendRoot(CaldavRequest request) throws IOException {
    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    response.startResponse("/");
    response.startPropstat();

    if (request.hasProperty("principal-collection-set")) {
        response.appendHrefProperty("D:principal-collection-set", "/principals/users/");
    }
    if (request.hasProperty("displayname")) {
        response.appendProperty("D:displayname", "ROOT");
    }
    if (request.hasProperty("resourcetype")) {
        response.appendProperty("D:resourcetype", "<D:collection/>");
    }
    if (request.hasProperty("current-user-principal")) {
        response.appendHrefProperty("D:current-user-principal",
                encodePath(request, "/principals/users/" + session.getEmail()));
    }
    response.endPropStatOK();
    response.endResponse();
    if (request.depth == 1) {
        // iPhone workaround: send calendar subfolder
        response.startResponse("/users/" + session.getEmail() + "/calendar");
        response.startPropstat();
        if (request.hasProperty("resourcetype")) {
            response.appendProperty("D:resourcetype",
                    "<D:collection/>" + "<C:calendar xmlns:C=\"urn:ietf:params:xml:ns:caldav\"/>");
        }
        if (request.hasProperty("displayname")) {
            response.appendProperty("D:displayname", session.getEmail());
        }
        if (request.hasProperty("supported-calendar-component-set")) {
            response.appendProperty("C:supported-calendar-component-set", "<C:comp name=\"VEVENT\"/>");
        }
        response.endPropStatOK();
        response.endResponse();

        response.startResponse("/users");
        response.startPropstat();
        if (request.hasProperty("displayname")) {
            response.appendProperty("D:displayname", "users");
        }
        if (request.hasProperty("resourcetype")) {
            response.appendProperty("D:resourcetype", "<D:collection/>");
        }
        response.endPropStatOK();
        response.endResponse();

        response.startResponse("/principals");
        response.startPropstat();
        if (request.hasProperty("displayname")) {
            response.appendProperty("D:displayname", "principals");
        }
        if (request.hasProperty("resourcetype")) {
            response.appendProperty("D:resourcetype", "<D:collection/>");
        }
        response.endPropStatOK();
        response.endResponse();
    }
    response.endMultistatus();
    response.close();
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send caldav response for /directory/ request.
 *
 * @param request Caldav request/*from   w w  w  . j av a  2s  .c  o  m*/
 * @throws IOException on error
 */
public void sendDirectory(CaldavRequest request) throws IOException {
    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    response.startResponse("/directory/");
    response.startPropstat();
    if (request.hasProperty("current-user-privilege-set")) {
        response.appendProperty("D:current-user-privilege-set", "<D:privilege><D:read/></D:privilege>");
    }
    response.endPropStatOK();
    response.endResponse();
    response.endMultistatus();
    response.close();
}

From source file:davmail.caldav.CaldavConnection.java

/**
 * Send Caldav principal response./*from   w  w  w . j  a  va2s.  com*/
 *
 * @param request   Caldav request
 * @param prefix    principal prefix (users or public)
 * @param principal principal name (email address for users)
 * @throws IOException on error
 */
public void sendPrincipal(CaldavRequest request, String prefix, String principal) throws IOException {
    // actual principal is email address
    String actualPrincipal = principal;
    if ("users".equals(prefix) && (principal.equalsIgnoreCase(session.getAlias())
            || (principal.equalsIgnoreCase(session.getAliasFromLogin())))) {
        actualPrincipal = session.getEmail();
    }

    CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
    response.startMultistatus();
    response.startResponse(encodePath(request, "/principals/" + prefix + '/' + principal));
    response.startPropstat();

    if (request.hasProperty("principal-URL") && request.isIcal5()) {
        response.appendHrefProperty("D:principal-URL",
                encodePath(request, "/principals/" + prefix + '/' + actualPrincipal));
    }

    if (request.hasProperty("calendar-home-set")) {
        if ("users".equals(prefix)) {
            response.appendHrefProperty("C:calendar-home-set",
                    encodePath(request, "/users/" + actualPrincipal + "/calendar/"));
        } else {
            response.appendHrefProperty("C:calendar-home-set",
                    encodePath(request, '/' + prefix + '/' + actualPrincipal));
        }
    }

    if (request.hasProperty("calendar-user-address-set") && "users".equals(prefix)) {
        response.appendHrefProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal);
    }

    if (request.hasProperty("addressbook-home-set")) {
        if (request.isUserAgent("Address%20Book") || request.isUserAgent("Darwin")) {
            response.appendHrefProperty("E:addressbook-home-set",
                    encodePath(request, '/' + prefix + '/' + actualPrincipal + '/'));
        } else if ("users".equals(prefix)) {
            response.appendHrefProperty("E:addressbook-home-set",
                    encodePath(request, "/users/" + actualPrincipal + "/contacts/"));
        } else {
            response.appendHrefProperty("E:addressbook-home-set",
                    encodePath(request, '/' + prefix + '/' + actualPrincipal + '/'));
        }
    }

    if ("users".equals(prefix)) {
        if (request.hasProperty("schedule-inbox-URL")) {
            response.appendHrefProperty("C:schedule-inbox-URL",
                    encodePath(request, "/users/" + actualPrincipal + "/inbox/"));
        }

        if (request.hasProperty("schedule-outbox-URL")) {
            response.appendHrefProperty("C:schedule-outbox-URL",
                    encodePath(request, "/users/" + actualPrincipal + "/outbox/"));
        }
    } else {
        // public calendar, send root href as inbox url (always empty) for Lightning
        if (request.isLightning() && request.hasProperty("schedule-inbox-URL")) {
            response.appendHrefProperty("C:schedule-inbox-URL", "/");
        }
        // send user outbox
        if (request.hasProperty("schedule-outbox-URL")) {
            response.appendHrefProperty("C:schedule-outbox-URL",
                    encodePath(request, "/users/" + session.getEmail() + "/outbox/"));
        }
    }

    if (request.hasProperty("displayname")) {
        response.appendProperty("D:displayname", actualPrincipal);
    }
    if (request.hasProperty("resourcetype")) {
        response.appendProperty("D:resourcetype", "<D:collection/><D:principal/>");
    }
    if (request.hasProperty("supported-report-set")) {
        response.appendProperty("D:supported-report-set",
                "<D:supported-report><D:report><C:calendar-multiget/></D:report></D:supported-report>");
    }
    response.endPropStatOK();
    response.endResponse();
    response.endMultistatus();
    response.close();
}