List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:com.ab.network.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///ww w . j a va 2 s. com @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()); 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; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:io.fabric8.etcd.impl.dsl.DeleteDataImpl.java
@Override public HttpUriRequest createRequest(OperationContext context) { try {/*from w w w . j a v a2s. com*/ URIBuilder builder = new URIBuilder(context.getBaseUri()).setPath(Keys.makeKey(key)) .addParameter("dir", String.valueOf(dir)).addParameter("recursive", String.valueOf(recursive)) .addParameter("prevExists", String.valueOf(prevExists)); if (prevValue != null) { builder = builder.addParameter("prevValue", prevValue).addParameter("prevIndex", String.valueOf(prevIndex)); } return new HttpDelete(builder.build()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.stratos.integration.common.rest.IntegrationMockClient.java
public HttpResponse doDelete(URI resourcePath) throws Exception { HttpDelete httpDelete = null;/*from www.java 2 s . c o m*/ try { httpDelete = new HttpDelete(resourcePath); httpDelete.addHeader("Content-Type", "application/json"); return httpClient.execute(httpDelete, new HttpResponseHandler()); } finally { releaseConnection(httpDelete); } }
From source file:com.joyent.manta.http.MantaHttpRequestFactory.java
/** * Convenience method used for building DELETE operations. * @param path path to resource// w w w . j a v a 2s . co m * @return instance of configured {@link org.apache.http.client.methods.HttpRequestBase} object. */ public HttpDelete delete(final String path) { final HttpDelete request = new HttpDelete(uriForPath(path)); prepare(request); return request; }
From source file:com.volley.android.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from www . ja va 2 s. com @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws 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.getPostBodyContentType()); 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 Request.Method.DELETE: return new HttpDelete(request.getUrl()); case Request.Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Request.Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:fr.efl.chaine.xslt.GauloisListenerTest.java
@Test public void listenerStart() throws Exception { GauloisPipe piper = new GauloisPipe(configFactory); ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/listener/start.xml"); Config config = cu.buildConfig(emptyInputParams); config.setLogFileSize(true);// w w w .j a v a 2 s . c o m config.verify(); assertEquals("Port escape does not work", 8123, config.getSources().getListener().getPort()); assertEquals("STOP keyword escape does not work", "ARRETE", config.getSources().getListener().getStopKeyword()); piper.setConfig(config); piper.setInstanceName("LISTENER_1"); piper.launch(); DefaultHttpClient httpClient = new DefaultHttpClient(); File userDir = new File(System.getProperty("user.dir")); File source = new File(userDir, "src/test/resources/source.xml"); HttpPut put = new HttpPut("http://localhost:8123/?url=" + URLEncoder.encode(source.toURI().toURL().toExternalForm(), "UTF-8")); HttpResponse response = httpClient.execute(put); System.out.println(response.getStatusLine().toString()); assertEquals(200, response.getStatusLine().getStatusCode()); put.releaseConnection(); // the same, with accents source = new File(userDir, "src/test/resources/source_avec_accents.xml"); put = new HttpPut("http://localhost:8123/?url=" + URLEncoder.encode(source.toURI().toURL().toExternalForm(), "UTF-8")); response = httpClient.execute(put); System.out.println(response.getStatusLine().toString()); assertEquals(200, response.getStatusLine().getStatusCode()); put.releaseConnection(); // we must let GauloisPipe process submitted file, because JUnit closes since the tested method returns. Thread.sleep(1000); File outputDir = new File("target/generated-test-files"); File target = new File(outputDir, "source-listen1.xml"); assertTrue("File " + target.toString() + " does not exists", target.exists()); HttpDelete delete = new HttpDelete("http://localhost:8123/?keyword=ARRETE"); response = httpClient.execute(delete); System.out.println(response.getStatusLine().toString()); assertEquals(200, response.getStatusLine().getStatusCode()); delete.releaseConnection(); File appendee = new File(outputDir, "listener-appendee.txt"); assertTrue(appendee.getAbsolutePath() + " does not exists.", appendee.exists()); String previousLine = null; try (BufferedReader br = new BufferedReader(new FileReader(appendee))) { String currentLine = br.readLine(); while (currentLine != null) { previousLine = currentLine; currentLine = br.readLine(); } } assertEquals(appendee.getAbsolutePath() + " does not ends with \"EOF\"", "EOF", previousLine); }
From source file:com.mr.http.toolbox.MR_HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w .java2s . c o m @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(MR_Request<?> request, Map<String, String> additionalHeaders) throws MR_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()); 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; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.srotya.tau.ui.rules.TenantManager.java
public Tenant deleteTenant(UserBean ub, String tenantId) throws Exception { Tenant tenant = getTenant(ub, tenantId); if (tenant != null) { try {//from w ww.j av a 2 s. co m CloseableHttpClient client = Utils.buildClient(am.getBaseUrl(), am.getConnectTimeout(), am.getRequestTimeout()); HttpDelete delete = new HttpDelete(am.getBaseUrl() + TENANT_URL + "/" + tenantId); if (am.isEnableAuth()) { delete.addHeader(BapiLoginDAO.X_SUBJECT_TOKEN, ub.getToken()); delete.addHeader(BapiLoginDAO.HMAC, ub.getHmac()); } CloseableHttpResponse resp = client.execute(delete); if (!Utils.validateStatus(resp)) { throw new Exception("status code:" + resp.getStatusLine().getStatusCode()); } return tenant; } catch (Exception e) { logger.log(Level.SEVERE, "Failed to delete tenant:" + tenant, e); throw e; } } else { throw new NotFoundException("Tenant not found"); } }
From source file:com.wudoumi.batter.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. */// w ww . j a v a 2 s . co m @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case RequestType.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 RequestType.GET: return new HttpGet(request.getUrl()); case RequestType.DELETE: return new HttpDelete(request.getUrl()); case RequestType.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case RequestType.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:org.simple.net.httpstacks.HttpClientStack.java
/** * ???Http//from ww w . ja va 2 s .c o m * * @param request * @return */ static HttpUriRequest createHttpRequest(Request<?> request) { HttpUriRequest httpUriRequest = null; switch (request.getHttpMethod()) { case GET: httpUriRequest = new HttpGet(request.getUrl()); break; case DELETE: httpUriRequest = new HttpDelete(request.getUrl()); break; case POST: { httpUriRequest = new HttpPost(request.getUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPost) httpUriRequest, request); } break; case PUT: { httpUriRequest = new HttpPut(request.getUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPut) httpUriRequest, request); } break; default: throw new IllegalStateException("Unknown request method."); } return httpUriRequest; }