Java Code Examples for org.apache.jackrabbit.webdav.MultiStatus#getResponses()

The following examples show how to use org.apache.jackrabbit.webdav.MultiStatus#getResponses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
protected String getItemProperty(String permanentUrl, String propertyName) throws IOException, DavException {
    String result = null;
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(Field.getPropertyName(propertyName));
    PropFindMethod propFindMethod = new PropFindMethod(encodeAndFixUrl(permanentUrl), davPropertyNameSet, 0);
    try {
        try {
            DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propFindMethod);
        } catch (UnknownHostException e) {
            propFindMethod.releaseConnection();
            // failover for misconfigured Exchange server, replace host name in url
            restoreHostName = true;
            propFindMethod = new PropFindMethod(encodeAndFixUrl(permanentUrl), davPropertyNameSet, 0);
            DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propFindMethod);
        }

        MultiStatus responses = propFindMethod.getResponseBodyAsMultiStatus();
        if (responses.getResponses().length > 0) {
            DavPropertySet properties = responses.getResponses()[0].getProperties(HttpStatus.SC_OK);
            result = getPropertyIfExists(properties, propertyName);
        }
    } finally {
        propFindMethod.releaseConnection();
    }
    return result;
}
 
Example 2
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportInbox() throws IOException, DavException {

        StringBuilder buffer = new StringBuilder();
        buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">");
        buffer.append("<D:prop>");
        buffer.append("<C:calendar-data/>");
        buffer.append("</D:prop>");
        buffer.append("<C:filter>");
        buffer.append("</C:filter>");
        buffer.append("</C:calendar-query>");
        SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/inbox/", buffer.toString());
        httpClient.executeMethod(method);
        assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
        MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
        MultiStatusResponse[] responses = multiStatus.getResponses();
        /*List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/",
                session.or(session.isEqualTo("instancetype", 1),
                        session.and(session.isEqualTo("instancetype", 0), dateCondition))

        );*/

        //assertEquals(events.size(), responses.length);
    }
 
Example 3
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportTasks() throws IOException, DavException {
    StringBuilder buffer = new StringBuilder();
    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">");
    buffer.append("<D:prop>");
    buffer.append("<C:calendar-data/>");
    buffer.append("</D:prop>");
    buffer.append("<C:comp-filter name=\"VCALENDAR\">");
    buffer.append("<C:comp-filter name=\"VTODO\"/>");
    buffer.append("</C:comp-filter>");
    buffer.append("<C:filter>");
    buffer.append("</C:filter>");
    buffer.append("</C:calendar-query>");
    SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString());
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
}
 
Example 4
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportEventsOnly() throws IOException, DavException {
    StringBuilder buffer = new StringBuilder();
    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">");
    buffer.append("<D:prop>");
    buffer.append("<C:calendar-data/>");
    buffer.append("</D:prop>");
    buffer.append("<C:comp-filter name=\"VCALENDAR\">");
    buffer.append("<C:comp-filter name=\"VEVENT\"/>");
    buffer.append("</C:comp-filter>");
    buffer.append("<C:filter>");
    buffer.append("</C:filter>");
    buffer.append("</C:calendar-query>");
    SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString());
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
}
 
