Search in sources :

Example 46 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project cxf by apache.

the class CrossOriginSimpleTest method testNonSimpleActualRequest.

@Test
public void testNonSimpleActualRequest() throws Exception {
    configureAllowOrigins(true, null);
    String r = configClient.replacePath("/setAllowCredentials/false").accept("text/plain").post(null, String.class);
    assertEquals("ok", r);
    HttpClient httpclient = HttpClientBuilder.create().build();
    HttpDelete httpdelete = new HttpDelete("http://localhost:" + PORT + "/untest/delete");
    httpdelete.addHeader("Origin", "http://localhost:" + PORT);
    HttpResponse response = httpclient.execute(httpdelete);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertAllowCredentials(response, false);
    assertOriginResponse(true, null, true, response);
    if (httpclient instanceof Closeable) {
        ((Closeable) httpclient).close();
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpClient(org.apache.http.client.HttpClient) Closeable(java.io.Closeable) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 47 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project cxf by apache.

the class Client method delete.

private static void delete(final String url, final CloseableHttpClient httpClient) throws IOException {
    System.out.println("Sent HTTP DELETE request to remove all books from catalog");
    final HttpDelete delete = new HttpDelete(url);
    try {
        CloseableHttpResponse response = httpClient.execute(delete);
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println(EntityUtils.toString(response.getEntity()));
        }
    } finally {
        delete.releaseConnection();
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 48 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project cas by apereo.

the class HttpUtils method execute.

/**
 * Execute http request and produce a response.
 *
 * @param url               the url
 * @param method            the method
 * @param basicAuthUsername the basic auth username
 * @param basicAuthPassword the basic auth password
 * @param parameters        the parameters
 * @param headers           the headers
 * @param entity            the entity
 * @return the http response
 */
public static HttpResponse execute(final String url, final String method, final String basicAuthUsername, final String basicAuthPassword, final Map<String, String> parameters, final Map<String, String> headers, final String entity) {
    try {
        final HttpClient client = buildHttpClient(basicAuthUsername, basicAuthPassword);
        final URI uri = buildHttpUri(url, parameters);
        final HttpUriRequest request;
        switch(method.toLowerCase()) {
            case "post":
                request = new HttpPost(uri);
                if (StringUtils.isNotBlank(entity)) {
                    final StringEntity stringEntity = new StringEntity(entity);
                    ((HttpPost) request).setEntity(stringEntity);
                }
                break;
            case "delete":
                request = new HttpDelete(uri);
                break;
            case "get":
            default:
                request = new HttpGet(uri);
                break;
        }
        headers.forEach(request::addHeader);
        return client.execute(request);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 49 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project janusgraph by JanusGraph.

the class ElasticSearchMultiTypeIndexTest method clear.

private void clear() throws Exception {
    try (final CloseableHttpClient httpClient = HttpClients.createDefault()) {
        final HttpHost host = new HttpHost(InetAddress.getByName(esr.getHostname()), ElasticsearchRunner.PORT);
        IOUtils.closeQuietly(httpClient.execute(host, new HttpDelete("janusgraph*")));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpHost(org.apache.http.HttpHost)

Example 50 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project camel by apache.

the class CxfRsConsumerSimpleBindingTest method testDeleteVipCustomer.

@Test
public void testDeleteVipCustomer() throws Exception {
    HttpDelete delete = new HttpDelete("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123");
    delete.addHeader("Accept", "text/xml");
    HttpResponse response = httpclient.execute(delete);
    assertEquals(200, response.getStatusLine().getStatusCode());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)108 HttpResponse (org.apache.http.HttpResponse)25 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)22 Test (org.junit.Test)21 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpPut (org.apache.http.client.methods.HttpPut)16 HttpPost (org.apache.http.client.methods.HttpPost)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)14 IOException (java.io.IOException)12 Deployment (org.activiti.engine.test.Deployment)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)9 URI (java.net.URI)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 URISyntaxException (java.net.URISyntaxException)6 Header (org.apache.http.Header)6 HttpEntity (org.apache.http.HttpEntity)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 User (org.activiti.engine.identity.User)5