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.oplay.nohelper.volley.toolbox.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 */// w  ww. j a  v  a2  s .  c o  m
@SuppressWarnings("deprecation")
public static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    switch (request.getMethod()) {
    case Method.DEPRECATED_GET_OR_POST: {
        // This is the deprecated way that needs to be handled for backwards compatibility.
        // If the request's post body is null, then the assumption is that the request is
        // GET.  Otherwise, it is assumed that the request is a POST.
        byte[] postBody = request.getPostBody();
        if (postBody != null) {
            HttpPost postRequest = new HttpPost(request.getUrl());
            postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType());
            HttpEntity entity;
            entity = new ByteArrayEntity(postBody);
            postRequest.setEntity(entity);
            return postRequest;
        } else {
            return new HttpGet(request.getUrl());
        }
    }
    case Method.GET:
        return new HttpGet(request.getUrl());
    case Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    case Method.HEAD:
        return new HttpHead(request.getUrl());
    case Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Method.PATCH: {
        HttpPatch patchRequest = new HttpPatch(request.getUrl());
        patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:org.neo4j.ogm.session.transaction.TransactionManager.java

public void rollback(Transaction tx) {
    String url = tx.url();/*w  ww. j  a  v  a  2s.  c o m*/
    logger.debug("DELETE {}", url);
    HttpDelete request = new HttpDelete(url);
    executeRequest(request);
}

From source file:de.adesso.referencer.search.helper.ElasticConfig.java

public static String sendHttpRequest(String url, String requestBody, String requestType) throws IOException {
    String result = null;//from  w  w  w .  ja  v a 2s.c o m
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse httpResponse;
    try {
        switch (requestType) {
        case "Get":
            httpResponse = httpclient.execute(new HttpGet(url));
            break;
        case "Post":
            HttpPost httppost = new HttpPost(url);
            if (requestBody != null)
                httppost.setEntity(new StringEntity(requestBody, DEFAULT_CHARSET));
            httpResponse = httpclient.execute(httppost);
            break;
        case "Put":
            HttpPut httpPut = new HttpPut(url);
            httpPut.addHeader("Content-Type", "application/json");
            httpPut.addHeader("Accept", "application/json");
            if (requestBody != null)
                httpPut.setEntity(new StringEntity(requestBody, DEFAULT_CHARSET));
            httpResponse = httpclient.execute(httpPut);
            break;
        case "Delete":
            httpResponse = httpclient.execute(new HttpDelete(url));
            break;
        default:
            httpResponse = httpclient.execute(new HttpGet(url));
            break;
        }
        try {
            HttpEntity entity1 = httpResponse.getEntity();
            if (entity1 != null) {
                long len = entity1.getContentLength();
                if (len != -1 && len < MAX_CONTENT_LENGTH) {
                    result = EntityUtils.toString(entity1, DEFAULT_CHARSET);
                } else {
                    System.out.println("Error!!!! entity length=" + len);
                }
            }
            EntityUtils.consume(entity1);
        } finally {
            httpResponse.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        httpclient.close();
    }
    return result;
}

From source file:org.ocpsoft.redoculous.tests.WebTest.java

/**
 * Request a resource from the deployed test-application. The context path will be automatically prepended to the
 * given path.//from   w w  w  .  j a  v  a2  s. c om
 * <p>
 * E.g: A path of '/example' will be sent as '/rewrite-test/example'
 * 
 * @throws Exception
 */
public HttpAction<HttpDelete> delete(HttpClient client, String path, Header... headers) throws Exception {
    HttpDelete request = new HttpDelete(getBaseURL() + getContextPath() + path);
    if (headers != null && headers.length > 0) {
        request.setHeaders(headers);
    }
    HttpContext context = new BasicHttpContext();
    HttpResponse response = client.execute(request, context);

    return new HttpAction<HttpDelete>(client, context, request, response, getBaseURL(), getContextPath());
}

From source file:com.activiti.service.activiti.JobService.java

public void deleteJob(ServerConfig serverConfig, String jobId) {
    HttpDelete post = new HttpDelete(clientUtil.getServerUrl(serverConfig, "management/jobs/" + jobId));
    clientUtil.executeRequestNoResponseBody(post, serverConfig, HttpStatus.SC_NO_CONTENT);
}

From source file:net.wedjaa.elasticparser.tester.ESSearchTester.java

private static void populateTest() {
    // Get the bulk index as a stream
    InputStream bulkStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("bulk-insert.json");
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();

    HttpResponse response;//from w  ww . ja  v  a 2 s . com
    // Drop the index if it's there
    HttpDelete httpdelete = new HttpDelete("http://localhost:9500/unit");
    try {
        response = httpclient.execute(httpdelete);
        System.out.println("Index Deleted: " + response);
        httpclient.close();
    } catch (ClientProtocolException protoException) {
        System.err.println("Protocol Error while deleting index: " + protoException);
    } catch (IOException ioException) {
        System.err.println("IO Error while deleting index: " + ioException);
    }

    HttpPost httppost = new HttpPost("http://localhost:9500/_bulk");

    InputStreamEntity isEntity = new InputStreamEntity(bulkStream);
    httppost.setEntity(isEntity);

    try {
        httpclient = HttpClientBuilder.create().build();
        response = httpclient.execute(httppost);
        System.out.println(response.getStatusLine());
        httpclient.close();
    } catch (ClientProtocolException protoException) {
        System.err.println("Protocol Error while bulk indexing: " + protoException);
    } catch (IOException ioException) {
        System.err.println("IO Error while bulk indexing: " + ioException);
    }
    System.out.println("Waiting for index to settle down...");
    while (countIndexed() < 50) {
        System.out.println("...");
    }
    System.out.println("...done!");
}

From source file:org.opencastproject.remotetest.server.SeriesFeedTest.java

@Test
public void testEmptySeriesFeed() throws Exception {
    // Add a series
    HttpPost postSeries = new HttpPost(BASE_URL + "/series/");
    List<NameValuePair> seriesParams = new ArrayList<NameValuePair>();
    seriesParams.add(new BasicNameValuePair("series", getSampleSeries()));
    //seriesParams.add(new BasicNameValuePair("acl", getSampleAcl()));
    postSeries.setEntity(new UrlEncodedFormEntity(seriesParams, "UTF-8"));
    HttpResponse response = client.execute(postSeries);
    response.getEntity().consumeContent();
    Assert.assertEquals(201, response.getStatusLine().getStatusCode());

    HttpGet get = new HttpGet(BASE_URL + "/feeds/rss/2.0/series/10.245/5819");
    response = client.execute(get);//from  w  w  w  .  j  a  va2  s .com
    HttpEntity entity = response.getEntity();
    String feed = EntityUtils.toString(entity);
    // Though empty should generate a valid feed for a valid series
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());

    // Remove series
    HttpDelete del = new HttpDelete(BASE_URL + "/series/10.245/5819");
    response = client.execute(del);
    response.getEntity().consumeContent();
}

From source file:io.djigger.monitoring.java.instrumentation.subscription.HttpClientTracerTest.java

private CloseableHttpResponse callDelete() throws Exception {
    CloseableHttpClient client = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    try {/*  www.  j  a v a 2s .  co m*/
        HttpDelete del = new HttpDelete("http://localhost:12298");
        response = client.execute(del);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return response;
}

From source file:org.wuspba.ctams.ui.server.ServerUtils.java

public static String delete(URI uri) throws IOException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpDelete httpDelete = new HttpDelete(uri);

    String ret;//from  w ww.  j a v  a2 s.co  m

    try (CloseableHttpResponse response = httpclient.execute(httpDelete)) {
        HttpEntity responseEntity = response.getEntity();

        ret = convertEntity(responseEntity);

        EntityUtils.consume(responseEntity);
    }

    return ret;
}

From source file:org.dthume.spring.http.client.httpcomponents.HttpComponentsClientHttpRequest.java

private HttpUriRequest createRequest() {
    final URI requestUri = getURI();
    final HttpMethod requestMethod = getMethod();

    switch (requestMethod) {
    case DELETE://from w  ww  . j a v  a2s . co m
        return new HttpDelete(requestUri);
    case GET:
        return new HttpGet(requestUri);
    case HEAD:
        return new HttpHead(requestUri);
    case PUT:
        return new HttpPut(requestUri);
    case POST:
        return new HttpPost(requestUri);
    case OPTIONS:
        return new HttpOptions(requestUri);
    default:
        final String msg = "Unknown Http Method: " + requestMethod;
        throw new IllegalArgumentException(msg);
    }
}