List of usage examples for org.apache.commons.httpclient.methods DeleteMethod releaseConnection
@Override public void releaseConnection()
From source file:org.sonatype.nexus.restlight.testharness.DELETEFixtureTest.java
@Test public void testDelete() throws HttpException, IOException, JDOMException { Document doc = new Document().setRootElement(new Element("root")); fixture.setResponseDocument(doc);//from w ww . j a v a 2 s . co m String url = "http://localhost:" + fixture.getPort(); HttpClient client = new HttpClient(); setupAuthentication(client); DeleteMethod get = new DeleteMethod(url); client.executeMethod(get); SAXBuilder builder = new SAXBuilder(); Document resp = builder.build(get.getResponseBodyAsStream()); get.releaseConnection(); XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); assertEquals(outputter.outputString(doc), outputter.outputString(resp)); }
From source file:org.ws4d.pipes.modules.http.Delete.java
public void doWork() { // execute base module doWork() super.doWork(); // check if we can terminate if (canClose()) { closeAllPorts();//from w ww .j a v a 2 s .c o m return; } if (getUrl() != null) { final DeleteMethod method = new DeleteMethod(getUrl()); try { getClient().executeMethod(method); setOutData(PORT_STATUSCODE, method.getStatusCode()); setOutData(PORT_STATUSLINE, method.getStatusLine()); } catch (Exception e) { getLogger().log(Level.SEVERE, "Can't execute http get request: ", e); } finally { method.releaseConnection(); } } }
From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java
public boolean deleteProject(Application application, String userName, String tenantDomain) throws AppFactoryException { String url = issueTrackerUrl + "services/tenant/" + tenantDomain + "/project/" + application.getId(); DeleteMethod deleteProject = new DeleteMethod(url); int result = -1; try {/*from www. j a v a 2 s . c o m*/ HttpClient httpclient = new HttpClient(); result = httpclient.executeMethod(deleteProject); } catch (Exception e) { String msg = "Error while creating project in issue repository for " + application.getName(); log.error(msg); if (log.isDebugEnabled()) { log.debug(msg, e); } throw new AppFactoryException(msg, e); } finally { // Release current connection to the connection pool once you are done deleteProject.releaseConnection(); } return result == HttpStatus.SC_OK; }
From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java
public void deleteProjectVersions(String projectId, String tenantDomain) throws AppFactoryException { String postUrl = issueTrackerUrl + "services/tenant/" + tenantDomain + "/project/" + projectId + "/version"; DeleteMethod deleteVersion = new DeleteMethod(postUrl); int result = -1; try {/*from w w w . j ava 2 s . c om*/ HttpClient httpclient = new HttpClient(); result = httpclient.executeMethod(deleteVersion); } catch (Exception e) { String msg = "Error while creating project in issue repository for " + projectId; log.error(msg, e); throw new AppFactoryException(msg, e); } finally { // Release current connection to the connection pool once you are done deleteVersion.releaseConnection(); } }
From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java
public boolean deleteProjectVersion(String projectId, String version, String tenantDomain) throws AppFactoryException { String postUrl = issueTrackerUrl + "services/tenant/" + tenantDomain + "/project/" + projectId + "/" + version;/*w w w . j av a 2s. com*/ DeleteMethod deleteVersion = new DeleteMethod(postUrl); int result = -1; try { HttpClient httpclient = new HttpClient(); result = httpclient.executeMethod(deleteVersion); } catch (Exception e) { String msg = "Error while creating project in issue repository for " + projectId; log.error(msg, e); throw new AppFactoryException(msg, e); } finally { // Release current connection to the connection pool once you are done deleteVersion.releaseConnection(); } return result == 200; }
From source file:org.wso2.carbon.esb.rest.test.api.ESBJAVA4852URITemplateWithCompleteURLTestCase.java
@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();//from ww w .ja v a 2 s.c o m 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"); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testCorrectlyCreateBucketOnPutThenRemoveAndCreateBucketAgain() throws Exception { // Do not change the bucket name: it is required to ensure operations will be executed on the expected node! String bucket = "bucket1"; ///* w w w . jav a 2 s . co m*/ TestValue value = new TestValue("value", 1); // This will be executed on node 1: PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection(); // This will be executed on node 2: DeleteMethod deleteBucket = makeDeleteMethod(NODE2_PORT, bucket); HTTP_CLIENT.executeMethod(deleteBucket); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); deleteBucket.releaseConnection(); // This will be executed on node 1: GetMethod getBuckets = makeGetMethod(NODE1_PORT, ""); HTTP_CLIENT.executeMethod(getBuckets); assertEquals(HttpStatus.SC_OK, getBuckets.getStatusCode()); assertTrue(getBuckets.getResponseBodyAsString().indexOf(bucket) == -1); getBuckets.releaseConnection(); // This will be executed on node 1: putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection(); // This will be executed on node 1: getBuckets = makeGetMethod(NODE1_PORT, ""); HTTP_CLIENT.executeMethod(getBuckets); assertEquals(HttpStatus.SC_OK, getBuckets.getStatusCode()); assertTrue(getBuckets.getResponseBodyAsString().indexOf(bucket) > -1); getBuckets.releaseConnection(); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testPutValueAndDeleteValueAndBucketOnOtherNode() throws Exception { String bucket = UUID.randomUUID().toString(); TestValue value = new TestValue("value", 1); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();/* w w w . ja va 2s .c o m*/ DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value"); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); DeleteMethod deleteBucket = makeDeleteMethod(NODE2_PORT, bucket); HTTP_CLIENT.executeMethod(deleteBucket); assertEquals(HttpStatus.SC_NO_CONTENT, deleteBucket.getStatusCode()); deleteBucket.releaseConnection(); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testDeleteValueIsIdempotent() throws Exception { String bucket = UUID.randomUUID().toString(); TestValue value = new TestValue("value", 1); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//w w w . j a va2 s. c om DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value"); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testRemoveBucket() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); updateService.removeBucket("bucket"); expectLastCall().once();/*from w w w . j a va 2 s . c o m*/ replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket"); client.executeMethod(method); assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }