Search in sources :

Example 56 with HttpDelete

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

the class Client method delete.

/**
   * Send a DELETE request
   * @param cluster the cluster definition
   * @param path the path or URI
   * @return a Response object with response detail
   * @throws IOException for error
   */
public Response delete(Cluster cluster, String path) throws IOException {
    HttpDelete method = new HttpDelete(path);
    try {
        HttpResponse resp = execute(cluster, method, null, path);
        Header[] headers = resp.getAllHeaders();
        byte[] content = getResponseBody(resp);
        return new Response(resp.getStatusLine().getStatusCode(), headers, content);
    } finally {
        method.releaseConnection();
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpDelete(org.apache.http.client.methods.HttpDelete) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HttpResponse(org.apache.http.HttpResponse)

Example 57 with HttpDelete

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

the class HttpClientStackTest method testCreateDeleteRequest.

public void testCreateDeleteRequest() throws Exception {
    TestRequest.Delete request = new TestRequest.Delete();
    assertEquals(request.getMethod(), Method.DELETE);
    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpDelete);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpDelete(org.apache.http.client.methods.HttpDelete) TestRequest(com.android.volley.mock.TestRequest)

Example 58 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project mobile-android by photo.

the class ApiBase method createHttpRequest.

/**
     * Create a HttpUriRequest out of a ApiRequest object.
     * 
     * @param request the ApiRequest for which a HttpUriRequest should be
     *            created
     * @param baseUrl the base server url
     * @param listener Progress Listener with callback on progress
     * @return HttpUriRequest object which will do the request as described in
     *         ApiRequest
     * @throws UnsupportedEncodingException
     */
private HttpUriRequest createHttpRequest(ApiRequest request, String baseUrl, ProgressListener listener) throws UnsupportedEncodingException {
    HttpUriRequest httpRequest = null;
    switch(request.getMethod()) {
        case ApiRequest.GET:
            httpRequest = new HttpGet(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
            break;
        case ApiRequest.POST:
            httpRequest = new HttpPost(baseUrl + request.getPath());
            HttpPost httpPost = ((HttpPost) httpRequest);
            if (request.isMime()) {
                // TODO use the multipart when possible (currently server
                // handles it wrong)
                // HttpEntity entity = createMultipartEntity(request);
                // TODO remove this when doing correct multipart
                httpRequest = new HttpPost(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
                httpPost = ((HttpPost) httpRequest);
                HttpEntity entity = createFileOnlyMultipartEntity(request);
                if (listener != null) {
                    httpPost.setEntity(new HttpEntityWithProgress(entity, listener, httpPost));
                } else {
                    httpPost.setEntity(entity);
                }
            } else {
                httpPost.setEntity(new UrlEncodedFormEntity(request.getParameters(), HTTP.UTF_8));
            }
            break;
        case ApiRequest.PUT:
            httpRequest = new HttpPut(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
            break;
        case ApiRequest.DELETE:
            httpRequest = new HttpDelete(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
            break;
    }
    for (NameValuePair pair : request.getHeaders()) {
        request.addHeader(pair.getName(), pair.getValue());
    }
    return httpRequest;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPost(org.apache.http.client.methods.HttpPost) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HttpPut(org.apache.http.client.methods.HttpPut)

Example 59 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project undertow by undertow-io.

the class RoutingHandlerTestCase method testRoutingTemplateHandler.

@Test
public void testRoutingTemplateHandler() throws IOException {
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/foo");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("foo", HttpClientUtils.readResponse(result));
        HttpDelete delete = new HttpDelete(DefaultServer.getDefaultServerURL() + "/foo");
        result = client.execute(delete);
        Assert.assertEquals(StatusCodes.METHOD_NOT_ALLOWED, result.getStatusLine().getStatusCode());
        Assert.assertEquals("", HttpClientUtils.readResponse(result));
        HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/foo");
        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("posted foo", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/foo");
        get.addHeader("SomeHeader", "value");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("foo", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/foo");
        get.addHeader("SomeHeader", "special");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("special foo", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/foo/a");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("foo-path[a]", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/baz");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("baz", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/baz/a");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("baz-path[a]", HttpClientUtils.readResponse(result));
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/bar");
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("GET bar", HttpClientUtils.readResponse(result));
        post = new HttpPost(DefaultServer.getDefaultServerURL() + "/bar");
        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("POST bar", HttpClientUtils.readResponse(result));
        HttpPut put = new HttpPut(DefaultServer.getDefaultServerURL() + "/bar");
        result = client.execute(put);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("PUT bar", HttpClientUtils.readResponse(result));
        delete = new HttpDelete(DefaultServer.getDefaultServerURL() + "/bar");
        result = client.execute(delete);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("DELETE bar", HttpClientUtils.readResponse(result));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 60 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project openkit-android by OpenKit.

the class AsyncHttpClient method delete.

/**
     * Perform a HTTP DELETE request.
     * @param context the Android Context which initiated the request.
     * @param url the URL to send the request to.
     * @param headers set one-time headers for this request
     * @param responseHandler the response handler instance that should handle the response.
     */
public void delete(Context context, String url, Header[] headers, AsyncHttpResponseHandler responseHandler) {
    final HttpDelete delete = new HttpDelete(url);
    if (headers != null)
        delete.setHeaders(headers);
    sendRequest(httpClient, httpContext, delete, null, responseHandler, context);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete)

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