List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getResponseHeaders
@Override
public Header[] getResponseHeaders()
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 {//from ww w. j a va2s . c o m // 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.sa.npopa.samples.hbase.rest.client.Client.java
/** * Send a DELETE request/*from www . j av a2 s.c o 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.funambol.json.api.dao.FunambolJSONApiDAO.java
protected String sendDeleteRequest(String REQUEST, long since, long until) throws IOOperationException { String response = null;//from w ww . j a v a 2s . c om DeleteMethod method = null; try { HttpClient httpClient = new HttpClient(); method = new DeleteMethod(REQUEST); addSinceUntil(method, since, until); if (log.isTraceEnabled()) { log.trace("\nREQUEST: " + REQUEST + ""); } if (this.sessionid != null) { method.setRequestHeader("Authorization", this.sessionid); } printHeaderFields(method.getRequestHeaders(), "REQUEST"); int code = httpClient.executeMethod(method); response = method.getResponseBodyAsString(); if (log.isTraceEnabled()) { log.trace("RESPONSE code: " + code); } printHeaderFields(method.getResponseHeaders(), "RESPONSE"); } catch (Exception e) { throw new IOOperationException("Error GET Request ", e); } finally { if (method != null) { method.releaseConnection(); } } return response; }
From source file:com.worldline.easycukes.rest.client.RestService.java
/** * Allows to send a DELETE request, with parameters using JSON format * * @param path path to be used for the DELETE request * @param data paremeters to be used (JSON format) as a string *//*from ww w. j a v a2 s. c o m*/ @SuppressWarnings("unchecked") public void sendDelete(final String path, final String data) { String fullpath = path; if (path.startsWith("/")) fullpath = baseUrl + path; log.info("Sending DELETE request to " + fullpath); final DeleteMethod method = new DeleteMethod(fullpath); for (final Map.Entry<String, String> header : requestHeaders.entrySet()) method.setRequestHeader(header.getKey(), header.getValue()); if (data != null) { JSONObject jsonObject = null; try { jsonObject = JSONHelper.toJSONObject(data); for (final Iterator<String> iterator = jsonObject.keySet().iterator(); iterator.hasNext();) { final String param = iterator.next(); HttpMethodParams methodParams = new HttpMethodParams(); methodParams.setParameter(param, (jsonObject.get(param) != null) ? jsonObject.get(param).toString() : null); method.setParams(methodParams); } } catch (final ParseException e) { log.error("Sorry, parameters are not proper JSON...", e); } } try { if (nonProxyHost != null && fullpath.contains(nonProxyHost)) { httpClient.getHostConfiguration().setProxyHost(null); } final int statusCode = httpClient.executeMethod(method); response = new ResponseWrapper(method.getResponseBodyAsString(), method.getResponseHeaders(), statusCode); } catch (final IOException e) { log.error(e.getMessage(), e); } finally { method.releaseConnection(); } }