Example usage for org.apache.http.client.methods HttpDelete HttpDelete

List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpDelete HttpDelete.

Prototype

public HttpDelete(final String uri) 

Source Link

Usage

From source file:com.releasequeue.server.ReleaseQueueServer.java

private void deleteRequest(URL url) throws IOException {
    HttpDelete request = new HttpDelete(url.toString());
    setAuthHeader(request);// w  ww  .j a v a2 s .  co m

    CloseableHttpClient httpClient = HttpClients.createDefault();

    try {
        HttpResponse response = httpClient.execute(request);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode >= 400) {
            throw new HttpException(statusLine.getReasonPhrase());
        }
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:com.ccreanga.bitbucket.rest.client.http.BitBucketHttpExecutor.java

private HttpRequestBase createRequest(HttpRequest httpRequest) {
    URI fullUri = URI.create(baseUrl + "/" + httpRequest.getUrl()).normalize();
    String payload;/*w w w  .java  2s .c  o m*/
    switch (httpRequest.getMethod()) {
    case GET:
        return new HttpGet(fullUri);
    case POST:
        HttpPost request = new HttpPost(fullUri);
        payload = httpRequest.getPayload();
        if (payload != null) {
            request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
        }
        return request;
    case DELETE:
        return new HttpDelete(fullUri);

    default:
        throw new UnsupportedOperationException(
                String.format("http method %s is not supported", httpRequest.getMethod()));
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalDeviceOrientationProfileTestCase.java

/**
 * ondeviceorientation???.//ww  w .j  av a 2s. co  m
 * <pre>
 * ?HTTP
 * Method: DELETE
 * Path: /deviceorientation/ondeviceorientation?deviceId=xxxx&sessionKey=xxxx
 * </pre>
 * <pre>
 * ??
 * result?0???????
 * </pre>
 */
public void testDeleteOnDeviceOrientation() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + DeviceOrientationProfileConstants.PROFILE_NAME);
    builder.append("/" + DeviceOrientationProfileConstants.ATTRIBUTE_ON_DEVICE_ORIENTATION);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpUriRequest request = new HttpDelete(builder.toString());
        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        assertResultOK(root);
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.apache.solr.client.solrj.impl.SolrClientCloudManager.java

@Override
public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String> headers, String payload,
        int timeout, boolean followRedirects) throws IOException {
    HttpClient client = solrClient.getHttpClient();
    final HttpRequestBase req;
    HttpEntity entity = null;//from  www. j  a va  2  s. c  o m
    if (payload != null) {
        entity = new StringEntity(payload, "UTF-8");
    }
    switch (method) {
    case GET:
        req = new HttpGet(url);
        break;
    case POST:
        req = new HttpPost(url);
        if (entity != null) {
            ((HttpPost) req).setEntity(entity);
        }
        break;
    case PUT:
        req = new HttpPut(url);
        if (entity != null) {
            ((HttpPut) req).setEntity(entity);
        }
        break;
    case DELETE:
        req = new HttpDelete(url);
        break;
    default:
        throw new IOException("Unsupported method " + method);
    }
    if (headers != null) {
        headers.forEach((k, v) -> req.addHeader(k, v));
    }
    RequestConfig.Builder requestConfigBuilder = HttpClientUtil.createDefaultRequestConfigBuilder();
    if (timeout > 0) {
        requestConfigBuilder.setSocketTimeout(timeout);
        requestConfigBuilder.setConnectTimeout(timeout);
    }
    requestConfigBuilder.setRedirectsEnabled(followRedirects);
    req.setConfig(requestConfigBuilder.build());
    HttpClientContext httpClientRequestContext = HttpClientUtil.createNewHttpClientRequestContext();
    HttpResponse rsp = client.execute(req, httpClientRequestContext);
    int statusCode = rsp.getStatusLine().getStatusCode();
    if (statusCode != 200) {
        throw new IOException("Error sending request to " + url + ", HTTP response: " + rsp.toString());
    }
    HttpEntity responseEntity = rsp.getEntity();
    if (responseEntity != null && responseEntity.getContent() != null) {
        return EntityUtils.toByteArray(responseEntity);
    } else {
        return EMPTY;
    }
}

From source file:com.omertron.slackbot.utils.HttpTools.java

/**
 * Execute a DELETE on the URL//ww w.j  a va2  s  .co m
 *
 * @param url URL to use in the request
 * @return String content
 * @throws ApiException
 */
public String deleteRequest(final URL url) throws ApiException {
    try {
        HttpDelete httpDel = new HttpDelete(url.toURI());
        return validateResponse(DigestedResponseReader.deleteContent(httpClient, httpDel, CHARSET), url);
    } catch (URISyntaxException | IOException ex) {
        throw new ApiException(ApiExceptionType.CONNECTION_ERROR, null, url, ex);
    }
}

From source file:org.apache.sling.hapi.client.impl.AbstractHtmlClientImpl.java

@Override
public <T extends Document> T delete(String url) throws ClientException {
    try {//from   w ww  . j a v a  2  s  .c om
        URI absoluteUri = absoluteUri(url);
        LOG.info("DELETE " + absoluteUri);
        HttpResponse response = this.execute(new HttpDelete(absoluteUri));
        return newDocument(response.getEntity().toString());
    } catch (URISyntaxException e) {
        throw new ClientException("Invalid post url " + url, e);
    } catch (Exception e) {
        throw new ClientException("Could not execute DELETE request", e);
    }
}

From source file:com.impetus.client.couchdb.utils.CouchDBTestUtils.java

/**
 * Drop database.//from  w  w w  .  java  2 s .co m
 * 
 * @param databaseName
 *            the database name
 * @param client
 *            the client
 * @param httpHost
 *            the http host
 */
public static void dropDatabase(String databaseName, HttpClient client, HttpHost httpHost) {
    HttpResponse response = null;
    try {
        URI uri = new URI(CouchDBConstants.PROTOCOL, null, httpHost.getHostName(), httpHost.getPort(),
                CouchDBConstants.URL_SEPARATOR + databaseName, null, null);
        HttpDelete delete = new HttpDelete(uri);

        response = client.execute(httpHost, delete, CouchDBUtils.getContext(httpHost));
    } catch (URISyntaxException e) {

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    } finally {
        CouchDBUtils.closeContent(response);
    }
}

From source file:com.arcbees.vcs.bitbucket.BitbucketApi.java

@Override
public void deletePullRequestApproval(Integer pullRequestId) throws IOException, UnsupportedOperationException {
    String requestUrl = apiPaths.approvePullRequest(repositoryOwner, repositoryName, pullRequestId);

    HttpDelete request = new HttpDelete(requestUrl);

    executeRequest(httpClient, request, credentials);
}

From source file:org.apache.geode.rest.internal.web.GeodeRestClient.java

public HttpResponse doDelete(String uri, String username, String password) throws Exception {
    HttpDelete httpDelete = new HttpDelete(CONTEXT + uri);
    return doRequest(httpDelete, username, password);
}