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:quarks.connectors.http.runtime.HttpRequester.java

@Override
public R apply(T t) {

    if (client == null)
        client = clientCreator.get();//www.j av a  2  s . c om

    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.hawq.ranger.integration.service.tests.common.RESTClient.java

public String executeRequest(Method method, String url, String payload) throws IOException {
    HttpUriRequest request = null;//from w  w w  . j a  v  a  2s  . c  om
    switch (method) {
    case GET:
        request = new HttpGet(url);
        break;
    case POST:
        request = new HttpPost(url);
        ((HttpPost) request).setEntity(new StringEntity(payload));
        break;
    case DELETE:
        request = new HttpDelete(url);
        break;
    default:
        throw new IllegalArgumentException("Method " + method + " is not supported");
    }
    return executeRequest(request);
}

From source file:com.urbancode.ud.client.AgentClient.java

public void deleteAgent(String name) throws IOException {
    String uri = url + "/cli/agentCLI";
    uri = uri + "?agent=" + encodePath(name);

    HttpDelete method = new HttpDelete(uri);
    invokeMethod(method);/*from w w  w  . j a va  2 s  .  c  o m*/
}

From source file:hmock.BasicHMockTest.java

@Test
public void testParamDeleteRequest() throws Exception {

    HMock.respond().body("A,B,C").when().delete("/employees").param("name", equalTo("John"));

    HttpDelete delete = new HttpDelete("http://localhost:7357/employees?name=John");

    HttpResponse response = _httpclient.execute(delete);

    String responsebody = IOUtils.toString(response.getEntity().getContent());
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals("A,B,C", responsebody);

    delete = new HttpDelete("http://localhost:7357/employees?name=John2");
    response = _httpclient.execute(delete);

    assertEquals(404, response.getStatusLine().getStatusCode());
}

From source file:org.flowable.rest.service.api.history.HistoricProcessInstanceResourceTest.java

/**
 * Test retrieval of historic process instance. GET history/historic-process-instances/{processInstanceId}
 *///  ww  w. ja va2s.com
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())),
            HttpStatus.SC_OK);

    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());

    response = executeRequest(
            new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
                    RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())),
            HttpStatus.SC_NO_CONTENT);
    assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
    closeResponse(response);
}

From source file:com.marklogic.client.test.util.TestServerBootstrapper.java

private void deleteRestServer() throws ClientProtocolException, IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials(username, password));

    HttpDelete delete = new HttpDelete(
            "http://" + host + ":8002/v1/rest-apis/java-unittest?include=modules&include=content");

    client.execute(delete);/*w  w  w . j av  a  2  s . co m*/
}

From source file:tv.arte.resteventapi.core.clients.RestEventApiRestClient.java

/**
 * Executes the REST request described by the {@link RestEvent}
 * /*  w  w  w. j a  v a2  s  .c  om*/
 * @param restEvent The {@link RestEvent} to process
 * @return A result of the execution
 * @throws RestEventApiRuntimeException In case of non managed errors
 */
