public void executeDeleteObject(final String uri) throws CloudstackRESTException { final DeleteMethod dm = (DeleteMethod) createMethod(DELETE_METHOD_TYPE, uri); dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); executeMethod(dm); if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) { final String errorMessage = responseToErrorMessage(dm); dm.releaseConnection(); s_logger.error("Failed to delete object : " + errorMessage); throw new CloudstackRESTException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); }
public JSONObject delete(String path) throws Exception { JSONObject result = new JSONObject(); DeleteMethod method = new DeleteMethod(repoHostname + ":" + repoHostPort + "/api/data/" + path); method.getParams().setCookiePolicy(CookiePolicy.RFC_2109); method.setRequestHeader("Cookie", "jsonhub-store-key=" + getStoreKey()); // client.getState().setCredentials(new AuthScope(null, repoHostPort, "authentication"), new // UsernamePasswordCredentials(memberId, memberPassword)); // method.setDoAuthentication(true); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } Reader reader = new InputStreamReader(method.getResponseBodyAsStream()); CharArrayWriter cdata = new CharArrayWriter(); char buf[] = new char[BUFFER_SIZE]; int ret; while ((ret = reader.read(buf, 0, BUFFER_SIZE)) != -1) cdata.write(buf, 0, ret); reader.close(); result = JSONObject.fromString(cdata.toString()); method.releaseConnection(); if (result.has("error")) throw new GeneralException(result.getString("error")); return result; }
public void purgeObject(String pid, boolean force) throws IOException { StringBuilder uri = new StringBuilder(getBaseUrl()); uri.append("/objects/"); uri.append(pid); uri.append("?force="); uri.append(force); DeleteMethod method = new DeleteMethod(uri.toString()); executeMethod(method); method.releaseConnection(); }
/** Remove entry from server. */ public void remove() throws ProponoException { if (getEditURI() == null) { throw new ProponoException("ERROR: cannot delete unsaved entry"); } DeleteMethod method = new DeleteMethod(getEditURI()); addAuthentication(method); try { getHttpClient().executeMethod(method); } catch (IOException ex) { throw new ProponoException("ERROR: removing entry, HTTP code", ex); } finally { method.releaseConnection(); } }
@Test public void testAddDeleteRepository() throws IOException { // Call create repository REST API String repoId = "securecentral"; String jsonRequest = "{\"id\":\"" + repoId + "\",\"url\":\"https://repo1.maven.org/maven2\",\"snapshot\":\"false\"}"; PostMethod post = httpPost("/interpreter/repository/", jsonRequest); assertThat("Test create method:", post, isCreated()); post.releaseConnection(); // Call delete repository REST API DeleteMethod delete = httpDelete("/interpreter/repository/" + repoId); assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); }
@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(); } }
@Test public void testSettingsCRUD() throws IOException { // Call Create Setting REST API String jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"session\": false }}"; PostMethod post = httpPost("/interpreter/setting/", jsonRequest); LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString()); assertThat("test create method:", post, isCreated()); Map<String, Object> resp = gson.fromJson( post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); Map<String, Object> body = (Map<String, Object>) resp.get("body"); // extract id from body string {id=2AWMQDNX7, name=md2, group=md, String newSettingId = body.toString().split(",")[0].split("=")[1]; post.releaseConnection(); // Call Update Setting REST API jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"Otherpropvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"session\": false }}"; PutMethod put = httpPut("/interpreter/setting/" + newSettingId, jsonRequest); LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString()); assertThat("test update method:", put, isAllowed()); put.releaseConnection(); // Call Delete Setting REST API DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId); LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString()); assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); }