Java Code Examples for org.apache.commons.httpclient.methods.DeleteMethod#releaseConnection()
The following examples show how to use
org.apache.commons.httpclient.methods.DeleteMethod#releaseConnection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Given host, port and schema name, send a http DELETE request to delete the {@link Schema}. * * @return <code>true</code> on success. * <P><code>false</code> on failure. */ public static boolean deleteSchema(@Nonnull String host, int port, @Nonnull String schemaName) { Preconditions.checkNotNull(host); Preconditions.checkNotNull(schemaName); try { URL url = new URL("http", host, port, "/schemas/" + schemaName); DeleteMethod httpDelete = new DeleteMethod(url.toString()); try { int responseCode = HTTP_CLIENT.executeMethod(httpDelete); if (responseCode >= 400) { String response = httpDelete.getResponseBodyAsString(); LOGGER.warn("Got error response code: {}, response: {}", responseCode, response); return false; } return true; } finally { httpDelete.releaseConnection(); } } catch (Exception e) { LOGGER.error("Caught exception while getting the schema: {} from host: {}, port: {}", schemaName, host, port, e); return false; } }
Example 2
Source File: CatalogITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testRemoveOwner() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).path("owners").path(id1.getUser().getKey().toString()) .build(); final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); method.releaseConnection(); assertEquals(200, code); final CatalogEntry entry = catalogService.loadCatalogEntry(entry1.getKey()); final List<Identity> identities = securityManager.getIdentitiesOfSecurityGroup(entry.getOwnerGroup()); boolean found = false; for (final Identity identity : identities) { if (identity.getKey().equals(id1.getKey())) { found = true; } } assertFalse(found); }
Example 3
Source File: CatalogITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testDeleteCatalogEntry() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry2.getKey().toString()).build(); final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(200, code); method.releaseConnection(); final List<CatalogEntry> entries = catalogService.getChildrenOf(root1); for (final CatalogEntry entry : entries) { assertFalse(entry.getKey().equals(entry2.getKey())); } }
Example 4
Source File: UserAuthenticationMgmtITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testDeleteAuthentications() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // create an authentication token final Identity adminIdent = baseSecurity.findIdentityByName("administrator"); final Authentication authentication = baseSecurity.createAndPersistAuthentication(adminIdent, "REST-A-2", "administrator", "credentials"); assertTrue(authentication != null && authentication.getKey() != null && authentication.getKey().longValue() > 0); DBFactory.getInstance().intermediateCommit(); // delete an authentication token final String request = "/users/administrator/auth/" + authentication.getKey().toString(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200); method.releaseConnection(); final Authentication refAuth = baseSecurity.findAuthentication(adminIdent, "REST-A-2"); assertNull(refAuth); }
Example 5
Source File: InterpreterRestApiTest.java From zeppelin with Apache License 2.0 | 6 votes |
@Test public void testAddDeleteRepository() throws IOException { // Call create repository 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, isAllowed()); post.releaseConnection(); // Call delete repository API DeleteMethod delete = httpDelete("/interpreter/repository/" + repoId); assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); }
Example 6
Source File: ESBJAVA4852URITemplateWithCompleteURLTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = { "wso2.esb" }, description = "Sending complete URL to API and for dispatching") public void testCompleteURLWithHTTPMethod() throws Exception { logReader.start(); DeleteMethod delete = new DeleteMethod(getApiInvocationURL( "myApi1/order/21441/item/17440079" + "?message_id=41ec2ec4-e629-4e04-9fdf-c32e97b35bd1")); HttpClient httpClient = new HttpClient(); try { httpClient.executeMethod(delete); Assert.assertEquals(delete.getStatusLine().getStatusCode(), 202, "Response code mismatched"); } finally { delete.releaseConnection(); } Assert.assertTrue(logReader.checkForLog("order API INVOKED", DEFAULT_TIMEOUT), "Request Not Dispatched to API when HTTP method having full url"); logReader.stop(); }
Example 7
Source File: ZeppelinRestApiTest.java From zeppelin with Apache License 2.0 | 6 votes |
@Test public void testDeleteParagraph() throws IOException { Note note = null; try { note = TestUtils.getInstance(Notebook.class).createNote("note1_testDeleteParagraph", anonymous); Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); p.setTitle("title1"); p.setText("text1"); TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId()); assertThat("Test delete method: ", delete, isAllowed()); delete.releaseConnection(); Note retrNote = TestUtils.getInstance(Notebook.class).getNote(note.getId()); Paragraph retrParagrah = retrNote.getParagraph(p.getId()); assertNull("paragraph should be deleted", retrParagrah); } finally { //cleanup if (null != note) { TestUtils.getInstance(Notebook.class).removeNote(note, anonymous); } } }
Example 8
Source File: CatalogITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testRemoveOwner() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).path("owners").path(id1.getUser().getKey().toString()) .build(); final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); method.releaseConnection(); assertEquals(200, code); final CatalogEntry entry = catalogService.loadCatalogEntry(entry1.getKey()); final List<Identity> identities = securityManager.getIdentitiesOfSecurityGroup(entry.getOwnerGroup()); boolean found = false; for (final Identity identity : identities) { if (identity.getKey().equals(id1.getKey())) { found = true; } } assertFalse(found); }
Example 9
Source File: UserMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testDeleteUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // delete an authentication token final String request = "/users/" + id2.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200); method.releaseConnection(); final Identity deletedIdent = securityManager.loadIdentityByKey(id2.getKey()); assertNotNull(deletedIdent);// Identity aren't deleted anymore assertEquals(Identity.STATUS_DELETED, deletedIdent.getStatus()); }
Example 10
Source File: UserMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testDeleteUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // delete an authentication token final String request = "/users/" + id2.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200); method.releaseConnection(); final Identity deletedIdent = securityManager.loadIdentityByKey(id2.getKey()); assertNotNull(deletedIdent);// Identity aren't deleted anymore assertEquals(Identity.STATUS_DELETED, deletedIdent.getStatus()); }
Example 11
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testDeleteCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g1.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); method.releaseConnection(); assertEquals(200, code); final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false); assertNull(bg); }
Example 12
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testBasicSecurityDeleteCall() throws IOException { final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g2.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); method.releaseConnection(); assertEquals(401, code); }
Example 13
Source File: ClientEntry.java From rome with Apache License 2.0 | 5 votes |
/** * Remove entry from server. */ public void remove() throws ProponoException { if (getEditURI() == null) { throw new ProponoException("ERROR: cannot delete unsaved entry"); } final DeleteMethod method = new DeleteMethod(getEditURI()); addAuthentication(method); try { getHttpClient().executeMethod(method); } catch (final IOException ex) { throw new ProponoException("ERROR: removing entry, HTTP code", ex); } finally { method.releaseConnection(); } }
Example 14
Source File: ESBJAVA4852URITemplateWithCompleteURLTestCase.java From product-ei with Apache License 2.0 | 5 votes |
@Test(groups = {"wso2.esb"}, description = "Sending complete URL to API and for dispatching") public void testCompleteURLWithHTTPMethod() throws Exception { DeleteMethod delete = new DeleteMethod(getApiInvocationURL("myApi1/order/21441/item/17440079" + "?message_id=41ec2ec4-e629-4e04-9fdf-c32e97b35bd1")); HttpClient httpClient = new HttpClient(); LogViewerClient logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie()); logViewerClient.clearLogs(); try { httpClient.executeMethod(delete); Assert.assertEquals(delete.getStatusLine().getStatusCode(), 202, "Response code mismatched"); } finally { delete.releaseConnection(); } LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs(); boolean isLogMessageFound = false; for (LogEvent log : logEvents) { if (log != null && log.getMessage().contains("order API INVOKED")) { isLogMessageFound = true; break; } } Assert.assertTrue(isLogMessageFound, "Request Not Dispatched to API when HTTP method having full url"); }
Example 15
Source File: ZeppelinRestApiTest.java From zeppelin with Apache License 2.0 | 4 votes |
@Test public void testCronDisable() throws Exception { Note note = null; try { // create a note and a paragraph System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "false"); note = TestUtils.getInstance(Notebook.class).createNote("note1_testCronDisable", anonymous); note.setName("note for run test"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); paragraph.setText("%md This is test paragraph."); Map config = paragraph.getConfig(); config.put("enabled", true); paragraph.setConfig(config); note.runAll(AuthenticationInfo.ANONYMOUS, false, false, new HashMap<>()); String jsonRequest = "{\"cron\":\"* * * * * ?\" }"; // right cron expression. PostMethod postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest); assertThat("", postCron, isForbidden()); postCron.releaseConnection(); System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "true"); System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_FOLDERS.getVarName(), "/System"); note.setName("System/test2"); note.runAll(AuthenticationInfo.ANONYMOUS, false, false, new HashMap<>()); postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest); assertThat("", postCron, isAllowed()); postCron.releaseConnection(); Thread.sleep(1000); // remove cron job. DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId()); assertThat("", deleteCron, isAllowed()); deleteCron.releaseConnection(); Thread.sleep(1000); System.clearProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_FOLDERS.getVarName()); } finally { //cleanup if (null != note) { TestUtils.getInstance(Notebook.class).removeNote(note, anonymous); } System.clearProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName()); } }
Example 16
Source File: ZeppelinRestApiTest.java From zeppelin with Apache License 2.0 | 4 votes |
@Test public void testNoteJobs() throws Exception { LOG.info("testNoteJobs"); Note note = null; try { // Create note to run test. note = TestUtils.getInstance(Notebook.class).createNote("note1_testNoteJobs", anonymous); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); Map config = paragraph.getConfig(); config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is test paragraph."); TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); String noteId = note.getId(); note.runAll(anonymous, true, false, new HashMap<>()); // wait until job is finished or timeout. int timeout = 1; while (!paragraph.isTerminated()) { Thread.sleep(1000); if (timeout++ > 10) { LOG.info("testNoteJobs timeout job."); break; } } // Call Run note jobs REST API PostMethod postNoteJobs = httpPost("/notebook/job/" + noteId + "?blocking=true", ""); assertThat("test note jobs run:", postNoteJobs, isAllowed()); postNoteJobs.releaseConnection(); // Call Stop note jobs REST API DeleteMethod deleteNoteJobs = httpDelete("/notebook/job/" + noteId); assertThat("test note stop:", deleteNoteJobs, isAllowed()); deleteNoteJobs.releaseConnection(); Thread.sleep(1000); // Call Run paragraph REST API PostMethod postParagraph = httpPost("/notebook/job/" + noteId + "/" + paragraph.getId(), ""); assertThat("test paragraph run:", postParagraph, isAllowed()); postParagraph.releaseConnection(); Thread.sleep(1000); // Call Stop paragraph REST API DeleteMethod deleteParagraph = httpDelete("/notebook/job/" + noteId + "/" + paragraph.getId()); assertThat("test paragraph stop:", deleteParagraph, isAllowed()); deleteParagraph.releaseConnection(); Thread.sleep(1000); } finally { //cleanup if (null != note) { TestUtils.getInstance(Notebook.class).removeNote(note, anonymous); } } }
Example 17
Source File: ZeppelinRestApiTest.java From zeppelin with Apache License 2.0 | 4 votes |
private void testDeleteNotExistNote(String noteId) throws IOException { DeleteMethod delete = httpDelete(("/notebook/" + noteId)); LOG.info("testDeleteNote delete response\n" + delete.getResponseBodyAsString()); assertThat("Test delete method:", delete, isNotFound()); delete.releaseConnection(); }
Example 18
Source File: InterpreterRestApiTest.java From zeppelin with Apache License 2.0 | 4 votes |
@Test public void testSettingsCreateWithInvalidName() throws IOException { String reqBody = "{" + "\"name\": \"mdName\"," + "\"group\": \"md\"," + "\"properties\": {" + "\"propname\": {" + "\"value\": \"propvalue\"," + "\"name\": \"propname\"," + "\"type\": \"textarea\"" + "}" + "}," + "\"interpreterGroup\": [" + "{" + "\"class\": \"org.apache.zeppelin.markdown.Markdown\"," + "\"name\": \"md\"" + "}" + "]," + "\"dependencies\": []," + "\"option\": {" + "\"remote\": true," + "\"session\": false" + "}" + "}"; JsonObject jsonRequest = gson.fromJson(StringUtils.replace(reqBody, "mdName", "mdValidName"), JsonElement.class).getAsJsonObject(); PostMethod post = httpPost("/interpreter/setting/", jsonRequest.toString()); String postResponse = post.getResponseBodyAsString(); LOG.info("testSetting with valid name\n" + post.getResponseBodyAsString()); InterpreterSetting created = convertResponseToInterpreterSetting(postResponse); String newSettingId = created.getId(); // then : call create setting API assertThat("test create method:", post, isAllowed()); post.releaseConnection(); // when: call delete setting API DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId); LOG.info("testSetting delete response\n" + delete.getResponseBodyAsString()); // then: call delete setting API assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); JsonObject jsonRequest2 = gson.fromJson(StringUtils.replace(reqBody, "mdName", "name space"), JsonElement.class).getAsJsonObject(); PostMethod post2 = httpPost("/interpreter/setting/", jsonRequest2.toString()); LOG.info("testSetting with name with space\n" + post2.getResponseBodyAsString()); assertThat("test create method with space:", post2, isNotFound()); post2.releaseConnection(); JsonObject jsonRequest3 = gson.fromJson(StringUtils.replace(reqBody, "mdName", ""), JsonElement.class).getAsJsonObject(); PostMethod post3 = httpPost("/interpreter/setting/", jsonRequest3.toString()); LOG.info("testSetting with empty name\n" + post3.getResponseBodyAsString()); assertThat("test create method with empty name:", post3, isNotFound()); post3.releaseConnection(); }
Example 19
Source File: ClusterEventTest.java From zeppelin with Apache License 2.0 | 4 votes |
@Test public void testInterpreterEvent() throws IOException, InterruptedException { // when: Create 1 interpreter settings `sh1` String md1Name = "sh1"; String md1Dep = "org.apache.drill.exec:drill-jdbc:jar:1.7.0"; String reqBody1 = "{\"name\":\"" + md1Name + "\",\"group\":\"sh\"," + "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " + "\"type\": \"textarea\"}}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.shell.ShellInterpreter\"," + "\"name\":\"md\"}]," + "\"dependencies\":[ {\n" + " \"groupArtifactVersion\": \"" + md1Dep + "\",\n" + " \"exclusions\":[]\n" + " }]," + "\"option\": { \"remote\": true, \"session\": false }}"; PostMethod post = httpPost("/interpreter/setting", reqBody1); String postResponse = post.getResponseBodyAsString(); LOG.info("testCreatedInterpreterDependencies create response\n" + post.getResponseBodyAsString()); InterpreterSetting created = convertResponseToInterpreterSetting(postResponse); MatcherAssert.assertThat("test create method:", post, isAllowed()); post.releaseConnection(); // 1. Call settings API GetMethod get = httpGet("/interpreter/setting"); String rawResponse = get.getResponseBodyAsString(); get.releaseConnection(); // 2. Parsing to List<InterpreterSettings> JsonObject responseJson = gson.fromJson(rawResponse, JsonElement.class).getAsJsonObject(); JsonArray bodyArr = responseJson.getAsJsonArray("body"); List<InterpreterSetting> settings = new Gson().fromJson(bodyArr, new TypeToken<ArrayList<InterpreterSetting>>() { }.getType()); // 3. Filter interpreters out we have just created InterpreterSetting md1 = null; for (InterpreterSetting setting : settings) { if (md1Name.equals(setting.getName())) { md1 = setting; } } // then: should get created interpreters which have different dependencies // 4. Validate each md interpreter has its own dependencies assertEquals(1, md1.getDependencies().size()); assertEquals(md1Dep, md1.getDependencies().get(0).getGroupArtifactVersion()); Thread.sleep(1000); checkClusterIntpSettingEventListener(); // 2. test update Interpreter String rawRequest = "{\"name\":\"sh1\",\"group\":\"sh\"," + "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " + "\"type\": \"textarea\"}}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\"," + "\"name\":\"md\"}],\"dependencies\":[]," + "\"option\": { \"remote\": true, \"session\": false }}"; JsonObject jsonRequest = gson.fromJson(rawRequest, JsonElement.class).getAsJsonObject(); // when: call update setting API JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("name", "propname2"); jsonObject.addProperty("value", "this is new prop"); jsonObject.addProperty("type", "textarea"); jsonRequest.getAsJsonObject("properties").add("propname2", jsonObject); PutMethod put = httpPut("/interpreter/setting/" + created.getId(), jsonRequest.toString()); LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString()); // then: call update setting API MatcherAssert.assertThat("test update method:", put, isAllowed()); put.releaseConnection(); Thread.sleep(1000); checkClusterIntpSettingEventListener(); // 3: call delete setting API DeleteMethod delete = httpDelete("/interpreter/setting/" + created.getId()); LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString()); // then: call delete setting API MatcherAssert.assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); Thread.sleep(1000); checkClusterIntpSettingEventListener(); }
Example 20
Source File: BigSwitchBcfApi.java From cloudstack with Apache License 2.0 | 3 votes |
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; }