List of usage examples for org.apache.commons.httpclient.methods DeleteMethod releaseConnection
@Override public void releaseConnection()
From source file:com.sa.npopa.samples.hbase.rest.client.Client.java
/** * Send a DELETE request//from w w w . ja v a 2s . co m * @param cluster the cluster definition * @param path the path or URI * @return a Response object with response detail * @throws IOException */ public Response delete(Cluster cluster, String path) throws IOException { DeleteMethod method = new DeleteMethod(); try { int code = execute(cluster, method, null, path); Header[] headers = method.getResponseHeaders(); byte[] content = method.getResponseBody(); return new Response(code, headers, content); } finally { method.releaseConnection(); } }
From source file:com.cloud.network.nicira.NiciraNvpApi.java
private void executeDeleteObject(String uri) throws NiciraNvpApiException { String url;/*from w w w . j a va 2 s. c om*/ try { url = new URL(_protocol, _host, uri).toString(); } catch (MalformedURLException e) { s_logger.error("Unable to build Nicira API URL", e); throw new NiciraNvpApiException("Unable to build Nicira API URL", e); } DeleteMethod dm = new DeleteMethod(url); dm.setRequestHeader("Content-Type", "application/json"); executeMethod(dm); if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage = responseToErrorMessage(dm); dm.releaseConnection(); s_logger.error("Failed to delete object : " + errorMessage); throw new NiciraNvpApiException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); }
From source file:com.zimbra.cs.store.triton.TritonBlobStoreManager.java
@Override public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); DeleteMethod delete = new DeleteMethod(blobApiUrl + locator); delete.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString()); try {/* w w w. j a va2 s . c o m*/ ZimbraLog.store.info("deleting %s", delete.getURI()); int statusCode = HttpClientUtil.executeMethod(client, delete); if (statusCode == HttpStatus.SC_OK) { return true; } else { throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText()); } } finally { delete.releaseConnection(); } }
From source file:com.owncloud.android.lib.resources.users.DeletePublicKeyOperation.java
/** * @param client Client object/* w ww .ja v a 2 s. c o m*/ */ @Override protected RemoteOperationResult run(OwnCloudClient client) { DeleteMethod postMethod = null; RemoteOperationResult result; try { // remote request postMethod = new DeleteMethod(client.getBaseUri() + PUBLIC_KEY_URL); postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); result = new RemoteOperationResult(status == HttpStatus.SC_OK, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Deletion of public key failed: " + result.getLogMessage(), result.getException()); } finally { if (postMethod != null) postMethod.releaseConnection(); } return result; }
From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java
@Override public void invalidateSessionToken(Long userId) { // Create a method instance. String resource = String.format(baseUrl + USER_SESSION, userId); DeleteMethod method = new DeleteMethod(resource); try {//from w w w . j a v a 2 s . co m // Execute the method. int statusCode = getClient().executeMethod(method); assertResponseCodeOK(method, statusCode); } catch (Exception e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForNotificationsOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; DeleteMethod delete = null; try {// ww w . j av a 2s . com // Post Method delete = new DeleteMethod(client.getBaseUri() + OCS_ROUTE); delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(delete); String response = delete.getResponseBodyAsString(); if (isSuccess(status)) { result = new RemoteOperationResult(true, status, delete.getResponseHeaders()); Log_OC.d(TAG, "Successful response: " + response); } else { result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while registering device for notifications", e); } finally { if (delete != null) { delete.releaseConnection(); } } return result; }
From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java
/** * @see {@link GraphRepository#delete(String)} *///from w w w .j a v a2 s .c o m public void delete(String rdfXml) throws Exception { // DELETE DeleteMethod del = new DeleteMethod(servletURL); try { // add the range header if (rdfXml != null) { String triples = "triples[" + trim(rdfXml) + "]"; Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, triples); del.addRequestHeader(range); } // Execute the method. int sc = getHttpClient().executeMethod(del); if (sc != HttpStatus.SC_OK) { throw new IOException("HTTP-DELETE failed: " + del.getStatusLine()); } } finally { // Release the connection. del.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 w w .ja 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.UnlockFileOperation.java
/** * @param client Client object//from w w w . j a v a 2s . c o m */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; DeleteMethod deleteMethod = null; try { // remote request deleteMethod = new DeleteMethod(client.getBaseUri() + LOCK_FILE_URL + localId); deleteMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); deleteMethod.addRequestHeader(TOKEN, token); int status = client.executeMethod(deleteMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); result = new RemoteOperationResult(status == HttpStatus.SC_OK, deleteMethod); client.exhaustResponse(deleteMethod.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Unlock file with id " + localId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (deleteMethod != null) deleteMethod.releaseConnection(); } return result; }
From source file:it.geosolutions.geoserver.rest.HTTPUtils.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; HttpClient client = new HttpClient(); HttpConnectionManager connectionManager = client.getHttpConnectionManager(); try {/* ww w . j ava 2 s. com*/ setAuth(client, url, user, pw); httpMethod = new DeleteMethod(url); connectionManager.getParams().setConnectionTimeout(5000); int status = client.executeMethod(httpMethod); String response = ""; if (status == HttpStatus.SC_OK) { InputStream is = httpMethod.getResponseBodyAsStream(); response = IOUtils.toString(is); IOUtils.closeQuietly(is); if (response.trim().equals("")) { if (LOGGER.isTraceEnabled()) LOGGER.trace( "ResponseBody is empty (this may be not an error since we just performed a DELETE call)"); return true; } if (LOGGER.isDebugEnabled()) LOGGER.debug("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); return true; } else { LOGGER.info("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); LOGGER.info("Response: '" + response + "'"); } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); } catch (IOException e) { LOGGER.info("Error talking to [" + url + "]", e); } finally { if (httpMethod != null) httpMethod.releaseConnection(); connectionManager.closeIdleConnections(0); } return false; }