List of usage examples for org.apache.commons.httpclient.methods DeleteMethod releaseConnection
@Override public void releaseConnection()
From source file:org.apache.zeppelin.rest.NotebookSecurityRestApiTest.java
private void deleteNoteForUser(String noteId, String user, String pwd) throws IOException { DeleteMethod delete = httpDelete(("/notebook/" + noteId), user, pwd); assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); // make sure note is deleted if (!noteId.isEmpty()) { Note deletedNote = ZeppelinServer.notebook.getNote(noteId); assertNull("Deleted note should be null", deletedNote); }//w w w . jav a 2 s . c om }
From source file:org.apache.zeppelin.rest.ZeppelinRestApiTest.java
@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\"}]}"; 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());//from ww w . j a v a 2 s . c o m 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\"}]}"; 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(); }
From source file:org.apache.zeppelin.rest.ZeppelinRestApiTest.java
private void testDeleteNotebook(String notebookId) throws IOException { DeleteMethod delete = httpDelete(("/notebook/" + notebookId)); LOG.info("testDeleteNotebook delete response\n" + delete.getResponseBodyAsString()); assertThat("Test delete method:", delete, isAllowed()); delete.releaseConnection(); // make sure note is deleted if (!notebookId.isEmpty()) { Note deletedNote = ZeppelinServer.notebook.getNote(notebookId); assertNull("Deleted note should be null", deletedNote); }//from w w w . java 2s . com }
From source file:org.collectionspace.services.client.test.ServiceLayerTest.java
@Test public void methodNotAllowed() { if (logger.isDebugEnabled()) { logger.debug(BaseServiceTest.testBanner("methodNotAllowed", CLASS_NAME)); }/* w w w . ja v a2 s . c om*/ // Delete is not allowed on the root URL of the id service String url = serviceClient.getBaseURL() + "idgenerators"; DeleteMethod method = new DeleteMethod(url); try { int statusCode = httpClient.executeMethod(method); if (logger.isDebugEnabled()) { logger.debug(" methodNotAllowed url=" + url + " status=" + statusCode); } Assert.assertEquals(statusCode, HttpStatus.SC_METHOD_NOT_ALLOWED, "expected " + HttpStatus.SC_METHOD_NOT_ALLOWED); } catch (HttpException e) { logger.error("Fatal protocol violation: ", e); } catch (IOException e) { logger.error("Fatal transport error", e); } catch (Exception e) { logger.error("unknown exception ", e); } finally { // Release the connection. method.releaseConnection(); } }
From source file:org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplayTransport.java
public static ServiceResult doDELETE(String urlString, String authForTest, String testID, String fromTestID) throws Exception { ServiceResult pr = new ServiceResult(); pr.failureReason = ""; pr.method = "DELETE"; pr.fullURL = urlString;//ww w . j a va 2 s.co m pr.fromTestID = fromTestID; if (Tools.isEmpty(urlString)) { pr.error = "url was empty. Check the result for fromTestID: " + fromTestID + ". currentTest: " + testID; return pr; } HttpClient client = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(urlString); deleteMethod.setRequestHeader("Accept", "multipart/mixed"); deleteMethod.addRequestHeader("Accept", "application/xml"); deleteMethod.setRequestHeader("Authorization", "Basic " + authForTest); deleteMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID); int statusCode1 = 0; String res = ""; try { statusCode1 = client.executeMethod(deleteMethod); pr.responseCode = statusCode1; //System.out.println("statusCode: "+statusCode1+" statusLine ==>" + deleteMethod.getStatusLine()); pr.responseMessage = deleteMethod.getStatusText(); res = deleteMethod.getResponseBodyAsString(); deleteMethod.releaseConnection(); } catch (Throwable t) { pr.error = t.toString(); } pr.result = res; pr.responseCode = statusCode1; return pr; }
From source file:org.eclipse.osee.framework.core.util.HttpProcessor.java
public static String delete(URL url) throws Exception { String response = null;/*www . j a va 2s .c om*/ int statusCode = -1; DeleteMethod method = new DeleteMethod(url.toString()); InputStream responseInputStream = null; try { method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); statusCode = executeMethod(url, method); if (statusCode == HttpStatus.SC_ACCEPTED) { responseInputStream = method.getResponseBodyAsStream(); response = Lib.inputStreamToString(responseInputStream); } } catch (Exception ex) { throw new Exception(String.format("Error deleting resource: [%s] - status code: [%s]", url, statusCode), ex); } finally { Lib.close(responseInputStream); method.releaseConnection(); } return response; }
From source file:org.eclipsecon.e4rover.client.production.ProductionServer.java
public void leavePlayerQueue(String playerKey) throws IOException { DeleteMethod delete = new DeleteMethod(IServerConstants.QUEUE_RESTLET + "/" + playerKey); try {/*from w ww.j a v a 2 s . c o m*/ int resp = httpClient.executeMethod(delete); if (resp != HttpStatus.SC_OK) { throw new RobotServerException(resp, delete.getURI(), delete.getResponseBodyAsString()); } } finally { delete.releaseConnection(); } }
From source file:org.exist.xquery.modules.httpclient.DELETEFunction.java
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { Sequence response = null;//w w w.j a va 2 s .c o m // must be a URL if (args[0].isEmpty()) { return (Sequence.EMPTY_SEQUENCE); } //get the url String url = args[0].itemAt(0).getStringValue(); //get the persist state boolean persistState = args[1].effectiveBooleanValue(); //setup DELETE request DeleteMethod delete = new DeleteMethod(url); //setup DELETE Request Headers if (!args[2].isEmpty()) { setHeaders(delete, ((NodeValue) args[2].itemAt(0)).getNode()); } try { //execute the request response = doRequest(context, delete, persistState, null, null); } catch (IOException ioe) { throw (new XPathException(this, ioe.getMessage(), ioe)); } finally { delete.releaseConnection(); } return (response); }
From source file:org.geosdi.geoplatform.publish.HttpUtilsLocal.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; try {/*from w w w . jav a 2 s . c o m*/ HttpClient client = new HttpClient(); setAuth(client, url, user, pw); httpMethod = new DeleteMethod(url); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(httpMethod); String response = ""; if (status == HttpStatus.SC_OK) { InputStream is = httpMethod.getResponseBodyAsStream(); response = IOUtils.toString(is); if (response.trim().equals("")) { // sometimes gs rest fails if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ResponseBody is empty (this may be not an error since we just performed a DELETE call)"); } return true; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); } return true; } else { LOGGER.info("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); LOGGER.info("Response: '" + response + "'"); } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); } catch (IOException e) { LOGGER.info("Error talking to [" + url + "]", e); } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } return false; }
From source file:org.iavante.sling.commons.services.DistributionServerTestIT.java
private void deleteContent(String content) { // Delete the content DeleteMethod post_delete = new DeleteMethod(content); post_delete.setDoAuthentication(true); // post_delete.setRequestBody(data_delete); try {/*from w ww . j a v a 2 s . c o m*/ client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } System.out.println(post_delete.getStatusCode()); assert 204 == post_delete.getStatusCode(); System.out.println("Borrado contenido: " + content); post_delete.releaseConnection(); }