List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:org.bibsonomy.rest.client.worker.impl.DeleteWorker.java
@Override protected DeleteMethod getMethod(final String url, String requestBody) { final DeleteMethod delete = new DeleteMethod(url); delete.setFollowRedirects(true);/*from w w w .ja v a2s. c o m*/ return delete; }
From source file:org.cloudata.core.rest.CRestTable.java
public String dropTable(String tableName) throws IOException { HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(selectRestServer() + "/table/" + tableName); int result = client.executeMethod(method); if (result != 200) { throw new IOException(method.getResponseBodyAsString()); }//from w w w . ja v a 2s .co m return method.getResponseBodyAsString(); }
From source file:org.cloudata.core.rest.CRestTable.java
public String delete(String tableName, String rowKey) throws IOException { HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(selectRestServer() + "/" + tableName + "/" + rowKey); int result = client.executeMethod(method); if (result != 200) { throw new IOException(method.getResponseBodyAsString()); }//from w w w .jav a 2s .c o m return method.getResponseBodyAsString(); }
From source file:org.codehaus.httpcache4j.client.HTTPClientResponseResolver.java
/** * Determines the HttpClient's request method from the HTTPMethod enum. * * @param method the HTTPCache enum that determines * @param requestURI the request URI.// w ww .jav a 2 s .c o m * @return a new HttpMethod subclass. */ protected HttpMethod getMethod(HTTPMethod method, URI requestURI) { if (CONNECT.equals(method)) { HostConfiguration config = new HostConfiguration(); config.setHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme()); return new ConnectMethod(config); } else if (DELETE.equals(method)) { return new DeleteMethod(requestURI.toString()); } else if (GET.equals(method)) { return new GetMethod(requestURI.toString()); } else if (HEAD.equals(method)) { return new HeadMethod(requestURI.toString()); } else if (OPTIONS.equals(method)) { return new OptionsMethod(requestURI.toString()); } else if (POST.equals(method)) { return new PostMethod(requestURI.toString()); } else if (PUT.equals(method)) { return new PutMethod(requestURI.toString()); } else if (TRACE.equals(method)) { return new TraceMethod(requestURI.toString()); } else { throw new IllegalArgumentException("Cannot handle method: " + method); } }
From source file:org.collectionspace.chain.csp.persistence.services.connection.ServicesConnection.java
private HttpMethod createMethod(RequestMethod method, String uri, InputStream data) throws ConnectionException { uri = prepend_base(uri);/*from ww w . j a v a2 s .co m*/ if (uri == null) throw new ConnectionException("URI must not be null"); // Extract QP's int qp_start = uri.indexOf('?'); String qps = null; if (qp_start != -1) { qps = uri.substring(qp_start + 1); uri = uri.substring(0, qp_start); } HttpMethod out = null; switch (method) { case POST: { out = new PostMethod(uri); if (data != null) ((PostMethod) out).setRequestEntity(new InputStreamRequestEntity(data)); break; } case PUT: { out = new PutMethod(uri); if (data != null) ((PutMethod) out).setRequestEntity(new InputStreamRequestEntity(data)); break; } case GET: out = new GetMethod(uri); break; case DELETE: out = new DeleteMethod(uri); break; default: throw new ConnectionException("Unsupported method " + method, 0, uri); } if (qps != null) out.setQueryString(qps); out.setDoAuthentication(true); return out; }
From source file:org.collectionspace.services.client.test.BaseServiceTest.java
/** * Submits an HTTP request to a specified URL, and returns the * status code of the response. Currently accepts GET and DELETE * requests.//from w ww.j av a 2 s . c o m * * @param method An HTTP method. * * @param url A String representation of a URL. * * @return The status code received in the HTTP response. */ protected int submitRequest(String method, String url) { int statusCode = 0; HttpMethodBase httpMethod = null; try { TestServiceClient client = new TestServiceClient(); if (method.equals(javax.ws.rs.HttpMethod.DELETE)) { httpMethod = new DeleteMethod(url); } else if (method.equals(javax.ws.rs.HttpMethod.GET)) { httpMethod = new GetMethod(url); } if (httpMethod != null) { statusCode = client.getHttpClient().executeMethod(httpMethod); } } catch (Exception e) { logger.error("Exception during HTTP " + method + " request to " + url + ":", e); } finally { if (httpMethod != null) httpMethod.releaseConnection(); } return statusCode; }
From source file:org.collectionspace.services.client.test.ServiceLayerTest.java
@Test public void methodNotAllowed() { if (logger.isDebugEnabled()) { logger.debug(BaseServiceTest.testBanner("methodNotAllowed", CLASS_NAME)); }//from w w w . j a va 2 s . c o m // Delete is not allowed on the root URL of the id service String url = serviceClient.getBaseURL() + "idgenerators"; DeleteMethod method = new DeleteMethod(url); try { int statusCode = httpClient.executeMethod(method); if (logger.isDebugEnabled()) { logger.debug(" methodNotAllowed url=" + url + " status=" + statusCode); } Assert.assertEquals(statusCode, HttpStatus.SC_METHOD_NOT_ALLOWED, "expected " + HttpStatus.SC_METHOD_NOT_ALLOWED); } catch (HttpException e) { logger.error("Fatal protocol violation: ", e); } catch (IOException e) { logger.error("Fatal transport error", e); } catch (Exception e) { logger.error("unknown exception ", e); } finally { // Release the connection. method.releaseConnection(); } }
From source file:org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplayTransport.java
public static ServiceResult doDELETE(String urlString, String authForTest, String testID, String fromTestID) throws Exception { ServiceResult pr = new ServiceResult(); pr.failureReason = ""; pr.method = "DELETE"; pr.fullURL = urlString;/*from w ww .jav a2s . c o m*/ pr.fromTestID = fromTestID; if (Tools.isEmpty(urlString)) { pr.error = "url was empty. Check the result for fromTestID: " + fromTestID + ". currentTest: " + testID; return pr; } HttpClient client = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(urlString); deleteMethod.setRequestHeader("Accept", "multipart/mixed"); deleteMethod.addRequestHeader("Accept", "application/xml"); deleteMethod.setRequestHeader("Authorization", "Basic " + authForTest); deleteMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID); int statusCode1 = 0; String res = ""; try { statusCode1 = client.executeMethod(deleteMethod); pr.responseCode = statusCode1; //System.out.println("statusCode: "+statusCode1+" statusLine ==>" + deleteMethod.getStatusLine()); pr.responseMessage = deleteMethod.getStatusText(); res = deleteMethod.getResponseBodyAsString(); deleteMethod.releaseConnection(); } catch (Throwable t) { pr.error = t.toString(); } pr.result = res; pr.responseCode = statusCode1; return pr; }
From source file:org.craftercms.studio.impl.v1.repository.alfresco.AlfrescoContentRepository.java
@Override public boolean logout() { long startTime = System.currentTimeMillis(); //make me do something String ticket = getSessionTicket(); logger.debug("Invalidating ticket " + ticket); Map<String, String> params = new HashMap<>(); params.put("ticket", ticket); String serviceURL = null;// www . j a v a2 s . c om try { serviceURL = buildAlfrescoRequestURL("/api/login/ticket/{ticket}", params); DeleteMethod getMethod = new DeleteMethod(serviceURL); HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); int status = httpClient.executeMethod(getMethod); if (status == HttpStatus.SC_OK) { long duration = System.currentTimeMillis() - startTime; logger.debug("logout()\n\t\tDuration: {0}", duration); return true; } } catch (Exception e) { logger.error("Error while invalidating authentication token", e); } long duration = System.currentTimeMillis() - startTime; logger.debug("TRACE: logout()\n\t\tDuration: {0}", duration); return false; }
From source file:org.dasein.persist.riak.RiakCache.java
@Override public void remove(Transaction xaction, T item) throws PersistenceException { startCall("remove"); try {/*w ww. j a v a2 s .c o m*/ StringBuilder url = new StringBuilder(); url.append(getEndpoint()); url.append("buckets/"); url.append(getBucket()); url.append("/keys/"); url.append(getKeyValue(item)); HttpClient client = getClient(); DeleteMethod delete = new DeleteMethod(url.toString()); int code; try { if (wire.isDebugEnabled()) { try { wire.debug(delete.getName() + " " + url.toString()); wire.debug(""); for (Header h : delete.getRequestHeaders()) { wire.debug(h.getName() + ": " + h.getValue()); } wire.debug(""); } catch (Throwable ignore) { // ignore } } code = client.executeMethod(delete); } catch (HttpException e) { throw new PersistenceException("HttpException during GET: " + e.getMessage()); } catch (IOException e) { throw new PersistenceException("IOException during GET: " + e.getMessage()); } try { String body = delete.getResponseBodyAsString(); if (wire.isDebugEnabled()) { try { wire.debug("----------------------------------------"); wire.debug(""); wire.debug(delete.getStatusLine().getStatusCode() + " " + delete.getStatusLine().getReasonPhrase()); wire.debug(""); if (body != null) { wire.debug(body); wire.debug(""); } } catch (Throwable ignore) { // ignore } } if (code != HttpStatus.SC_NO_CONTENT && code != HttpStatus.SC_NOT_FOUND) { throw new PersistenceException(code + ": " + body); } getCache().release(item); } catch (IOException e) { throw new PersistenceException(e); } } finally { endCall("remove"); } }