List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getStatusCode
@Override public int getStatusCode()
From source file:org.apache.zeppelin.rest.AbstractTestRestApi.java
protected static DeleteMethod httpDelete(String path) throws IOException { LOG.info("Connecting to {}", url + path); HttpClient httpClient = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(url + path); deleteMethod.addRequestHeader("Origin", url); httpClient.executeMethod(deleteMethod); LOG.info("{} - {}", deleteMethod.getStatusCode(), deleteMethod.getStatusText()); return deleteMethod; }
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. ja va 2 s.co 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(); }
From source file:org.iavante.sling.s3backend.S3BackendTestIT.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 {/* www . j av a2s .co m*/ client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(204, post_delete.getStatusCode()); log.info("Borrado contenido: " + content); post_delete.releaseConnection(); }
From source file:org.roda.wui.filter.CasClient.java
/** * Logout from the CAS server./*from w w w . jav a2s . c o m*/ * * @param ticketGrantingTicket * the <strong>Ticket Granting Ticket</strong>. * @throws GenericException * if some error occurred. */ public void logout(final String ticketGrantingTicket) throws GenericException { final HttpClient client = new HttpClient(); final DeleteMethod method = new DeleteMethod( String.format("%s/v1/tickets/%s", casServerUrlPrefix, ticketGrantingTicket)); try { client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Logged out"); } else { LOGGER.warn(invalidResponseMessage(method)); throw new GenericException(invalidResponseMessage(method)); } } catch (final IOException e) { throw new GenericException(e.getMessage(), e); } finally { method.releaseConnection(); } }
From source file:org.sonatype.nexus.restlight.common.AbstractRESTLightClient.java
/** * <p>//from www. ja v a 2 s. com * Low-level DELETE implementation. * </p> * <p> * Submit a DELETE request to the URL given (absolute or relative-to-base-URL depends on urlIsAbsolute flag), and * parse the response as an XML {@link Document} (JDOM) instance <b>if</b> expectResponseBody == true. Use the given * requestParams map to inject into the HTTP DELETE method. * </p> */ protected Document doDelete(final String url, final Map<String, ? extends Object> requestParams, final boolean urlIsAbsolute, final boolean expectResponseBody) throws RESTLightClientException { DeleteMethod method = urlIsAbsolute ? new DeleteMethod(url) : new DeleteMethod(baseUrl + url); addRequestParams(method, requestParams); try { client.executeMethod(method); } catch (HttpException e) { throw new RESTLightClientException("DELETE request execution failed. Reason: " + e.getMessage(), e); } catch (IOException e) { throw new RESTLightClientException("DELETE request execution failed. Reason: " + e.getMessage(), e); } int status = method.getStatusCode(); String statusText = method.getStatusText(); if (status != 200) { throw new RESTLightClientException("DELETE request failed; HTTP status: " + status + ": " + statusText); } if (expectResponseBody) { try { return new SAXBuilder().build(method.getResponseBodyAsStream()); } catch (JDOMException e) { throw new RESTLightClientException("Failed to parse response body as XML for DELETE request.", e); } catch (IOException e) { throw new RESTLightClientException("Could not retrieve body as a String from DELETE request.", e); } finally { method.releaseConnection(); } } else { method.releaseConnection(); return null; } }
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 w w. j av a2 s.co 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.xwiki.test.rest.AttachmentsResourceTest.java
@Before public void setUp() throws Exception { super.setUp(); this.wikiName = getWiki(); this.spaces = Arrays.asList(getTestClassName()); this.pageName = getTestMethodName(); // Create a clean test page. DeleteMethod deleteMethod = executeDelete(buildURIForThisPage(PageResource.class), TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode()); createPage(this.spaces, this.pageName, ""); }
From source file:org.xwiki.test.rest.AttachmentsResourceTest.java
@Test public void testDELETEAttachment() throws Exception { String attachmentName = String.format("%d.txt", System.currentTimeMillis()); String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName); String content = "ATTACHMENT CONTENT"; PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode()); GetMethod getMethod = executeGet(attachmentURI); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); DeleteMethod deleteMethod = executeDelete(attachmentURI, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode()); getMethod = executeGet(attachmentURI); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.AttachmentsResourceTest.java
@Test public void testDELETEAttachmentNoRights() throws Exception { String attachmentName = String.format("%d.txt", System.currentTimeMillis()); String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName); String content = "ATTACHMENT CONTENT"; PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode()); DeleteMethod deleteMethod = executeDelete(attachmentURI); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode()); GetMethod getMethod = executeGet(attachmentURI); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.ObjectsResourceTest.java
@Test public void testDELETEObject() throws Exception { Object objectToBeDeleted = createObjectIfDoesNotExists("XWiki.TagClass", MAIN_SPACE, "WebHome"); DeleteMethod deleteMethod = executeDelete( buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString(), TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode()); GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode()); }