org.apache.jackrabbit.webdav.MultiStatus Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.MultiStatus. 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: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The PROPPATCH method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
@SuppressWarnings("rawtypes")
protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doPropPatch");

	List changeList = request.getPropPatchChangeList();
	if (changeList.isEmpty()) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	MultiStatus ms = new MultiStatus();
	MultiStatusResponse msr = resource.alterProperties(changeList);
	ms.addResponse(msr);
	response.sendMultiStatus(ms);
}
 
Example #2
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 #3
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void updateMessage(ExchangeSession.Message message, Map<String, String> properties) throws IOException {
    HttpProppatch patchMethod = new HttpProppatch(encodeAndFixUrl(message.permanentUrl), buildProperties(properties)) {
        @Override
        public MultiStatus getResponseBodyAsMultiStatus(HttpResponse response) {
            // ignore response body, sometimes invalid with exchange mapi properties
            throw new UnsupportedOperationException();
        }
    };
    try (CloseableHttpResponse response = httpClientAdapter.execute(patchMethod)) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_MULTI_STATUS) {
            throw new DavMailException("EXCEPTION_UNABLE_TO_UPDATE_MESSAGE");
        }
    }
}
 
Example #4
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 #5
Source File: SyncMethod.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Process the sync-token, from the response.
 */
protected void processResponseBody(HttpResponse response) {
	if (!processedResponse && succeeded(response)) {
		try {
			Document document = getResponseBodyAsDocument(response.getEntity());
			if (document != null) {
				synctoken = DomUtil.getChildText(document.getDocumentElement(), SyncReportInfo.XML_SYNC_TOKEN, DavConstants.NAMESPACE);
				log.info("Sync-Token for REPORT: {}", synctoken);
				multiStatus = MultiStatus.createFromXml(document.getDocumentElement());
			}
		} catch (IOException e) {
			log.error("Error while parsing sync-token.", e);
		}

		processedResponse = true;
	}
}
 
Example #6
Source File: SyncMethod.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Adapted from DavMethodBase to handle MultiStatus responses.
 *
 * @param response {@link HttpResponse} to be converted to {@link MultiStatus}
 * @return MultiStatus response
 * @throws DavException if the response body could not be parsed
 */
@Override
public MultiStatus getResponseBodyAsMultiStatus(HttpResponse response) throws DavException {
	if (!processedResponse) {
		processResponseBody(response);
	}

	if (multiStatus != null) {
		return multiStatus;
	} else {
		DavException dx = getResponseException(response);
		if (dx != null) {
			throw dx;
		} else {
			throw new DavException(response.getStatusLine().getStatusCode(), getMethod() + " resulted with unexpected status: " + response.getStatusLine());
		}
	}
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
Source File: BaseProvider.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * {@inheritDoc}
 */
public void proppatch(DavRequest request, DavResponse response, WebDavResource resource)
        throws CosmoDavException, IOException {
    if (!resource.exists()) {
        throw new NotFoundException();
    }
    DavPropertySet set = request.getProppatchSetProperties();
    DavPropertyNameSet remove = request.getProppatchRemoveProperties();

    MultiStatus ms = new MultiStatus();
    MultiStatusResponse msr = resource.updateProperties(set, remove);
    ms.addResponse(msr);

    response.sendMultiStatus(ms);
}
 
Example #12
Source File: BaseProvider.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * {@inheritDoc}
 */
public void propfind(DavRequest request, DavResponse response, WebDavResource resource)
        throws CosmoDavException, IOException {
    if (!resource.exists()) {
        throw new NotFoundException();
    }
    int depth = getDepth(request);
    if (depth != DEPTH_0 && !resource.isCollection()) {
        throw new BadRequestException("Depth must be 0 for non-collection resources");
    }

    DavPropertyNameSet props = null;
    int type = -1;

    try {

        props = request.getPropFindProperties();

        type = request.getPropFindType();

    } catch (DavException de) {
        throw new CosmoDavException(de);
    }

    // Since the propfind properties could not be determined in the
    // security filter in order to check specific property privileges, the
    // check must be done manually here.
    checkPropFindAccess(resource, props, type);

    MultiStatus ms = new MultiStatus();
    ms.addResourceProperties(resource, props, type, depth);

    response.sendMultiStatus(ms);
}
 
Example #13
Source File: CalendarCollectionProvider.java    From cosmo with Apache License 2.0 5 votes vote down vote up
@Override
public void mkcalendar(DavRequest request, DavResponse response, DavCollection collection)
        throws CosmoDavException, IOException {
    if (collection.exists()) {
        throw new ExistsException();
    }

    DavItemCollection parent = (DavItemCollection) collection.getParent();
    if (!parent.exists()) {
        throw new MissingParentException("One or more intermediate collections must be created");
    }
    if (parent.isCalendarCollection()) {
        throw new InvalidCalendarLocationException(
                "A calendar collection may not be created within a calendar collection");
    }
    // XXX DAV:needs-privilege DAV:bind on parent collection

    if (LOG.isDebugEnabled()) {
        LOG.debug("MKCALENDAR at {}", collection.getResourcePath());
    }
    DavPropertySet properties = request.getMkCalendarSetProperties();
    MultiStatusResponse msr = collection.getParent().addCollection(collection, properties);

    if (properties.isEmpty() || !hasNonOK(msr)) {
        response.setStatus(201);
        response.setHeader("Cache-control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        return;
    }

    MultiStatus ms = new MultiStatus();
    ms.addResponse(msr);
    response.sendMultiStatus(ms);

}
 
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
Source File: HttpClientAdapter.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute WebDav request
 *
 * @param request WebDav request
 * @return multistatus response
 * @throws IOException on error
 */
public MultiStatus executeDavRequest(BaseDavRequest request) throws IOException {
    handleURI(request);
    MultiStatus multiStatus = null;
    try (CloseableHttpResponse response = execute(request)) {
        request.checkSuccess(response);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_MULTI_STATUS) {
            multiStatus = request.getResponseBodyAsMultiStatus(response);
        }
    } catch (DavException e) {
        LOGGER.error(e.getMessage(), e);
        throw new IOException(e.getErrorCode() + " " + e.getStatusPhrase(), e);
    }
    return multiStatus;
}
 
Example #21
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 #22
Source File: MultiStatusReport.java    From cosmo with Apache License 2.0 4 votes vote down vote up
protected MultiStatus getMultiStatus() {
    return multistatus;
}
 
Example #23
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);
    }
}
 
