List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:org.exoplatform.addons.es.client.ElasticClient.java
protected ElasticResponse sendHttpDeleteRequest(String url) { ElasticResponse response;/*from w w w . j av a 2 s . com*/ try { HttpDelete httpDeleteRequest = new HttpDelete(url); response = handleHttpResponse(client.execute(httpDeleteRequest)); LOG.debug("Sent request to ES:\n Method = DELETE \nURI = {}", url); logResultDependingOnStatusCode(url, response); } catch (IOException e) { throw new ElasticClientException(e); } return response; }
From source file:org.b3log.latke.urlfetch.bae.BAEURLFetchService.java
@Override public HTTPResponse fetch(final HTTPRequest request) throws IOException { final HttpClient httpClient = new DefaultHttpClient(); final URL url = request.getURL(); final HTTPRequestMethod requestMethod = request.getRequestMethod(); HttpUriRequest httpUriRequest = null; try {/*from w w w . j a v a 2s . com*/ final byte[] payload = request.getPayload(); switch (requestMethod) { case GET: final HttpGet httpGet = new HttpGet(url.toURI()); // FIXME: GET with payload httpUriRequest = httpGet; break; case DELETE: httpUriRequest = new HttpDelete(url.toURI()); break; case HEAD: httpUriRequest = new HttpHead(url.toURI()); break; case POST: final HttpPost httpPost = new HttpPost(url.toURI()); if (null != payload) { httpPost.setEntity(new ByteArrayEntity(payload)); } httpUriRequest = httpPost; break; case PUT: final HttpPut httpPut = new HttpPut(url.toURI()); if (null != payload) { httpPut.setEntity(new ByteArrayEntity(payload)); } httpUriRequest = httpPut; break; default: throw new RuntimeException("Unsupported HTTP request method[" + requestMethod.name() + "]"); } } catch (final Exception e) { LOGGER.log(Level.SEVERE, "URL fetch failed", e); throw new IOException("URL fetch failed [msg=" + e.getMessage() + ']'); } final List<HTTPHeader> headers = request.getHeaders(); for (final HTTPHeader header : headers) { httpUriRequest.addHeader(header.getName(), header.getValue()); } final HttpResponse res = httpClient.execute(httpUriRequest); final HTTPResponse ret = new HTTPResponse(); ret.setContent(EntityUtils.toByteArray(res.getEntity())); ret.setResponseCode(res.getStatusLine().getStatusCode()); return ret; }
From source file:bad.robot.http.apache.ApacheHttpClient.java
@Override public HttpResponse delete(URL url) throws HttpException { return execute(new HttpDelete(url.toExternalForm())); }
From source file:org.qucosa.migration.processors.PurgeFedoraObject.java
@Override public void process(Exchange exchange) throws Exception { Opus4ResourceID resourceID = exchange.getIn().getBody(Opus4ResourceID.class); HttpDelete delete = new HttpDelete(fedoraUri + "/objects/qucosa:" + resourceID.getIdentifier()); HttpResponse response = httpClient.execute(delete); response.getEntity().getContent().close(); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) { String reason = response.getStatusLine().getReasonPhrase(); exchange.isFailed();/*from ww w . ja v a2s. com*/ exchange.setException(new Exception(reason)); } }
From source file:emcewen.websms.services.C2DMRegistrationService.java
private void unregisterForPush() { Log.d(TAG, "Unregister with WebApp!"); HttpClient httpclient = new DefaultHttpClient(); String deviceID = ((TelephonyManager) this.getSystemService(TELEPHONY_SERVICE)).getDeviceId().toString(); HttpDelete httpdelete = new HttpDelete("http://sms.evanmcewen.ca/push_users/" + deviceID); try {/* w w w. j a v a 2 s. c o m*/ // Add your data // Execute HTTP Post Request HttpResponse response = httpclient.execute(httpdelete); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } }
From source file:eu.trentorise.smartcampus.storage.ResourceRetriever.java
private byte[] getFileContent(Token token) throws ClientProtocolException, IOException { HttpUriRequest request = null;/*from w w w. java2 s . co m*/ if (token.getUrl() != null && token.getMethodREST() != null) { if (token.getMethodREST().equals("GET")) { request = new HttpGet(token.getUrl()); } else if (token.getMethodREST().equals("POST")) { request = new HttpPost(token.getUrl()); } else if (token.getMethodREST().equals("PUT")) { request = new HttpPut(token.getUrl()); } else if (token.getMethodREST().equals("DELETE")) { request = new HttpDelete(token.getUrl()); } if (token.getHttpHeaders() != null) { for (Entry<String, String> entry : token.getHttpHeaders().entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } } DefaultHttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(request); if (response.getStatusLine().getStatusCode() == 200) { InputStream is = response.getEntity().getContent(); return eu.trentorise.smartcampus.storage.Utils.read(is); } } else if (token.getMetadata() != null) { return retrieveContent(token.getMetadata()); } return null; }
From source file:com.robustaweb.library.rest.client.implementation.AndroidRestClient.java
/** * {@inheritDoc }/*from ww w.ja va 2 s . co m*/ */ @Override protected void executeMethod(final HttpMethod method, final String url, final String requestBody, final Callback callback) throws HttpException { requestThread = new Thread() { @Override public void run() { HttpRequestBase meth = null; try { switch (method) { case GET: meth = new HttpGet(url); break; case POST: meth = new HttpPost(url); break; case DELETE: meth = new HttpDelete(url); break; case PUT: meth = new HttpPut(url); break; default: meth = new HttpEntityEnclosingRequestBase() { @Override public String getMethod() { return method.getMethod(); } }; break; } // this.builder = new RequestBuilder(meth, url); if (contentType != null && !contentType.isEmpty()) { meth.addHeader("Content-Type", contentType); } if (AndroidRestClient.authorizationValue != null && AndroidRestClient.authorizationValue.length() > 0) { meth.addHeader("Authorization", AndroidRestClient.authorizationValue); } HttpContext localContext = new BasicHttpContext(); HttpResponse response = client.execute(meth, localContext); callback.onSuccess(response.toString()); // headers response HeaderIterator it = response.headerIterator(); while (it.hasNext()) { Header header = it.nextHeader(); responseHeaders.put(header.getName(), header.getValue()); } } catch (Exception ex) { callback.onException(ex); } finally { clean(); } } }; }
From source file:com.wms.opensource.images3android.images3.ImageS3Service.java
public static boolean deleteImage(String baseUrl, String imagePlantId, String imageId) { HttpClient client = getClient();// w ww. j a v a 2s . c o m String url = baseUrl + imagePlantId + "/images/" + imageId; HttpDelete httpDelete = new HttpDelete(url); HttpResponse response; try { response = client.execute(httpDelete); int code = response.getStatusLine().getStatusCode(); if (code == 204) { return true; } } catch (ClientProtocolException e) { } catch (IOException e) { } return false; }
From source file:com.qwazr.mavenplugin.QwazrStopMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { final Log log = getLog(); log.info("Stopping QWAZR"); public_addr = getProperty(public_addr, "PUBLIC_ADDR", "localhost"); webservice_port = getProperty(webservice_port, "WEBSERVICE_PORT", 9091); wait_ms = getProperty(webservice_port, null, 5000); CloseableHttpResponse response = null; CloseableHttpClient httpClient = null; try {//w w w . ja v a2 s.c om httpClient = HttpUtils.createHttpClient_AcceptsUntrustedCerts(); URI uri = new URI("http", null, public_addr, webservice_port, "/shutdown", null, null); log.info("Post HTTP Delete on: " + uri); response = httpClient.execute(new HttpDelete(uri)); log.info("HTTP Status Code: " + response.getStatusLine().getStatusCode()); } catch (IOException | URISyntaxException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { if (fault_tolerant == null || fault_tolerant) log.warn(e); else throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.close(httpClient, response); } try { Thread.sleep(wait_ms); } catch (InterruptedException e) { log.warn(e); } }
From source file:com.mber.client.HTTParty.java
public static Call delete(String url, final JSONObject args) throws IOException { if (args != null) { url += toQuery(args);/*from w ww .ja v a2 s .c o m*/ } HttpDelete request = new HttpDelete(url); return execute(request); }