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

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

Introduction

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

Prototype

String METHOD_NAME

To view the source code for org.apache.http.client.methods HttpDelete METHOD_NAME.

Click Source Link

Usage

From source file:org.fcrepo.camel.HttpMethodsTest.java

@Test
public void testMethods() {
    assertEquals(HttpMethods.DELETE.toString(), HttpDelete.METHOD_NAME);
    assertEquals(HttpMethods.GET.toString(), HttpGet.METHOD_NAME);
    assertEquals(HttpMethods.HEAD.toString(), HttpHead.METHOD_NAME);
    assertEquals(HttpMethods.OPTIONS.toString(), HttpOptions.METHOD_NAME);
    assertEquals(HttpMethods.PATCH.toString(), HttpPatch.METHOD_NAME);
    assertEquals(HttpMethods.POST.toString(), HttpPost.METHOD_NAME);
    assertEquals(HttpMethods.PUT.toString(), HttpPut.METHOD_NAME);
}

From source file:com.blacklocus.jres.request.search.JresDeleteByQuery.java

@Override
public String getHttpMethod() {
    return HttpDelete.METHOD_NAME;
}

From source file:io.wcm.caravan.io.http.impl.RequestUtil.java

/**
 * @param urlPrefix URL prefix//from  w w  w  . j a v  a  2 s . c  o  m
 * @param request Requset
 * @return HTTP client request object
 */
public static HttpUriRequest buildHttpRequest(String urlPrefix, Request request) {
    String url = urlPrefix + request.url();

    // http method
    HttpUriRequest httpRequest;
    String method = StringUtils.upperCase(request.method());
    switch (method) {
    case HttpGet.METHOD_NAME:
        httpRequest = new HttpGet(url);
        break;
    case HttpPost.METHOD_NAME:
        httpRequest = new HttpPost(url);
        break;
    case HttpPut.METHOD_NAME:
        httpRequest = new HttpPut(url);
        break;
    case HttpDelete.METHOD_NAME:
        httpRequest = new HttpDelete(url);
        break;
    default:
        throw new IllegalArgumentException("Unsupported HTTP method type: " + request.method());
    }

    // headers
    for (Entry<String, Collection<String>> entry : request.headers().entrySet()) {
        Streams.of(entry.getValue()).forEach(value -> httpRequest.addHeader(entry.getKey(), value));
    }

    // body
    if ((httpRequest instanceof HttpEntityEnclosingRequest) && request.body() != null) {
        HttpEntityEnclosingRequest entityHttpRequest = (HttpEntityEnclosingRequest) httpRequest;
        if (request.charset() != null) {
            entityHttpRequest.setEntity(
                    new StringEntity(new String(request.body(), request.charset()), request.charset()));
        } else {
            entityHttpRequest.setEntity(new ByteArrayEntity(request.body()));
        }
    }

    return httpRequest;
}

From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java

public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
        throws ProtocolException {
    URI uri = this.getLocationURI(request, response, context);
    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        return new HttpHead(uri);
    } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
        return this.copyEntity(new HttpPost(uri), request);
    } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
        return this.copyEntity(new HttpPut(uri), request);
    } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) {
        return new HttpDelete(uri);
    } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) {
        return new HttpTrace(uri);
    } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) {
        return new HttpOptions(uri);
    } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) {
        return this.copyEntity(new HttpPatch(uri), request);
    } else {/*  www .j ava2  s.c  o m*/
        return new HttpGet(uri);
    }
}

From source file:quarks.connectors.http.runtime.HttpRequester.java

@Override
public R apply(T t) {

    if (client == null)
        client = clientCreator.get();/*from   w  w  w.  j a v  a  2 s  .  c o  m*/

    String m = method.apply(t);
    String uri = url.apply(t);
    HttpUriRequest request;
    switch (m) {
    case HttpGet.METHOD_NAME:
        request = new HttpGet(uri);
        break;
    case HttpDelete.METHOD_NAME:
        request = new HttpDelete(uri);
        break;

    default:
        throw new IllegalArgumentException();
    }

    try {
        try (CloseableHttpResponse response = client.execute(request)) {
            return responseProcessor.apply(t, response);
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestClient.java

private static Request delete(final String indexName) {
    return new Request(HttpDelete.METHOD_NAME, "/" + indexName, Collections.emptyMap(), null);
}

From source file:org.camunda.connect.httpclient.HttpRequestTest.java

@Test
public void setHttpMethod() {
    HttpRequest request = connector.createRequest().get();
    assertThat(request.getMethod()).isEqualTo(HttpGet.METHOD_NAME);

    request = connector.createRequest().post();
    assertThat(request.getMethod()).isEqualTo(HttpPost.METHOD_NAME);

    request = connector.createRequest().put();
    assertThat(request.getMethod()).isEqualTo(HttpPut.METHOD_NAME);

    request = connector.createRequest().delete();
    assertThat(request.getMethod()).isEqualTo(HttpDelete.METHOD_NAME);

    request = connector.createRequest().patch();
    assertThat(request.getMethod()).isEqualTo(HttpPatch.METHOD_NAME);

    request = connector.createRequest().head();
    assertThat(request.getMethod()).isEqualTo(HttpHead.METHOD_NAME);

    request = connector.createRequest().options();
    assertThat(request.getMethod()).isEqualTo(HttpOptions.METHOD_NAME);

    request = connector.createRequest().trace();
    assertThat(request.getMethod()).isEqualTo(HttpTrace.METHOD_NAME);
}

From source file:org.elasticsearch.client.Request.java

static Request delete(DeleteRequest deleteRequest) {
    String endpoint = endpoint(deleteRequest.index(), deleteRequest.type(), deleteRequest.id());

    Params parameters = Params.builder();
    parameters.withRouting(deleteRequest.routing());
    parameters.withParent(deleteRequest.parent());
    parameters.withTimeout(deleteRequest.timeout());
    parameters.withVersion(deleteRequest.version());
    parameters.withVersionType(deleteRequest.versionType());
    parameters.withRefreshPolicy(deleteRequest.getRefreshPolicy());
    parameters.withWaitForActiveShards(deleteRequest.waitForActiveShards());

    return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
}

From source file:org.apache.edgent.connectors.http.runtime.HttpRequester.java

@Override
public R apply(T t) {

    if (client == null)
        client = clientCreator.get();// w  w w  .ja  v  a  2  s  .c o m

    String m = method.apply(t);
    String uri = url.apply(t);
    HttpUriRequest request;

    switch (m) {

    case HttpGet.METHOD_NAME:
        request = new HttpGet(uri);
        break;
    case HttpDelete.METHOD_NAME:
        request = new HttpDelete(uri);
        break;
    case HttpPost.METHOD_NAME:
        request = new HttpPost(uri);
        break;
    case HttpPut.METHOD_NAME:
        request = new HttpPut(uri);
        break;

    default:
        throw new IllegalArgumentException();
    }

    // If entity is not null means http request should have a body
    if (entity != null) {

        HttpEntity body = entity.apply(t);

        if (request instanceof HttpEntityEnclosingRequest == false) {
            throw new IllegalArgumentException("Http request does not support body");
        }

        ((HttpEntityEnclosingRequest) request).setEntity(body);
    }

    try {
        try (CloseableHttpResponse response = client.execute(request)) {
            return responseProcessor.apply(t, response);
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}