use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class ExchangeMessage method createMethod.
public HttpMethod createMethod(String uri, FreeBusy fb) throws IOException {
// PROPPATCH
PostMethod method = new PostMethod(uri) {
private String PROPPATCH = "PROPPATCH";
public String getName() {
return PROPPATCH;
}
};
Document doc = createRequest(fb);
byte[] buf = DomUtil.getBytes(doc);
if (ZimbraLog.fb.isDebugEnabled())
ZimbraLog.fb.debug(new String(buf, "UTF-8"));
ByteArrayRequestEntity re = new ByteArrayRequestEntity(buf, "text/xml");
method.setRequestEntity(re);
return method;
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method groupMemberSetExpandProperty.
public static Document groupMemberSetExpandProperty(Account acct, Account member, boolean proxyWrite) throws IOException, ServiceException {
String url = proxyWrite ? TestCalDav.getCalendarProxyWriteUrl(acct) : TestCalDav.getCalendarProxyReadUrl(acct);
url = url.replaceAll("@", "%40");
String href = proxyWrite ? UrlNamespace.getCalendarProxyWriteUrl(acct, acct) : UrlNamespace.getCalendarProxyReadUrl(acct, acct);
href = href.replaceAll("@", "%40");
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(TestCalDav.expandPropertyGroupMemberSet.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());
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(TestCalDav.NamespaceContextForXPath.forCalDAV());
XPathExpression xPathExpr;
try {
String xpathS = "/D:multistatus/D:response/D:href/text()";
xPathExpr = xpath.compile(xpathS);
String text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("HREF for response", href, text);
xpathS = "/D:multistatus/D:response/D:propstat/D:prop/D:group-member-set/D:response/D:href/text()";
xPathExpr = xpath.compile(xpathS);
text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("HREF for sharee", UrlNamespace.getPrincipalUrl(member).replaceAll("@", "%40"), text);
} catch (XPathExpressionException e1) {
ZimbraLog.test.debug("xpath problem", e1);
}
return doc;
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method testXBusyMacAttach.
@Test
public void testXBusyMacAttach() throws ServiceException, IOException {
Account dav1 = users[1].create();
String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(smallBusyMacAttach.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String location = null;
for (Header hdr : exe.respHeaders) {
if ("Location".equals(hdr.getName())) {
location = hdr.getValue();
}
}
assertNotNull("Location Header returned when creating", location);
String url = String.format("%s%s", contactsFolderUrl, location.substring(location.lastIndexOf('/') + 1));
GetMethod getMethod = new GetMethod(url);
addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addRequestHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = new String(exe.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
String[] expecteds = { "\r\nX-BUSYMAC-ATTACH;X-FILENAME=favicon.ico;ENCODING=B:AAABAAEAEBAAAAEAIABoBA\r\n", "\r\n AAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAABMLAAATCwAAAAAAAAAAAAAAAAAAw4cAY8\r\n", "\r\nX-BUSYMAC-MODIFIED-BY:Gren Elliot\r\n", "\r\nX-CUSTOM:one two three four five six seven eight nine ten eleven twelve t\r\n hirteen fourteen fifteen", "\r\nX-CUSTOM:Here are my simple\\Nmultiline\\Nnotes\r\n", "\r\nX-CUSTOM;TYPE=pref:semi-colon\\;seperated\\;\"stuff\"\\;here\r\n", "\r\nX-CUSTOM:comma\\,\"stuff\"\\,'there'\\,too\r\n", "\r\nX-HOBBY:my backslash\\\\ hobbies\r\n", "\r\nX-CREATED:2015-04-05T09:50:44Z\r\n" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = users[1].getZMailbox();
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 1, hits.size());
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method testBadPostToSchedulingOutbox.
@Test
public void testBadPostToSchedulingOutbox() throws Exception {
Account dav1 = users[1].create();
Account dav2 = users[2].create();
Account dav3 = users[3].create();
String url = getSchedulingOutboxUrl(dav2, dav2);
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
addBasicAuthHeaderForUser(method, dav2);
method.addRequestHeader("Content-Type", "text/calendar");
method.addRequestHeader("Originator", "mailto:" + dav2.getName());
method.addRequestHeader("Recipient", "mailto:" + dav3.getName());
method.setRequestEntity(new ByteArrayRequestEntity(exampleCancelIcal(dav1, dav2, dav3).getBytes(), MimeConstants.CT_TEXT_CALENDAR));
HttpMethodExecutor.execute(client, method, HttpStatus.SC_BAD_REQUEST);
}
use of org.apache.commons.httpclient.methods.ByteArrayRequestEntity in project zm-mailbox by Zimbra.
the class TestCalDav method testAppleStyleGroup.
@Test
public void testAppleStyleGroup() throws ServiceException, IOException {
Account dav1 = users[1].create();
String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(rachelVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupCreate.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String groupLocation = null;
for (Header hdr : exe.respHeaders) {
if ("Location".equals(hdr.getName())) {
groupLocation = hdr.getValue();
}
}
assertNotNull("Location Header returned when creating Group", groupLocation);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(parisVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/vcard");
putMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupModify.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
GetMethod getMethod = new GetMethod(url);
addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addRequestHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = new String(exe.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
String[] expecteds = { "X-ADDRESSBOOKSERVER-KIND:group", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:BE43F16D-336E-4C3E-BAE6-22B8F245A986", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:07139DE2-EA7B-46CB-A970-C4DF7F72D9AE" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
// members are actually stored in a different way. Make sure it isn't a fluke
// that the GET response contained the correct members by checking that the members
// appear where expected in a search hit.
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = users[1].getZMailbox();
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 3, hits.size());
boolean seenGroup = false;
for (SearchHit hit : hits) {
ContactInfo contactInfo = (ContactInfo) hit;
if ("BlueGroup".equals(contactInfo.getFileAs())) {
seenGroup = true;
assertEquals("Number of members of group in search hit", 2, contactInfo.getContactGroupMembers().size());
}
ZimbraLog.test.info("Hit %s class=%s", hit, hit.getClass().getName());
}
assertTrue("Seen group", seenGroup);
}
Aggregations