List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:org.dasein.cloud.opsource.OpSourceMethod.java
protected AbstractHttpMessage getMethod(String httpMethod, String urlStr) { AbstractHttpMessage method = null;/*w w w . j av a2 s. c o m*/ if (httpMethod.equals("GET")) { method = new HttpGet(urlStr); } else if (httpMethod.equals("POST")) { method = new HttpPost(urlStr); } else if (httpMethod.equals("PUT")) { method = new HttpPut(urlStr); } else if (httpMethod.equals("DELETE")) { method = new HttpDelete(urlStr); } else if (httpMethod.equals("HEAD")) { method = new HttpHead(urlStr); } else if (httpMethod.equals("OPTIONS")) { method = new HttpOptions(urlStr); } else if (httpMethod.equals("HEAD")) { method = new HttpTrace(urlStr); } else { return null; } return method; }
From source file:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java
@Override public void delete(String path, String username) { Pair[] params = { Pair.of("recursive", "true") }; HttpDelete removeFileOrDirectoryRequest = new HttpDelete(buildUri(path, username, "DELETE", params)); try (CloseableHttpResponse response = httpClient.execute(removeFileOrDirectoryRequest)) { if (response.getStatusLine().getStatusCode() != SC_OK) { throw invalidStatusException("DELETE", path, username, removeFileOrDirectoryRequest, response); }//from w w w . ja v a 2 s .com logger.debug("Removed file or directory {} - username: {}", path, username); } catch (IOException e) { throw new RuntimeException("Could not remove file or directory " + path + " in hdfs, user: " + username, e); } }
From source file:org.sharetask.controller.WorkspaceControllerIT.java
@Test public void testDelete() throws IOException { //given// w ww.j av a 2 s . c om final HttpDelete httpDelete = new HttpDelete(URL_WORKSPACE + "/2"); httpDelete.addHeader(new BasicHeader("Content-Type", "application/json")); //when final HttpResponse response = getClient().execute(httpDelete); //then Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode()); }
From source file:com.activiti.service.activiti.TaskService.java
/** * @return true, if the task was deleted. False, if deleting the task failed. *///w ww . ja v a2 s. co m public void deleteTask(ServerConfig serverConfig, String taskId) { if (taskId == null) { throw new IllegalArgumentException("Task id is required"); } JsonNode taskNode = getTask(serverConfig, taskId, false); if (taskNode.has("endTime")) { JsonNode endTimeNode = taskNode.get("endTime"); if (endTimeNode != null && !endTimeNode.isNull() && StringUtils.isNotEmpty(endTimeNode.asText())) { // Completed task URIBuilder builder = clientUtil.createUriBuilder(MessageFormat.format(HISTORIC_TASK_URL, taskId)); HttpDelete delete = new HttpDelete(clientUtil.getServerUrl(serverConfig, builder)); clientUtil.executeRequestNoResponseBody(delete, serverConfig, HttpStatus.SC_NO_CONTENT); } else { // Not completed task URIBuilder builder = clientUtil .createUriBuilder(MessageFormat.format(RUNTIME_TASK_URL, taskId) + "?cascadeHistory=true"); HttpDelete delete = new HttpDelete(clientUtil.getServerUrl(serverConfig, builder)); clientUtil.executeRequestNoResponseBody(delete, serverConfig, HttpStatus.SC_NO_CONTENT); } } }
From source file:com.example.bookstoremb.utils.RestClient.java
/** * check search type and execute request * //from ww w . ja v a2s .co m * @param method The type of request method(ex: GET, POST...) * @throws UnsupportedEncodingException * @throws ClientProtocolException * @throws IOException */ public void execute(RequestMethod method) throws UnsupportedEncodingException, ClientProtocolException, IOException { switch (method) { //case request is get case GET: { String combinedParams = ""; if (!params.isEmpty()) { combinedParams += "?"; for (NameValuePair p : params) { String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(), "UTF-8"); if (combinedParams.length() > 1) { combinedParams += "&" + paramString; } else { combinedParams += paramString; } } } HttpGet request = new HttpGet(url + combinedParams); request.setHeader(AUTHORIZATION, getAuthorization()); for (NameValuePair h : headers) { request.addHeader(h.getName(), h.getValue()); } executeRequest(request, url); break; } //case request is post case POST: { HttpPost request = new HttpPost(url); for (NameValuePair h : headers) { request.addHeader(h.getName(), h.getValue()); request.setHeader(AUTHORIZATION, getAuthorization()); } if (!params.isEmpty()) { request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); } executeRequest(request, url); break; } //case request is delete case DELETE: { HttpDelete request = new HttpDelete(url); request.setHeader(AUTHORIZATION, getAuthorization()); for (NameValuePair h : headers) { request.addHeader(h.getName(), h.getValue()); } executeRequest(request, url); break; } //case request is put case PUT: { HttpPut request = new HttpPut(); request.setHeader(AUTHORIZATION, getAuthorization()); for (NameValuePair h : headers) { request.addHeader(h.getName(), h.getValue()); } executeRequest(request, url); break; } } }
From source file:info.androidhive.volleyjson.util.SslHttpStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. */// w w w .ja va 2 s. co m @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); //setMultiPartBody(postRequest,request); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); //setMultiPartBody(putRequest,request); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } // Added in source code of Volley libray. case Method.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."); } }
From source file:com.google.android.gcm.demo.app.utils.ServerUtilities.java
/** * Issue a Delete request to the server. * * @param endpoint DELETE address.//from w w w .jav a 2 s . co m * @throws IOException propagated from DELETE. */ private static HttpResponse doHttpDelete(String endpoint) throws IOException { return executeRequest(new HttpDelete(endpoint)); }
From source file:eu.betaas.betaasandroidapp.rest.RestClient.java
public String[] deleteResource(String path, Map<HeaderType, String> headers) { HttpHost target = new HttpHost(endpointUrl, port); String[] result;/*from w ww. ja v a 2s . co m*/ try { // specify the post request HttpDelete delRequest = new HttpDelete(path); for (HeaderType header : headers.keySet()) { delRequest.setHeader(HEADERS.get(header), headers.get(header)); } HttpResponse httpResponse = httpclient.execute(target, delRequest); result = getResponse(httpResponse); } catch (Exception e) { result = new String[2]; result[0] = "clientException"; result[1] = e.getMessage(); } return result; }
From source file:com.nxt.zyl.data.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*from w w w. j ava 2 s. co m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { switch (request.getMethod()) { case Request.Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Request.Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.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."); } }