Example #24
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * The PROPFIND method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
protected void doPropFind(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doPropFind");
	if (log.isDebugEnabled())
		log.debug("[READ] FINDING {} {}",
				(resource.isCollection() ? "DOCUMENTS WITHIN THE FOLDER" : "JUST THE DOCUMENT"),
				resource.getDisplayName());

	if (!resource.exists()) {
		log.warn("Resource not found: {}", resource.getResourcePath());
		response.sendError(DavServletResponse.SC_NOT_FOUND);
		return;
	}

	DavPropertyNameSet requestProperties = request.getPropFindProperties();

	if (log.isDebugEnabled()) {
		DavPropertyNameIterator iter = requestProperties.iterator();
		StringBuffer sb = new StringBuffer("Requested properties: ");
		while (iter.hasNext()) {
			sb.append(((DavPropertyName) iter.next()).getName());
			sb.append(",");
		}
		log.debug(sb.toString());
	}

	int propfindType = request.getPropFindType();

	int depth = Context.get().getProperties().getInt("webdav.depth", 1);
	String headerDepth = request.getHeader("Depth");
	if (StringUtils.isNotEmpty(headerDepth)) {
		if ("infinity".equals(headerDepth))
			depth = request.getDepth(DEPTH_INFINITY);
		else {
			depth = Integer.parseInt(headerDepth);
		}
	}

	MultiStatus mstatus = new MultiStatus();
	mstatus.addResourceProperties(resource, requestProperties, propfindType, depth);

	response.sendMultiStatus(mstatus);
}
 
Example #25
Source File: VersionControlledResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * MERGE feature is not (yet) supported. This method allows fails with
 * {@link DavServletResponse#SC_NOT_IMPLEMENTED}.
 * 
 * @param mergeInfo details bout the merge
 * 
 * @return the status
 * 
 * @throws org.apache.jackrabbit.webdav.DavException error in the DAV communication
 * @see VersionControlledResource#merge(MergeInfo)
 */
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
	throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
}
 
Example #26
Source File: VersionControlledResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * UPDATE feature is not (yet) supported. This method allows fails with
 * {@link DavServletResponse#SC_NOT_IMPLEMENTED}.
 * 
 * @param updateInfo update datails
 *  
 * @return the status
 * 
 * @throws org.apache.jackrabbit.webdav.DavException error in the DAV communication
 * @see VersionControlledResource#update(UpdateInfo)
 */
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
	throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
}