org.apache.jackrabbit.webdav.client.methods.BaseDavRequest Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.client.methods.BaseDavRequest. 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: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportInbox() throws IOException {
    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:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/inbox/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));
    httpClient.executeDavRequest(method);
}
 
Example #2
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportTasks() throws IOException {
    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=\"VTODO\"/>" +
            "</C:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    httpClient.executeDavRequest(method);
}
 
Example #3
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportEventsOnly() throws IOException {
    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:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    httpClient.executeDavRequest(method);
}
 
Example #4
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testInvalidDavRequest() {
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity("invalid", ContentType.create("text/xml", "UTF-8")));

    try {
        httpClient.executeDavRequest(method);
        fail("Should fail");
    } catch (IOException e) {
        assertNotNull(e.getMessage());
        assertEquals(503, ((DavException)e.getCause()).getErrorCode());

    }

}
 
Example #5
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 #6
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 #7
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 #8
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testCreateCalendar() throws IOException, URISyntaxException {
    String folderName = "test & accentué";
    //String folderName = "justatest";
    URI uri = new URIBuilder().setPath("/users/" + session.getEmail() + "/calendar/" + folderName + '/').build();
    // first delete calendar
    session.deleteFolder("calendar/" + folderName);
    String body =
            "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
                    "   <C:mkcalendar xmlns:D=\"DAV:\"\n" +
                    "                 xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\n" +
                    "     <D:set>\n" +
                    "       <D:prop>\n" +
                    "         <D:displayname>" + StringUtil.xmlEncode(folderName) + "</D:displayname>\n" +
                    "         <C:calendar-description xml:lang=\"en\">Calendar description</C:calendar-description>\n" +
                    "         <C:supported-calendar-component-set>\n" +
                    "           <C:comp name=\"VEVENT\"/>\n" +
                    "         </C:supported-calendar-component-set>\n" +
                    "       </D:prop>\n" +
                    "     </D:set>\n" +
                    "   </C:mkcalendar>";
    BaseDavRequest method = new BaseDavRequest(uri) {
        @Override
        public String getMethod() {
            return "MKCALENDAR";
        }

        public boolean succeeded(HttpResponse response) {
            int status = response.getStatusLine().getStatusCode();
            return status == HttpStatus.SC_CREATED;
        }
    };
    method.setEntity(new StringEntity(body, ContentType.create("text/xml", "UTF-8")));

    httpClient.executeDavRequest(method);

    HttpGet getRequest = new HttpGet(uri);
    CloseableHttpResponse getResponse = httpClient.execute(getRequest);
    assertEquals(org.apache.commons.httpclient.HttpStatus.SC_OK, getResponse.getStatusLine().getStatusCode());
}
 
Example #9
Source File: AbstractCalendarHandler.java    From openmeetings with Apache License 2.0 2 votes vote down vote up
/**
 * Abstract method for syncing, this is implemented by subclasses to
 * perform the actual syncing.
 * @return Method which performed the execution.
 * @throws IOException on error
 * @throws DavException on error
 */
abstract BaseDavRequest internalSyncItems() throws IOException, DavException;