org.apache.jackrabbit.webdav.MultiStatusResponse Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.MultiStatusResponse. 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: ExchangeDavRequest.java    From davmail with GNU General Public License v2.0 7 votes vote down vote up
protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
    int propstatStatus = 0;
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("status".equals(tagLocalName)) {
                if ("HTTP/1.1 200 OK".equals(reader.getElementText())) {
                    propstatStatus = HttpStatus.SC_OK;
                } else {
                    propstatStatus = 0;
                }
            } else if ("prop".equals(tagLocalName) && propstatStatus == HttpStatus.SC_OK) {
                handleProperty(reader, multiStatusResponse);
            }
        }
    }

}
 
Example #2
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 #3
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public List<Folder> getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException {
    boolean isPublic = folderPath.startsWith("/public");
    FolderQueryTraversal mode = (!isPublic && recursive) ? FolderQueryTraversal.Deep : FolderQueryTraversal.Shallow;
    List<Folder> folders = new ArrayList<>();

    MultiStatusResponse[] responses = searchItems(folderPath, FOLDER_PROPERTIES, and(isTrue("isfolder"), isFalse("ishidden"), condition), mode, 0);

    for (MultiStatusResponse response : responses) {
        Folder folder = buildFolder(response);
        folders.add(buildFolder(response));
        if (isPublic && recursive) {
            getSubFolders(folder.folderPath, condition, recursive);
        }
    }
    return folders;
}
 
Example #4
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 #5
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build Contact instance from multistatusResponse info
 *
 * @param multiStatusResponse response
 * @throws IOException      on error
 * @throws DavMailException on error
 */
public Contact(MultiStatusResponse multiStatusResponse) throws IOException, DavMailException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    for (String attributeName : CONTACT_ATTRIBUTES) {
        String value = getPropertyIfExists(properties, attributeName);
        if (value != null) {
            if ("bday".equals(attributeName) || "anniversary".equals(attributeName)
                    || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
                value = convertDateFromExchange(value);
            } else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
                value = "1".equals(value) ? "true" : "false";
            }
            put(attributeName, value);
        }
    }
}
 
Example #6
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 #7
Source File: DavItemResourceBase.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public static boolean hasNonOK(MultiStatusResponse msr) {
    if (msr == null || msr.getStatus() == null) {
        return false;
    }

    for (Status status : msr.getStatus()) {

        if (status != null) {
            int statusCode = status.getStatusCode();

            if (statusCode != 200) {
                return true;
            }
        }
    }
    return false;
}
 
Example #8
Source File: CtagHandler.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
@Override
BaseDavRequest internalSyncItems() throws IOException, DavException {
	//Calendar already inited.

	DavPropertyNameSet properties = new DavPropertyNameSet();
	properties.add(DNAME_GETCTAG);

	HttpPropFindMethod method = new HttpPropFindMethod(path, properties, CalDAVConstants.DEPTH_0);
	HttpResponse httpResponse = client.execute(method, context);

	if (method.succeeded(httpResponse)) {
		for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus(httpResponse).getResponses()) {
			DavPropertySet set = response.getProperties(SC_OK);
			String ctag = AppointmentManager.getTokenFromProperty(set.get(DNAME_GETCTAG));

			if (ctag != null && !ctag.equals(calendar.getToken())) {
				EtagsHandler etagsHandler = new EtagsHandler(path, calendar, client, context, appointmentDao, utils);
				etagsHandler.syncItems();
				calendar.setToken(ctag);
			}
		}
	} else {
		log.error("Error executing PROPFIND Method, with status Code: {}", httpResponse.getStatusLine().getStatusCode());
	}
	return method;
}
 
Example #9
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 #10
Source File: ExchangeDavMethod.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
    int propstatStatus = 0;
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("status".equals(tagLocalName)) {
                if ("HTTP/1.1 200 OK".equals(reader.getElementText())) {
                    propstatStatus = HttpStatus.SC_OK;
                } else {
                    propstatStatus = 0;
                }
            } else if ("prop".equals(tagLocalName) && propstatStatus == HttpStatus.SC_OK) {
                handleProperty(reader, multiStatusResponse);
            }
        }
    }

}
 
Example #11
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 #12
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<ExchangeSession.Event> searchEvents(String folderPath, Set<String> attributes, Condition condition) throws IOException {
    List<ExchangeSession.Event> events = new ArrayList<>();
    MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow, 0);
    for (MultiStatusResponse response : responses) {
        String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype");
        Event event = new Event(response);
        //noinspection VariableNotUsedInsideIf
        if (instancetype == null) {
            // check ics content
            try {
                event.getBody();
                // getBody success => add event or task
                events.add(event);
            } catch (IOException e) {
                // invalid event: exclude from list
                LOGGER.warn("Invalid event " + event.displayName + " found at " + response.getHref(), e);
            }
        } else {
            events.add(event);
        }
    }
    return events;
}
 
