use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method calendarQuery.
public static Document calendarQuery(String url, Account acct) throws IOException, XmlParseException {
ReportMethod method = new ReportMethod(url);
addBasicAuthHeaderForUser(method, acct);
HttpClient client = new HttpClient();
TestCalDav.HttpMethodExecutor executor;
method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
method.setRequestEntity(new ByteArrayRequestEntity(calendar_query_etags_by_vevent.getBytes(), MimeConstants.CT_TEXT_XML));
executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
String respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
Document doc = W3cDomUtil.parseXMLToDoc(respBody);
org.w3c.dom.Element docElement = doc.getDocumentElement();
assertEquals("Report node name", DavElements.P_MULTISTATUS, docElement.getLocalName());
return doc;
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method doPropPatch.
public HttpMethodExecutor doPropPatch(Account account, String url, String body) throws IOException {
HttpClient client = new HttpClient();
PropPatchMethod propPatchMethod = new PropPatchMethod(url);
addBasicAuthHeaderForUser(propPatchMethod, account);
propPatchMethod.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
propPatchMethod.setRequestEntity(new ByteArrayRequestEntity(body.getBytes(), MimeConstants.CT_TEXT_XML));
return HttpMethodExecutor.execute(client, propPatchMethod, HttpStatus.SC_MULTI_STATUS);
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method testAndroidMeetingSeries.
@Test
public void testAndroidMeetingSeries() throws Exception {
Account dav1 = users[1].create();
Account dav2 = users[2].create();
// Force creation of mailbox - shouldn't be needed
users[2].getZMailbox();
String calFolderUrl = getFolderUrl(dav1, "Calendar").replaceAll("@", "%40");
String url = String.format("%s%s.ics", calFolderUrl, androidSeriesMeetingUid);
HttpClient client = new HttpClient();
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/calendar");
String body = androidSeriesMeetingTemplate.replace("%%ORG%%", dav1.getName()).replace("%%ATT%%", dav2.getName()).replace("%%UID%%", androidSeriesMeetingUid);
putMethod.setRequestEntity(new ByteArrayRequestEntity(body.getBytes(), MimeConstants.CT_TEXT_CALENDAR));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_CREATED);
String inboxhref = TestCalDav.waitForNewSchedulingRequestByUID(dav2, androidSeriesMeetingUid);
assertTrue("Found meeting request for newly created item", inboxhref.contains(androidSeriesMeetingUid));
GetMethod getMethod = new GetMethod(url);
addBasicAuthHeaderForUser(getMethod, dav1);
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String etag = null;
for (Header hdr : exe.respHeaders) {
if (DavProtocol.HEADER_ETAG.equals(hdr.getName())) {
etag = hdr.getValue();
}
}
assertNotNull("ETag from get", etag);
// Check that we fail if the etag is wrong
putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/calendar");
putMethod.addRequestHeader(DavProtocol.HEADER_IF_MATCH, "willNotMatch");
putMethod.setRequestEntity(new ByteArrayRequestEntity(body.getBytes(), MimeConstants.CT_TEXT_CALENDAR));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_PRECONDITION_FAILED);
PropFindMethod propFindMethod = new PropFindMethod(getFolderUrl(dav1, "Calendar"));
addBasicAuthHeaderForUser(propFindMethod, dav1);
TestCalDav.HttpMethodExecutor executor;
String respBody;
Element respElem;
propFindMethod.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
propFindMethod.addRequestHeader("Depth", "1");
propFindMethod.setRequestEntity(new ByteArrayRequestEntity(propFindEtagResType.getBytes(), MimeConstants.CT_TEXT_XML));
executor = new TestCalDav.HttpMethodExecutor(client, propFindMethod, HttpStatus.SC_MULTI_STATUS);
respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
respElem = Element.XMLElement.parseXML(respBody);
assertEquals("name of top element in propfind response", DavElements.P_MULTISTATUS, respElem.getName());
assertTrue("propfind response should have child elements", respElem.hasChildren());
Iterator<Element> iter = respElem.elementIterator();
boolean hasCalendarHref = false;
boolean hasCalItemHref = false;
while (iter.hasNext()) {
Element child = iter.next();
if (DavElements.P_RESPONSE.equals(child.getName())) {
Iterator<Element> hrefIter = child.elementIterator(DavElements.P_HREF);
while (hrefIter.hasNext()) {
Element href = hrefIter.next();
calFolderUrl.endsWith(href.getText());
hasCalendarHref = hasCalendarHref || calFolderUrl.endsWith(href.getText());
hasCalItemHref = hasCalItemHref || url.endsWith(href.getText());
}
}
}
assertTrue("propfind response contained entry for calendar", hasCalendarHref);
assertTrue("propfind response contained entry for calendar entry ", hasCalItemHref);
DeleteMethod deleteMethod = new DeleteMethod(url);
addBasicAuthHeaderForUser(deleteMethod, dav1);
HttpMethodExecutor.execute(client, deleteMethod, HttpStatus.SC_NO_CONTENT);
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method doIcalPut.
public HttpMethodExecutor doIcalPut(String url, Account authAcct, byte[] vcalendar, int expected) throws IOException {
HttpClient client = new HttpClient();
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, authAcct);
putMethod.addRequestHeader("Content-Type", "text/calendar");
putMethod.setRequestEntity(new ByteArrayRequestEntity(vcalendar, MimeConstants.CT_TEXT_CALENDAR));
return HttpMethodExecutor.execute(client, putMethod, expected);
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method checkPropFindSupportedCalendarComponentSet.
public void checkPropFindSupportedCalendarComponentSet(Account user, String fullurl, String shorturl, String[] compNames) throws Exception {
PropFindMethod method = new PropFindMethod(fullurl);
addBasicAuthHeaderForUser(method, user);
HttpClient client = new HttpClient();
TestCalDav.HttpMethodExecutor executor;
String respBody;
method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
method.setRequestEntity(new ByteArrayRequestEntity(propFindSupportedCalendarComponentSet.getBytes(), MimeConstants.CT_TEXT_XML));
executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
Document doc = W3cDomUtil.parseXMLToDoc(respBody);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(TestCalDav.NamespaceContextForXPath.forCalDAV());
XPathExpression xPathExpr;
String text;
NodeList result;
xPathExpr = xpath.compile("/D:multistatus/D:response/D:href/text()");
result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("HREF", shorturl.replaceAll("@", "%40"), text);
xPathExpr = xpath.compile("/D:multistatus/D:response/D:propstat/D:status/text()");
text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("status", "HTTP/1.1 200 OK", text);
xPathExpr = xpath.compile("/D:multistatus/D:response/D:propstat/D:prop/C:supported-calendar-component-set/C:comp");
result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
assertEquals("Number of comp nodes under supported-calendar-component-set", compNames.length, result.getLength());
List<String> names = Arrays.asList(compNames);
for (int ndx = 0; ndx < result.getLength(); ndx++) {
org.w3c.dom.Element child = (org.w3c.dom.Element) result.item(ndx);
String name = child.getAttribute("name");
assertNotNull("comp should have a 'name' attribute", name);
assertTrue(String.format("comp 'name' attribute '%s' should be one of the expected names", name), names.contains(name));
}
}
Aggregations