public static RestClientExecutionResult execute(final RestEvent restEvent) throws RestEventApiRuntimeException {
    RestClientExecutionResult result = new RestClientExecutionResult();
    String url = restEvent.getUrl();
    CloseableHttpClient client = null;
    HttpUriRequest request = null;
    Integer responseCode = null;

    try {
        //Request custom configs
        RequestConfig.Builder requestBuilder = RequestConfig.custom();
        requestBuilder = requestBuilder.setConnectTimeout(restEvent.getTimeout());
        requestBuilder = requestBuilder.setConnectionRequestTimeout(restEvent.getTimeout());

        client = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()).build();

        //Determine the method to execute
        switch (restEvent.getMethod()) {
        case GET:
            request = new HttpGet(url);
            break;
        case POST:
            request = new HttpPost(url);
            break;
        case PUT:
            request = new HttpPut(url);
            break;
        case DELETE:
            request = new HttpDelete(url);
            break;
        case PATCH:
            request = new HttpPatch(url);
            break;
        case HEAD:
            request = new HttpHead(url);
            break;
        default:
            throw new RestEventApiRuntimeException("RestEventAPI unsupported HTTP method");
        }

        //Set the body for eligible methods
        if (restEvent.getBody() != null && request instanceof HttpEntityEnclosingRequestBase) {
            ((HttpEntityEnclosingRequestBase) request).setEntity(new StringEntity(restEvent.getBody()));
        }

        //Set headers
        if (CollectionUtils.isNotEmpty(restEvent.getHeaders())) {
            for (String strHeader : restEvent.getHeaders()) {
                CharArrayBuffer headerBuffer = new CharArrayBuffer(strHeader.length() + 1);
                headerBuffer.append(strHeader);
                request.addHeader(new BufferedHeader(headerBuffer));
            }
        }

        HttpResponse response = client.execute(request);
        responseCode = response.getStatusLine().getStatusCode();

        result.setState(RestClientCallState.OK);
    } catch (ConnectTimeoutException e) {
        result.setState(RestClientCallState.TIMEOUT);
    } catch (Exception e) {
        throw new RestEventApiRuntimeException("Un error occured while processing rest event", e);
    } finally {
        result.setResponseCode(responseCode);

        try {
            client.close();
        } catch (Exception e2) {
            logger.warn("Unable to close HTTP client", e2);
        }
    }

    return result;
}

From source file:com.linecorp.armeria.server.thrift.ThriftOverHttp1Test.java

@Test
public void testNonPostRequest() throws Exception {
    final HttpUriRequest[] reqs = { new HttpGet(newUri("http", "/hello")),
            new HttpDelete(newUri("http", "/hello")) };

    try (CloseableHttpClient hc = HttpClients.createMinimal()) {
        for (HttpUriRequest r : reqs) {
            try (CloseableHttpResponse res = hc.execute(r)) {
                assertThat(res.getStatusLine().toString(), is("HTTP/1.1 405 Method Not Allowed"));
                assertThat(EntityUtils.toString(res.getEntity()), is(not("Hello, world!")));
            }/* w w w  .j a  va 2 s .com*/
        }
    }
}

From source file:com.meltmedia.cadmium.cli.ApiCommand.java

/**
 * Sends acl request to cadmium./*from   w  ww  . j av a2s  .c o m*/
 * 
 * @param site
 * @param op
 * @param path
 * @return
 * @throws Exception
 */
public static String[] sendRequest(String token, String site, OPERATION op, String path) throws Exception {
    HttpClient client = httpClient();
    HttpUriRequest message = null;
    if (op == OPERATION.DISABLE) {
        message = new HttpPut(site + ENDPOINT + path);
    } else if (op == OPERATION.ENABLE) {
        message = new HttpDelete(site + ENDPOINT + path);
    } else {
        message = new HttpGet(site + ENDPOINT);
    }
    addAuthHeader(token, message);

    HttpResponse resp = client.execute(message);
    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String results = EntityUtils.toString(resp.getEntity());
        return new Gson().fromJson(results, String[].class);
    }
    return null;
}

From source file:com.scut.easyfe.network.kjFrame.http.HttpClientStack.java

static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) {
    switch (request.getMethod()) {
    case Request.HttpMethod.GET:
        return new HttpGet(request.getUrl());
    case Request.HttpMethod.DELETE:
        return new HttpDelete(request.getUrl());
    case Request.HttpMethod.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }//w  w w.  ja va 2s  . co  m
    case Request.HttpMethod.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    case Request.HttpMethod.HEAD:
        return new HttpHead(request.getUrl());
    case Request.HttpMethod.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Request.HttpMethod.TRACE:
        return new HttpTrace(request.getUrl());
    case Request.HttpMethod.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.");
    }
}