Example #13
Source File: TestDavExchangeSessionOther.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Search in non ipm subtree
 *
 * @throws IOException on error
 */
public void testNonIpmSubtree() throws IOException {
    Set<String> attributes = new HashSet<>();
    attributes.add("messageclass");
    attributes.add("permanenturl");
    attributes.add("roamingxmlstream");
    attributes.add("roamingdictionary");
    attributes.add("displayname");

    MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/non_ipm_subtree", attributes, davSession.and(davSession.isTrue("ishidden")), HC4DavExchangeSession.FolderQueryTraversal.Deep, 0);
    for (MultiStatusResponse response : responses) {
        System.out.println(response.getHref() + ' ' + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
                + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());

        DavProperty<?> roamingxmlstreamProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream"));
        if (roamingxmlstreamProperty != null) {
            System.out.println("roamingxmlstream: " + new String(Base64.decodeBase64(((String) roamingxmlstreamProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }

        DavProperty<?> roamingdictionaryProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingdictionary"));
        if (roamingdictionaryProperty != null) {
            System.out.println("roamingdictionary: " + new String(Base64.decodeBase64(((String) roamingdictionaryProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }
    }
}
 
Example #14
Source File: BaseProvider.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param msr
 *            MultiStatusResponse
 * @return boolean
 */
public static boolean hasNonOK(MultiStatusResponse msr) {
    if (msr == null || msr.getStatus() == null) {
        return false;
    }

    for (Status status : msr.getStatus()) {

        if (status != null) {
            int statusCode = status.getStatusCode();

            if (statusCode != 200) {
                return true;
            }
        }
    }
    return false;
}
 
Example #15
Source File: ExchangeDavRequest.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
            String tagLocalName = reader.getLocalName();
            if (reader.getAttributeCount() > 0 && "mv.string".equals(reader.getAttributeValue(0))) {
                handleMultiValuedProperty(reader, multiStatusResponse);
            } else {
                String tagContent = getTagContent(reader);
                if (tagContent != null) {
                    multiStatusResponse.add(new DefaultDavProperty<>(tagLocalName, tagContent, namespace));
                }
            }
        }
    }
}
 
Example #16
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<ExchangeSession.Event> searchEvents(String folderPath, Set<String> attributes, Condition condition) throws IOException {
    List<ExchangeSession.Event> events = new ArrayList<>();
    MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow, 0);
    for (MultiStatusResponse response : responses) {
        String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype");
        Event event = new Event(response);
        //noinspection VariableNotUsedInsideIf
        if (instancetype == null) {
            // check ics content
            try {
                event.getBody();
                // getBody success => add event or task
                events.add(event);
            } catch (IOException e) {
                // invalid event: exclude from list
                LOGGER.warn("Invalid event " + event.displayName + " found at " + response.getHref(), e);
            }
        } else {
            events.add(event);
        }
    }
    return events;
}
 
Example #17
Source File: MultigetReport.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the hrefs provided in the report info to resources.
 */
protected void runQuery()
    throws CosmoDavException {
    DavPropertyNameSet propspec = createResultPropSpec();

    if (getResource() instanceof DavCollection) {
        DavCollection collection = (DavCollection) getResource();
        for (String href : hrefs) {
            WebDavResource target = collection.findMember(href);
            if (target != null) {
                getMultiStatus().addResponse(buildMultiStatusResponse(target, propspec));
            }
            else {
                getMultiStatus().addResponse(new MultiStatusResponse(href,404));
            }
        }
        return;
    }

    if (getResource() instanceof DavCalendarResource) {
        getMultiStatus().addResponse(buildMultiStatusResponse(getResource(), propspec));
        return;
    }

    throw new UnprocessableEntityException(getType() + " report not supported for non-calendar resources");
}
 
Example #18
Source File: DavGatewayHttpClientFacade.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute webdav request.
 *
 * @param httpClient http client instance
 * @param method     webdav method
 * @return Responses enumeration
 * @throws IOException on error
 */
public static MultiStatusResponse[] executeMethod(HttpClient httpClient, DavMethodBase method) throws IOException {
    MultiStatusResponse[] responses;
    try {
        int status = executeMethodFollowRedirectOnce(httpClient, method);

        if (status != HttpStatus.SC_MULTI_STATUS) {
            throw buildHttpResponseException(method);
        }
        responses = method.getResponseBodyAsMultiStatus().getResponses();

    } catch (DavException e) {
        throw new IOException(e.getMessage());
    } finally {
        method.releaseConnection();
    }
    return responses;
}
 
Example #19
Source File: DavGatewayHttpClientFacade.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute webdav request.
 *
 * @param httpClient http client instance
 * @param method     webdav method
 * @return Responses enumeration
 * @throws IOException on error
 */
public static MultiStatusResponse[] executeMethod(HttpClient httpClient, ExchangeDavMethod method) throws IOException {
    MultiStatusResponse[] responses;
    try {
        int status = executeMethodFollowRedirectOnce(httpClient, method);

        if (status != HttpStatus.SC_MULTI_STATUS) {
            throw buildHttpResponseException(method);
        }
        responses = method.getResponses();

    } finally {
        method.releaseConnection();
    }
    return responses;
}
 
Example #20
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build Contact instance from multistatusResponse info
 *
 * @param multiStatusResponse response
 * @throws IOException      on error
 * @throws DavMailException on error
 */
public Contact(MultiStatusResponse multiStatusResponse) throws IOException, DavMailException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    for (String attributeName : CONTACT_ATTRIBUTES) {
        String value = getPropertyIfExists(properties, attributeName);
        if (value != null) {
            if ("bday".equals(attributeName) || "anniversary".equals(attributeName)
                    || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
                value = convertDateFromExchange(value);
            } else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
                value = "1".equals(value) ? "true" : "false";
            }
            put(attributeName, value);
        }
    }
}
 
Example #21
Source File: TestExchangePropfindMethod.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testGetFolder() throws IOException {
    ExchangeSession.Folder folder = session.getFolder("INBOX");
    assertNotNull(folder);
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
       // davPropertyNameSet.add(Field.getPropertyName("displayname"));
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    //session.httpClient.executeMethod(propFindMethod);
    //propFindMethod.getResponseBodyAsMultiStatus();

    

    ExchangePropFindMethod exchangePropFindMethod = new ExchangePropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)), davPropertyNameSet, 0);
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    session.httpClient.executeMethod(exchangePropFindMethod);
     MultiStatusResponse response = exchangePropFindMethod.getResponse();
                DavPropertySet properties = response.getProperties(HttpStatus.SC_OK);
                System.out.println(properties);
}
 
