Java Code Examples for org.apache.http.client.methods.HttpDelete#releaseConnection()

The following examples show how to use org.apache.http.client.methods.HttpDelete#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: RtNetwork.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void remove() throws IOException, UnexpectedResponseException {
    final UncheckedUriBuilder uri = new UncheckedUriBuilder(
        this.baseUri.toString()
    );
    final HttpDelete delete = new HttpDelete(
        uri.build()
    );
    try {
        this.client.execute(
            delete,
            new MatchStatus(delete.getURI(), HttpStatus.SC_NO_CONTENT)
        );
    } finally {
        delete.releaseConnection();
    }
}
 
Example 2
Source File: RtVolume.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void remove(final boolean force)
    throws IOException, UnexpectedResponseException {
    final UncheckedUriBuilder uri = new UncheckedUriBuilder(
        this.baseUri.toString()
    );
    uri.addParameter("force", String.valueOf(force));
    final HttpDelete delete = new HttpDelete(
        uri.build()
    );
    try {
        this.client.execute(
            delete,
            new MatchStatus(delete.getURI(), HttpStatus.SC_OK)
        );
    } finally {
        delete.releaseConnection();
    }
}
 
Example 3
Source File: DefaultRestClient.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public HttpResponse doDelete(String resourcePath) throws RestClientException {

        HttpDelete delete = new HttpDelete(resourcePath);
        setAuthHeader(delete);

        try {
            return httpClient.execute(delete);

        } catch (IOException e) {
            String errorMsg = "Error while executing DELETE statement";
            log.error(errorMsg, e);
            throw new RestClientException(errorMsg, e);
        } finally {
            delete.releaseConnection();
        }
    }
 
Example 4
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteBook() throws Exception {
    String endpointAddress =
        "http://localhost:" + PORT + "/bookstore/books/123";

    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpDelete delete = new HttpDelete(endpointAddress);

    try {
        CloseableHttpResponse response = client.execute(delete);
        assertEquals(200, response.getStatusLine().getStatusCode());
    } finally {
        // Release current connection to the connection pool once you are done
        delete.releaseConnection();
    }
}
 
Example 5
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteBookByQuery() throws Exception {
    String endpointAddress =
        "http://localhost:" + PORT + "/bookstore/books/id?value=123";

    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpDelete delete = new HttpDelete(endpointAddress);

    try {
        CloseableHttpResponse response = client.execute(delete);
        assertEquals(200, response.getStatusLine().getStatusCode());
    } finally {
        // Release current connection to the connection pool once you are done
        delete.releaseConnection();
    }
}
 
Example 6
Source File: BrocadeVcsApi.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
protected void executeDeleteObject(String uri) throws BrocadeVcsApiException {
    if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {
        throw new BrocadeVcsApiException("Hostname/credentials are null or empty");
    }

    final HttpDelete dm = (HttpDelete)createMethod("delete", uri);
    dm.setHeader("Accept", "application/vnd.configuration.resource+xml");

    final HttpResponse response = executeMethod(dm);

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {

        String errorMessage;
        try {
            errorMessage = responseToErrorMessage(response);
        } catch (final IOException e) {
            s_logger.error("Failed to delete object : " + e.getMessage());
            throw new BrocadeVcsApiException("Failed to delete object : " + e.getMessage());
        }

        dm.releaseConnection();
        s_logger.error("Failed to delete object : " + errorMessage);
        throw new BrocadeVcsApiException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
}
 
Example 7
Source File: HttpClientUtil.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
public static String delete(String url) throws IOException {
    HttpDelete httpDelete = deleteForm(url);
    HttpResponse response;
    String result = null;
    try {
        response = httpclient.execute(httpDelete);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            result = EntityUtils.toString(entity);
        }
    } finally {
        httpDelete.releaseConnection();
    }
    return result;
}
 
Example 8
Source File: Client.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Send a DELETE request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @return a Response object with response detail
 * @throws IOException for error
 */
public Response delete(Cluster cluster, String path) throws IOException {
  HttpDelete method = new HttpDelete(path);
  try {
    HttpResponse resp = execute(cluster, method, null, path);
    Header[] headers = resp.getAllHeaders();
    byte[] content = getResponseBody(resp);
    return new Response(resp.getStatusLine().getStatusCode(), headers, content);
  } finally {
    method.releaseConnection();
  }
}
 
Example 9
Source File: Client.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Send a DELETE request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @return a Response object with response detail
 * @throws IOException for error
 */
public Response delete(Cluster cluster, String path, Header extraHdr) throws IOException {
  HttpDelete method = new HttpDelete(path);
  try {
    Header[] headers = { extraHdr };
    HttpResponse resp = execute(cluster, method, headers, path);
    headers = resp.getAllHeaders();
    byte[] content = getResponseBody(resp);
    return new Response(resp.getStatusLine().getStatusCode(), headers, content);
  } finally {
    method.releaseConnection();
  }
}