Example 5
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupMethod(method);
        execute(method);
        if (method.succeeded()) {
            final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example 6
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
protected Folder internalGetFolder(String folderPath) throws IOException {
    MultiStatus multiStatus = httpClientAdapter.executeDavRequest(new HttpPropfind(
            URIUtil.encodePath(getFolderPath(folderPath)),
            FOLDER_PROPERTIES_NAME_SET, 0));
    MultiStatusResponse[] responses = multiStatus.getResponses();

    Folder folder = null;
    if (responses.length > 0) {
        folder = buildFolder(responses[0]);
        folder.folderPath = folderPath;
    }
    return folder;
}
 
Example 7
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testReportCalendar() throws IOException, DavException {
    SimpleDateFormat formatter = ExchangeSession.getZuluDateFormat();
    Calendar cal = Calendar.getInstance();
    Date end = cal.getTime();
    cal.add(Calendar.MONTH, -1);
    Date start = cal.getTime();

    StringBuilder buffer = new StringBuilder();
    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    buffer.append("<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">");
    buffer.append("<D:prop>");
    buffer.append("<C:calendar-data/>");
    buffer.append("</D:prop>");
    buffer.append("<C:comp-filter name=\"VCALENDAR\">");
    buffer.append("<C:comp-filter name=\"VEVENT\">");
    buffer.append("<C:time-range start=\"").append(formatter.format(start)).append("\" end=\"").append(formatter.format(end)).append("\"/>");
    //buffer.append("<C:time-range start=\"").append(formatter.format(start)).append("\"/>");
    buffer.append("</C:comp-filter>");
    buffer.append("</C:comp-filter>");
    buffer.append("<C:filter>");
    buffer.append("</C:filter>");
    buffer.append("</C:calendar-query>");
    SearchReportMethod method = new SearchReportMethod("/users/" + session.getEmail() + "/calendar/", buffer.toString());
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    ExchangeSession.Condition dateCondition = session.and(
            session.gt("dtstart", session.formatSearchDate(start)),
            session.lt("dtend", session.formatSearchDate(end))
    );
    List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/",
            session.or(session.isEqualTo("instancetype", 1),
                    session.and(session.isEqualTo("instancetype", 0), dateCondition))

    );

    assertEquals(events.size(), responses.length);
}
 
Example 8
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testPropfindPrincipal() throws IOException, DavException {
    //Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);

    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(DavPropertyName.create("calendar-home-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("calendar-user-address-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-inbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-outbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    PropFindMethod method = new PropFindMethod("/principals/users/" + session.getEmail() + "/", davPropertyNameSet, 0);
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(1, responses.length);
}
 
Example 9
Source File: TestCaldav.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testPropfindPublicPrincipal() throws IOException, DavException {
    //Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);

    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(DavPropertyName.create("calendar-home-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("calendar-user-address-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-inbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-outbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    PropFindMethod method = new PropFindMethod("/principals/public/testcalendar/", davPropertyNameSet, 0);
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(1, responses.length);
}
 
Example 10
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testReportCalendar() throws IOException {
    SimpleDateFormat formatter = ExchangeSession.getZuluDateFormat();
    Calendar cal = Calendar.getInstance();
    Date end = cal.getTime();
    cal.add(Calendar.MONTH, -1);
    Date start = cal.getTime();

    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    String buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">" +
            "<D:prop>" +
            "<C:calendar-data/>" +
            "</D:prop>" +
            "<C:comp-filter name=\"VCALENDAR\">" +
            "<C:comp-filter name=\"VEVENT\">" +
            "<C:time-range start=\"" + formatter.format(start) + "\" end=\"" + formatter.format(end) + "\"/>" +
            //"<C:time-range start=\"" + formatter.format(start) + "\"/>" +
            "</C:comp-filter>" +
            "</C:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    MultiStatus multiStatus = httpClient.executeDavRequest(method);
    MultiStatusResponse[] responses = multiStatus.getResponses();
    List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/",
            ExchangeSession.getZuluDateFormat().format(start),
            ExchangeSession.getZuluDateFormat().format(end)
    );

    assertEquals(events.size(), responses.length);
}
 
Example 11
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testPropfindPrincipal() throws IOException {
    //Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);

    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(DavPropertyName.create("calendar-home-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("calendar-user-address-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-inbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-outbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    HttpPropfind method = new HttpPropfind("/principals/users/" + session.getEmail() + "/", davPropertyNameSet, 0);
    MultiStatus multiStatus = httpClient.executeDavRequest(method);
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(1, responses.length);
}
 
Example 12
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testPropfindPublicPrincipal() throws IOException {
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    davPropertyNameSet.add(DavPropertyName.create("calendar-home-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("calendar-user-address-set", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-inbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    davPropertyNameSet.add(DavPropertyName.create("schedule-outbox-URL", Namespace.getNamespace("urn:ietf:params:xml:ns:caldav")));
    HttpPropfind method = new HttpPropfind("/principals/public/testcalendar/", davPropertyNameSet, 0);
    MultiStatus multiStatus = httpClient.executeDavRequest(method);
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(1, responses.length);
}
 
Example 13
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
DavPropertySet getProperties(final GenericURLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final HttpPropfind request = new HttpPropfind(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupRequest(request);
        final HttpResponse res = executeRequest(request);
        if (request.succeeded(res)) {
            final MultiStatus multiStatus = request.getResponseBodyAsMultiStatus(res);
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final ContentType resContentType = ContentType.getOrDefault(res.getEntity());
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET,
                        resContentType.getCharset().name());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example 14
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
protected void getWellKnownFolders() throws DavMailException {
    // Retrieve well known URLs
    try {
        HttpPropfind httpPropfind = new HttpPropfind(mailPath, WELL_KNOWN_FOLDERS, 0);
        MultiStatus multiStatus;
        try (CloseableHttpResponse response = httpClientAdapter.execute(httpPropfind)) {
            multiStatus = httpPropfind.getResponseBodyAsMultiStatus(response);
        }
        MultiStatusResponse[] responses = multiStatus.getResponses();
        if (responses.length == 0) {
            throw new WebdavNotAvailableException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
        }
        DavPropertySet properties = responses[0].getProperties(org.apache.http.HttpStatus.SC_OK);
        inboxUrl = getURIPropertyIfExists(properties, "inbox");
        inboxName = getFolderName(inboxUrl);
        deleteditemsUrl = getURIPropertyIfExists(properties, "deleteditems");
        deleteditemsName = getFolderName(deleteditemsUrl);
        sentitemsUrl = getURIPropertyIfExists(properties, "sentitems");
        sentitemsName = getFolderName(sentitemsUrl);
        sendmsgUrl = getURIPropertyIfExists(properties, "sendmsg");
        sendmsgName = getFolderName(sendmsgUrl);
        draftsUrl = getURIPropertyIfExists(properties, "drafts");
        draftsName = getFolderName(draftsUrl);
        calendarUrl = getURIPropertyIfExists(properties, "calendar");
        calendarName = getFolderName(calendarUrl);
        tasksUrl = getURIPropertyIfExists(properties, "tasks");
        tasksName = getFolderName(tasksUrl);
        contactsUrl = getURIPropertyIfExists(properties, "contacts");
        contactsName = getFolderName(contactsUrl);
        outboxUrl = getURIPropertyIfExists(properties, "outbox");
        outboxName = getFolderName(outboxUrl);
        // junk folder not available over webdav

        LOGGER.debug("Inbox URL: " + inboxUrl +
                " Trash URL: " + deleteditemsUrl +
                " Sent URL: " + sentitemsUrl +
                " Send URL: " + sendmsgUrl +
                " Drafts URL: " + draftsUrl +
                " Calendar URL: " + calendarUrl +
                " Tasks URL: " + tasksUrl +
                " Contacts URL: " + contactsUrl +
                " Outbox URL: " + outboxUrl +
                " Public folder URL: " + publicFolderUrl
        );
    } catch (IOException | DavException e) {
        LOGGER.error(e.getMessage());
        throw new WebdavNotAvailableException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
    }
}