Example #22
Source File: TestDavExchangeSessionOther.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve all hidden items
 *
 * @throws IOException on error
 */
public void testAllHidden() throws IOException {
    Set<String> attributes = new HashSet<>();
    attributes.add("messageclass");
    attributes.add("permanenturl");
    attributes.add("roamingxmlstream");
    attributes.add("displayname");

    MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + '/', attributes, davSession.and(davSession.isTrue("ishidden")), HC4DavExchangeSession.FolderQueryTraversal.Deep, 0);
    for (MultiStatusResponse response : responses) {
        System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
                + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());

        DavProperty<?> roamingxmlstreamProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream"));
        if (roamingxmlstreamProperty != null) {
            System.out.println(new String(Base64.decodeBase64(((String) roamingxmlstreamProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }

    }
}
 
Example #23
Source File: ExchangeDavMethod.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
            String tagLocalName = reader.getLocalName();
            if (reader.getAttributeCount() > 0 && "mv.string".equals(reader.getAttributeValue(0))) {
                 handleMultiValuedProperty(reader, multiStatusResponse);
            } else {
                String tagContent = getTagContent(reader);
                if (tagContent != null) {
                    multiStatusResponse.add(new DefaultDavProperty<>(tagLocalName, tagContent, namespace));
                }
            }
        }
    }
}
 
Example #24
Source File: ExchangeDavRequest.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected void handleMultiValuedProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
    String tagLocalName = reader.getLocalName();
    Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
    ArrayList<String> values = new ArrayList<>();
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, tagLocalName)) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagContent = getTagContent(reader);
            if (tagContent != null) {
                values.add(tagContent);
            }
        }
    }
    multiStatusResponse.add(new DefaultDavProperty<>(tagLocalName, values, namespace));
}
 
Example #25
Source File: ExchangeDavRequest.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get single Multistatus response.
 *
 * @return response
 * @throws HttpResponseException on error
 */
public MultiStatusResponse getResponse() throws HttpResponseException {
    if (responses == null || responses.size() != 1) {
        throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
    }
    return responses.get(0);
}
 
Example #26
Source File: ExchangeDavRequest.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get Multistatus responses.
 *
 * @return responses
 * @throws HttpResponseException on error
 */
public MultiStatusResponse[] getResponses() throws HttpResponseException {
    if (responses == null) {
        // TODO: compare with native HttpClient error handling
        throw new HttpResponseException(response.getStatusLine().getStatusCode(),
                response.getStatusLine().getReasonPhrase());
    }
    return responses.toArray(new MultiStatusResponse[0]);
}
 
Example #27
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 #28
Source File: MultiStatusReport.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
    * Returns a <code>MultiStatusResponse</code> describing the specified resource including the specified properties.
    */
   protected MultiStatusResponse buildMultiStatusResponse(WebDavResource resource, DavPropertyNameSet props)
           throws CosmoDavException {
       if (props.isEmpty()) {
           String href = resource.getResourceLocator().getHref(resource.isCollection());
           return new MultiStatusResponse(href, 200);
       }
return new MultiStatusResponse(resource, props, this.propfindType);
   }
 
Example #29
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 #30
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);
}