use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class UserServlet method getRemoteResourceAsUpload.
public static FileUploadServlet.Upload getRemoteResourceAsUpload(AuthToken at, ItemId iid, Map<String, String> params) throws ServiceException, IOException {
Map<String, String> pcopy = new HashMap<String, String>(params);
pcopy.put(QP_ID, iid.toString());
// fetch from remote store
Provisioning prov = Provisioning.getInstance();
Account target = prov.get(AccountBy.id, iid.getAccountId(), at);
String url = getRemoteUrl(target, null, pcopy);
Pair<Header[], HttpInputStream> response = getRemoteResourceAsStream(at.toZAuthToken(), url);
// and save the result as an upload
String ctype = "text/plain", filename = null;
for (Header hdr : response.getFirst()) {
String hname = hdr.getName().toLowerCase();
if (hname.equals("content-type"))
ctype = hdr.getValue();
else if (hname.equals("content-disposition"))
filename = new ContentDisposition(hdr.getValue()).getParameter("filename");
}
if (filename == null || filename.equals(""))
filename = new ContentType(ctype).getParameter("name");
if (filename == null || filename.equals(""))
filename = "unknown";
return FileUploadServlet.saveUpload(response.getSecond(), filename, ctype, at.getAccountId());
}
use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class SoapDebugListener method receiveSoapMessage.
@Override
public void receiveSoapMessage(PostMethod postMethod, Element envelope) {
if (level == Level.OFF) {
return;
}
printer.println();
printer.println("=== Response ===");
if (Level.needsHeader(level)) {
Header[] headers = postMethod.getResponseHeaders();
for (Header header : headers) {
// trim the ending crlf
printer.println(header.toString().trim());
}
printer.println();
}
if (Level.needsBody(level)) {
printer.println(envelope.prettyPrint());
}
}
use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class SoapDebugListener method sendSoapMessage.
@Override
public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState) {
if (level == Level.OFF) {
return;
}
printer.println();
printer.println("=== Request ===");
if (Level.needsHeader(level)) {
try {
URI uri = postMethod.getURI();
printer.println(uri.toString());
} catch (URIException e) {
e.printStackTrace();
}
// headers
Header[] headers = postMethod.getRequestHeaders();
for (Header header : headers) {
// trim the ending crlf
printer.println(header.toString().trim());
}
printer.println();
//cookies
if (httpState != null) {
Cookie[] cookies = httpState.getCookies();
for (Cookie cookie : cookies) {
printer.println("Cookie: " + cookie.toString());
}
}
printer.println();
}
if (Level.needsBody(level)) {
printer.println(envelope.prettyPrint());
}
}
use of org.apache.commons.httpclient.Header 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.Header 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