List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:com.zimbra.cs.index.ElasticSearchIndexTest.java
@Override protected void cleanupForIndexStore() { String key = testAcct.getId(); String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key); HttpMethod method = new DeleteMethod(indexUrl); try {//from w ww. ja v a 2s .c o m ElasticSearchConnector connector = new ElasticSearchConnector(); int statusCode = connector.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false); boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false); if (!ok || !acknowledged) { ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged); } } else { String error = connector.getStringAtJsonPath(new String[] { "error" }); if (error != null && error.startsWith("IndexMissingException")) { ZimbraLog.index.debug("Unable to delete index for key=%s. Index is missing", key); } else { ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error); } } } catch (HttpException e) { ZimbraLog.index.error("Problem Deleting index with key=" + key, e); } catch (IOException e) { ZimbraLog.index.error("Problem Deleting index with key=" + key, e); } }
From source file:net.sf.ufsc.http.HttpFile.java
/** * @see net.sf.ufsc.File#delete()//w w w . j av a 2 s. c o m */ public void delete() throws java.io.IOException { DeleteMethod method = new DeleteMethod(this.uri.toString()); try { this.execute(method); method.getResponseBody(); } finally { method.releaseConnection(); } }
From source file:edu.northwestern.jcr.adapter.fedora.persistence.FedoraConnectorREST.java
/** * Sends an HTTP DELETE request and returns the status code. * * @param url URL of the resource/*from w ww .j a v a 2 s . c o m*/ * @return status code */ private int httpDelete(String url) { DeleteMethod deleteMethod = null; try { deleteMethod = new DeleteMethod(url); deleteMethod.setDoAuthentication(true); deleteMethod.getParams().setParameter("Connection", "Keep-Alive"); fc.getHttpClient().executeMethod(deleteMethod); return deleteMethod.getStatusCode(); } catch (Exception e) { e.printStackTrace(); log.warn("failed to delete!"); return -1; } finally { if (deleteMethod != null) { deleteMethod.releaseConnection(); } } }
From source file:com.owncloud.android.lib.resources.files.ToggleEncryptionOperation.java
/** * @param client Client object/*from w w w. ja v a 2 s .c om*/ */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; HttpMethodBase method = null; ReadRemoteFolderOperation remoteFolderOperation = new ReadRemoteFolderOperation(remotePath); RemoteOperationResult remoteFolderOperationResult = remoteFolderOperation.execute(client); // Abort if not empty // Result has always the folder and maybe children, so size == 1 is ok if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().size() > 1) { return new RemoteOperationResult(false, "Non empty", HttpStatus.SC_FORBIDDEN); } try { String url = client.getBaseUri() + ENCRYPTED_URL + localId; if (encryption) { method = new PutMethod(url); } else { method = new DeleteMethod(url); } // remote request method.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); method.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); int status = client.executeMethod(method, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { result = new RemoteOperationResult(true, method); } else { result = new RemoteOperationResult(false, method); client.exhaustResponse(method.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Setting encryption status of " + localId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (method != null) method.releaseConnection(); } return result; }
From source file:net.oauth.client.httpclient3.HttpClient3.java
public HttpResponseMessage execute(HttpMessage request, Map<String, Object> parameters) throws IOException { final String method = request.method; final String url = request.url.toExternalForm(); final InputStream body = request.getBody(); final boolean isDelete = DELETE.equalsIgnoreCase(method); final boolean isPost = POST.equalsIgnoreCase(method); final boolean isPut = PUT.equalsIgnoreCase(method); byte[] excerpt = null; HttpMethod httpMethod;//from w ww . j a va 2s . c om if (isPost || isPut) { EntityEnclosingMethod entityEnclosingMethod = isPost ? new PostMethod(url) : new PutMethod(url); if (body != null) { ExcerptInputStream e = new ExcerptInputStream(body); String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH); entityEnclosingMethod.setRequestEntity((length == null) ? new InputStreamRequestEntity(e) : new InputStreamRequestEntity(e, Long.parseLong(length))); excerpt = e.getExcerpt(); } httpMethod = entityEnclosingMethod; } else if (isDelete) { httpMethod = new DeleteMethod(url); } else { httpMethod = new GetMethod(url); } for (Map.Entry<String, Object> p : parameters.entrySet()) { String name = p.getKey(); String value = p.getValue().toString(); if (FOLLOW_REDIRECTS.equals(name)) { httpMethod.setFollowRedirects(Boolean.parseBoolean(value)); } else if (READ_TIMEOUT.equals(name)) { httpMethod.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(value)); } } for (Map.Entry<String, String> header : request.headers) { httpMethod.addRequestHeader(header.getKey(), header.getValue()); } HttpClient client = clientPool.getHttpClient(new URL(httpMethod.getURI().toString())); client.executeMethod(httpMethod); return new HttpMethodResponse(httpMethod, excerpt, request.getContentCharset()); }
From source file:CertStreamCallback.java
private static HttpMethod getHttpMethod(String url, String method) { if ("delete".equals(method)) { return new DeleteMethod(url); } else if ("get".equals(method)) { return new GetMethod(url); } else if ("post".equals(method)) { return new PostMethod(url); } else if ("put".equals(method)) { return new PutMethod(url); } else {/*from ww w. ja v a 2 s . co m*/ throw ActionException.create(ClientMessages.NO_METHOD1, method); } }
From source file:com.sixdimensions.wcm.cq.dao.webdav.WebDavDAO.java
/** * Delete a file from the Sling repository * //from ww w .j a v a 2s. co m * @return the HTTP status code */ public int delete(final String path) throws IOException { this.log.debug("delete"); final DeleteMethod delete = new DeleteMethod(this.config.getHost() + ":" + this.config.getPort() + path); return this.httpClient.executeMethod(delete); }
From source file:com.wandisco.s3hdfs.rewrite.redirect.Redirect.java
HttpMethod getHttpMethod(String scheme, String host, int port, String op, String userName, String uri, HTTP_METHOD method) {// ww w. java 2 s. c o m if (!uri.startsWith(WEBHDFS_PREFIX)) uri = ADD_WEBHDFS(uri); String url = scheme + "://" + host + ":" + port + uri + "?user.name=" + userName + "&op=" + op; switch (method) { case GET: return new GetMethod(url); case PUT: return new PutMethod(url); case POST: return new PostMethod(url); case DELETE: return new DeleteMethod(url); case HEAD: return new HeadMethod(url); default: return null; } }
From source file:demo.jaxrs.search.client.Client.java
private static void delete(final String url, final HttpClient httpClient) throws IOException, HttpException { System.out.println("Sent HTTP DELETE request to remove all books from catalog"); final DeleteMethod delete = new DeleteMethod(url); try {/*from w w w .j av a 2 s . co m*/ int status = httpClient.executeMethod(delete); if (status == 200) { System.out.println(delete.getResponseBodyAsString()); } } finally { delete.releaseConnection(); } }
From source file:cz.muni.fi.pa165.creatures.rest.client.services.impl.RegionCRUDServiceImpl.java
@Override public void delete(Long id) { DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id); CRUDServiceHelper.send(deleteMethod); }