List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:com.manning.blogapps.chapter10.examples.AuthDelete.java
public static void main(String[] args) throws Exception { if (args.length < 3) { System.out.println("USAGE: authdelete <username> <password> <url>"); System.exit(-1);//w w w . ja v a2 s . com } String credentials = args[0] + ":" + args[1]; String url = args[2]; HttpClient httpClient = new HttpClient(); DeleteMethod method = new DeleteMethod(url); method.setRequestHeader("Authorization", "Basic " + new String(Base64.encodeBase64(credentials.getBytes()))); httpClient.executeMethod(method); System.out.println("Server returned status code: "); }
From source file:com.agile_coder.poker.server.stories.steps.ResetEstimatesSteps.java
@When("I reset the estimates") public void reset() throws IOException { HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod(BASE_URL + "/" + sessionId + "/status"); client.executeMethod(delete);//from w ww . ja v a 2 s . co m assertEquals(HttpStatus.SC_NO_CONTENT, delete.getStatusCode()); }
From source file:com.predic8.membrane.core.http.MethodTest.java
@Test public void testDELETE() throws Exception { HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod("http://localhost:4000/method-test/"); int status = client.executeMethod(delete); assertTrue(status < 400);/*w w w . j a va2s. c om*/ }
From source file:net.bioclipse.opentox.api.Task.java
public static void delete(String task) throws IOException, GeneralSecurityException { HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(task); method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT)); client.executeMethod(method);/*from www. ja v a2s .com*/ int status = method.getStatusCode(); switch (status) { case 200: // excellent, it worked break; case 401: throw new GeneralSecurityException("Not authorized"); case 404: // not found, well, I guess equals 'deleted' break; case 503: throw new IOException("Service unavailable"); default: throw new IOException("Unknown server state: " + status); } }
From source file:javaapplicationclientrest.ControllerCliente.java
public void removerNoticia(String id) { DeleteMethod del = new DeleteMethod(String.format(Constants.REMOVE_NOTICIA, id)); // System.out.println(String.format(Constants.REMOVE_NOTICIA, id)); try {/*from w ww . ja va 2s. c om*/ http.executeMethod(del); System.out.println("Status: " + del.getStatusText()); System.out.println(del.getResponseBodyAsString()); } catch (IOException ex) { Logger.getLogger(ControllerCliente.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.sf.j2ep.requesthandlers.BasicRequestHandler.java
/** * Will only set the headers.// w w w .j ava 2 s. c o m * @throws HttpException * * @see net.sf.j2ep.model.RequestHandler#process(javax.servlet.http.HttpServletRequest, java.lang.String) */ public HttpMethod process(HttpServletRequest request, String url) throws HttpException { HttpMethodBase method = null; if (request.getMethod().equalsIgnoreCase("GET")) { method = new GetMethod(url); } else if (request.getMethod().equalsIgnoreCase("HEAD")) { method = new HeadMethod(url); } else if (request.getMethod().equalsIgnoreCase("DELETE")) { method = new DeleteMethod(url); } else { return null; } setHeaders(method, request); return method; }
From source file:com.owncloud.android.lib.resources.users.DeletePublicKeyOperation.java
/** * @param client Client object//from w w w. j a 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.owncloud.android.lib.resources.files.UnlockFileOperation.java
/** * @param client Client object//from www . j a va2s . 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:com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForNotificationsOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; DeleteMethod delete = null;// ww w . j a va 2 s . co m try { // 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:it.geosolutions.httpproxy.utils.ProxyMethodConfig.java
/** * Obtain he method generation with {@link ProxyMethodConfig#method} and {@link ProxyMethodConfig#url} * //from w w w.j a v a2 s. co m * @return HttpMethod only supports {DELETE, GET, POST and PUT} @see {@link HttpMethods} */ public HttpMethod getMethod() { if (HttpMethods.METHOD_DELETE.equals(method)) { return new DeleteMethod(url.toExternalForm()); } else if (HttpMethods.METHOD_GET.equals(method)) { return new GetMethod(url.toExternalForm()); } else if (HttpMethods.METHOD_POST.equals(method)) { return new PostMethod(url.toExternalForm()); } else if (HttpMethods.METHOD_PUT.equals(method)) { return new PutMethod(url.toExternalForm()); } else { // Default is doGet return new GetMethod(url.toExternalForm()); } }