List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:com.impetus.kundera.ycsb.utils.CouchDBOperationUtils.java
public void dropDatabase(String keyspace, String host, int port) throws URISyntaxException, ClientProtocolException, IOException { initiateClient(host, port);/*w w w . j a va 2 s. c o m*/ URI uri = new URI(CouchDBConstants.PROTOCOL, null, httpHost.getHostName(), httpHost.getPort(), CouchDBConstants.URL_SAPRATOR + keyspace.toLowerCase(), null, null); HttpDelete delete = new HttpDelete(uri); HttpResponse delReq = null; try { // creating database. logger.info("Droping database " + keyspace); delReq = httpClient.execute(httpHost, delete, CouchDBUtils.getContext(httpHost)); } finally { CouchDBUtils.closeContent(delReq); } }
From source file:org.wrml.runtime.service.rest.RestService.java
@Override public void delete(final Keys keys, final Dimensions dimensions) { final Context context = getContext(); final URI uri = keys.getValue(context.getSchemaLoader().getDocumentSchemaUri()); final HttpDelete httpDelete = new HttpDelete(uri); executeRequest(httpDelete);//from w ww . j a va2s. c o m }
From source file:com.google.appengine.tck.endpoints.support.EndPointClient.java
public String doDelete(URL url) throws Exception { return doRequest(new HttpDelete(url.toURI())); }
From source file:org.fcrepo.integration.api.FedoraObjectsIT.java
@Test public void testDeleteObject() throws Exception { assertEquals(201, getStatus(postObjMethod("FedoraObjectsTest3"))); assertEquals(204, getStatus(new HttpDelete(serverAddress + "objects/FedoraObjectsTest3"))); assertEquals("Object wasn't really deleted!", 404, getStatus(new HttpGet(serverAddress + "objects/FedoraObjectsTest3"))); }
From source file:com.imaginary.home.device.hue.HueMethod.java
public void delete(@Nonnull String resource) throws HueException { Logger std = Hue.getLogger(HueMethod.class); Logger wire = Hue.getWireLogger(HueMethod.class); if (std.isTraceEnabled()) { std.trace("enter - " + HueMethod.class.getName() + ".delete(" + resource + ")"); }/*from w w w.ja v a2 s. c o m*/ if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource); } try { HttpClient client = getClient(); HttpDelete method = new HttpDelete(hue.getAPIEndpoint() + resource); method.addHeader("Content-Type", "application/json"); if (wire.isDebugEnabled()) { wire.debug(method.getRequestLine().toString()); for (Header header : method.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); } HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { std.error("DELETE: Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); if (std.isTraceEnabled()) { e.printStackTrace(); } throw new HueException(e); } if (std.isDebugEnabled()) { std.debug("DELETE: HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() != HttpServletResponse.SC_OK && status.getStatusCode() != HttpServletResponse.SC_NO_CONTENT && status.getStatusCode() != HttpServletResponse.SC_ACCEPTED) { std.error("DELETE: Expected OK or NO_CONTENT or ACCEPTED for DELETE request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new HueException(status.getStatusCode(), "An error was returned without explanation"); } String body; try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new HueException(status.getStatusCode(), e.getMessage()); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); throw new HueException(status.getStatusCode(), body); } } finally { if (std.isTraceEnabled()) { std.trace("exit - " + HueMethod.class.getName() + ".delete()"); } if (wire.isDebugEnabled()) { wire.debug("<<< [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } }
From source file:org.opennms.smoketest.RequisitionUtils.java
protected void deleteTestRequisition() throws Exception { final Integer responseCode = m_testCase.doRequest(new HttpGet(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/requisitions/" + OpenNMSSeleniumTestCase.REQUISITION_NAME)); LOG.debug("Checking for existing test requisition: {}", responseCode); if (responseCode == 404 || responseCode == 204) { LOG.debug("deleteTestRequisition: already deleted"); return;//from w ww .j ava2 s . c o m } for (OnmsNode node : getNodesInDatabase(OpenNMSSeleniumTestCase.REQUISITION_NAME)) { m_testCase.doRequest( new HttpDelete(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/nodes/" + node.getId())); } m_testCase.doRequest(new HttpDelete(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/requisitions/" + OpenNMSSeleniumTestCase.REQUISITION_NAME)); m_testCase.doRequest(new HttpDelete(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/requisitions/deployed/" + OpenNMSSeleniumTestCase.REQUISITION_NAME)); m_testCase.doRequest(new HttpDelete(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/foreignSources/" + OpenNMSSeleniumTestCase.REQUISITION_NAME)); m_testCase.doRequest(new HttpDelete(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/foreignSources/deployed/" + OpenNMSSeleniumTestCase.REQUISITION_NAME)); m_testCase.doRequest(new HttpGet(OpenNMSSeleniumTestCase.BASE_URL + "/opennms/rest/requisitions")); }
From source file:edu.vt.alerts.android.library.tasks.CancelRegistrationTask.java
/** * {@inheritDoc}//from w ww.j a v a2 s . co m */ @Override protected TaskResult<Boolean> doInBackground(Void... params) { try { if (keyStoreContainer.retrieveKeyStore(context, environment) == null) return new TaskResult<Boolean>(true, null); String subscriberUrl = PreferenceUtil.getSubscriberUrl(context, environment); if (subscriberUrl == null || subscriberUrl.length() == 0) return new TaskResult<Boolean>(true, null); HttpClient client = httpClientFactory.generateSubscriberClient(context, environment); HttpDelete delete = new HttpDelete(subscriberUrl); HttpResponse response = client.execute(delete); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); Log.d("cancelRegistration", "Received a " + statusCode); if (statusCode >= 200 || statusCode < 300) { return new TaskResult<Boolean>(true, null); } else if (statusCode == 401 || statusCode == 403 || statusCode == 404) { return new TaskResult<Boolean>(true, null); } throw new UnexpectedNetworkResponseException("Unexpected response while trying to cancel registration", statusCode, statusLine.getReasonPhrase()); } catch (Exception e) { return new TaskResult<Boolean>(false, e); } }
From source file:v2.service.generic.library.utils.HttpClientUtil.java
public static ResponsePOJO nativeRequest(String url, String json, String requestType, Map<String, String> headers) throws Exception { HttpClient httpclient = createHttpClient(); // HttpEntityEnclosingRequestBase request=null; HttpRequestBase request = null;// ww w .j a v a2 s . c o m if ("POST".equalsIgnoreCase(requestType)) { request = new HttpPost(url); } else if ("PUT".equalsIgnoreCase(requestType)) { request = new HttpPut(url); } else if ("GET".equalsIgnoreCase(requestType)) { request = new HttpGet(url); } else if ("DELETE".equalsIgnoreCase(requestType)) { request = new HttpDelete(url); } if (json != null) { if (!"GET".equalsIgnoreCase(requestType) && (!"DELETE".equalsIgnoreCase(requestType))) { StringEntity params = new StringEntity(json, "UTF-8"); // StringEntity s = new StringEntity(jsonString, "UTF-8"); ((HttpEntityEnclosingRequestBase) request).setEntity(params); } } if (headers == null) { request.addHeader("content-type", "application/json"); } else { Set<String> keySet_header = headers.keySet(); for (String key : keySet_header) { request.setHeader(key, headers.get(key)); } } ResponsePOJO result = nativeInvoke(httpclient, request); return result; }
From source file:com.mongolduu.android.ng.misc.HttpConnector.java
public static String httpDELETE(String url) throws ClientProtocolException, IOException { HttpClient httpClient = createHttpClient(); HttpResponse response = httpClient.execute(new HttpDelete(url)); if (response.getStatusLine().getStatusCode() >= 400) { throw new IOException("HTTP client error: " + response.getStatusLine().getStatusCode()); }/*w w w. j av a 2 s . c om*/ return processEntity(response.getEntity()); }
From source file:es.ucm.look.data.remote.restful.RestMethod.java
/** * Delete a resource in the server/*from ww w. j a va 2 s. co m*/ * * @param url * Element URI * @throws ClientProtocolException * @throws IOException */ public static void doDelete(String url) throws ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient(); HttpDelete delete = new HttpDelete(url); delete.addHeader("accept", "application/json"); httpclient.execute(delete); }