use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.
the class MailboxTestUtil method cleanupIndexStore.
public static void cleanupIndexStore(Mailbox mbox) {
IndexStore index = mbox.index.getIndexStore();
if (index instanceof ElasticSearchIndex) {
String key = mbox.getAccountId();
String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
HttpMethod method = new DeleteMethod(indexUrl);
try {
ElasticSearchConnector connector = new ElasticSearchConnector();
int statusCode = connector.executeMethod(method);
if (statusCode == HttpStatus.SC_OK) {
boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
if (!ok || !acknowledged) {
ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
}
} else {
String error = connector.getStringAtJsonPath(new String[] { "error" });
if (error != null && error.startsWith("IndexMissingException")) {
ZimbraLog.index.debug("Unable to delete index for key=%s. Index is missing", key);
} else {
ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
}
}
} catch (HttpException e) {
ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
} catch (IOException e) {
ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
}
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.
the class HttpStoreManager method deleteFromStore.
@Override
public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException {
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator));
try {
int statusCode = HttpClientUtil.executeMethod(client, delete);
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
return true;
} else if (statusCode == HttpStatus.SC_NOT_FOUND) {
return false;
} else {
throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText());
}
} finally {
delete.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod 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.DeleteMethod in project zm-mailbox by Zimbra.
the class TestCalDav method attendeeDeleteFromCalendar.
private void attendeeDeleteFromCalendar(boolean suppressReply) throws Exception {
Account dav1 = users[1].create();
users[2].create();
String url = getSchedulingInboxUrl(dav1, dav1);
ReportMethod method = new ReportMethod(url);
addBasicAuthHeaderForUser(method, dav1);
ZMailbox organizer = users[2].getZMailbox();
// Force creation of mailbox - shouldn't be needed
users[1].getZMailbox();
String subject = String.format("%s %s", NAME_PREFIX, suppressReply ? "testInvite which shouldNOT be replied to" : "testInvite to be auto-declined");
Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
TestUtil.createAppointment(organizer, subject, dav1.getName(), startDate, endDate);
// Wait for appointment to arrive
String href = waitForNewSchedulingRequestByUID(dav1, "");
assertNotNull("href for inbox invitation", href);
String uid = href.substring(href.lastIndexOf('/') + 1);
uid = uid.substring(0, uid.indexOf(',') - 1);
String calFolderUrl = getFolderUrl(dav1, "Calendar");
String delurl = waitForItemInCalendarCollectionByUID(calFolderUrl, dav1, uid, true, 5000);
StringBuilder sb = getLocalServerRoot().append(delurl);
DeleteMethod delMethod = new DeleteMethod(sb.toString());
addBasicAuthHeaderForUser(delMethod, dav1);
if (suppressReply) {
delMethod.addRequestHeader(DavProtocol.HEADER_SCHEDULE_REPLY, "F");
}
HttpClient client = new HttpClient();
HttpMethodExecutor.execute(client, delMethod, HttpStatus.SC_NO_CONTENT);
List<ZMessage> msgs;
if (suppressReply) {
// timeout may be a bit short but don't want long time wastes in test suite.
msgs = TestUtil.waitForMessages(organizer, "is:invite is:unread inid:2 after:\"-1month\"", 0, 2000);
if (msgs != null) {
assertEquals("Should be no DECLINE reply msg", 0, msgs.size());
}
} else {
msgs = TestUtil.waitForMessages(organizer, "is:invite is:unread inid:2 after:\"-1month\"", 1, 10000);
assertNotNull("inbox DECLINE reply msgs", msgs);
assertEquals("Should be 1 DECLINE reply msg", 1, msgs.size());
assertNotNull("inbox DECLINE reply msg invite", msgs.get(0).getInvite());
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project cloudstack by apache.
the class BigSwitchBcfApi method executeDeleteObject.
protected String executeDeleteObject(final String uri) throws BigSwitchBcfApiException {
checkInvariants();
DeleteMethod dm = (DeleteMethod) createMethod("delete", uri, _port);
setHttpHeader(dm);
executeMethod(dm);
String hash = checkResponse(dm, "BigSwitch HTTP delete failed: ");
dm.releaseConnection();
return hash;
}
Aggregations