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();
}
}
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);
}
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;
}
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();
}
}
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);
}
Aggregations