List of usage examples for org.apache.commons.httpclient.methods DeleteMethod releaseConnection
@Override public void releaseConnection()
From source file:org.olat.restapi.CourseGroupMgmtTest.java
@Test public void testBasicSecurityDeleteCall() throws IOException { final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g2.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); method.releaseConnection(); assertEquals(401, code);//from w ww .ja v a2s . c om }
From source file:org.olat.restapi.UserAuthenticationMgmtTest.java
@Test public void testDeleteAuthentications() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // create an authentication token final BaseSecurity baseSecurity = BaseSecurityManager.getInstance(); final Identity adminIdent = baseSecurity.findIdentityByName("administrator"); final Authentication authentication = baseSecurity.createAndPersistAuthentication(adminIdent, "REST-A-2", "administrator", "credentials"); assertTrue(authentication != null && authentication.getKey() != null && authentication.getKey().longValue() > 0); DBFactory.getInstance().intermediateCommit(); // delete an authentication token final String request = "/users/administrator/auth/" + authentication.getKey().toString(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200);// www . j a va 2s . co m method.releaseConnection(); final Authentication refAuth = baseSecurity.findAuthentication(adminIdent, "REST-A-2"); assertNull(refAuth); }
From source file:org.olat.restapi.UserMgmtTest.java
@Test public void testDeleteUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // delete an authentication token final String request = "/users/" + id2.getKey(); final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200);/*from w ww . j av a 2 s. com*/ method.releaseConnection(); final Identity deletedIdent = BaseSecurityManager.getInstance().loadIdentityByKey(id2.getKey()); assertNotNull(deletedIdent);// Identity aren't deleted anymore assertEquals(Identity.STATUS_DELETED, deletedIdent.getStatus()); }
From source file:org.panlab.software.fci.uop.UoPGWClient.java
/** * It makes a DELETE towards the gateway * @author ctranoris//from w w w. ja v a2 s. com * @param resourceInstance sets the name of the resource Instance, e.g.: uop.rubis_db-27 * @param ptmAlias sets the name of the provider URI, e.g.: uop * @param content sets the name of the content; send in utf8 */ public void DELETEexecute(String resourceInstance, String ptmAlias, String content) { System.out.println("content body=" + "\n" + content); HttpClient client = new HttpClient(); String tgwcontent = content; // resource instance is like uop.rubis_db-6 so we need to make it like // this /uop/uop.rubis_db-6 String ptm = ptmAlias; String url = uopGWAddress + "/" + ptm + "/" + resourceInstance; System.out.println("Request: " + url); // Create a method instance. DeleteMethod delMethod = new DeleteMethod(url); delMethod.setRequestHeader("User-Agent", userAgent); delMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Provide custom retry handler is necessary // delMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, // new DefaultHttpMethodRetryHandler(3, false)); // RequestEntity requestEntity = null; // try { // requestEntity = new StringRequestEntity(tgwcontent, // "application/x-www-form-urlencoded", "utf-8"); // } catch (UnsupportedEncodingException e1) { // e1.printStackTrace(); // } //delMethod.setRequestEntity(requestEntity); try { // Execute the method. int statusCode = client.executeMethod(delMethod); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + delMethod.getStatusLine()); } // Deal with the response. // Use caution: ensure correct character encoding and is not binary // data // print the status and response InputStream responseBody = delMethod.getResponseBodyAsStream(); CopyInputStream cis = new CopyInputStream(responseBody); response_stream = cis.getCopy(); System.out.println("Response body=" + "\n" + convertStreamToString(response_stream)); response_stream.reset(); // System.out.println("for address: " + url + " the response is:\n " // + post.getResponseBodyAsString()); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. delMethod.releaseConnection(); } }
From source file:org.roda.wui.filter.CasClient.java
/** * Logout from the CAS server./*from w w w. j av a 2s . c om*/ * * @param ticketGrantingTicket * the <strong>Ticket Granting Ticket</strong>. * @throws GenericException * if some error occurred. */ public void logout(final String ticketGrantingTicket) throws GenericException { final HttpClient client = new HttpClient(); final DeleteMethod method = new DeleteMethod( String.format("%s/v1/tickets/%s", casServerUrlPrefix, ticketGrantingTicket)); try { client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Logged out"); } else { LOGGER.warn(invalidResponseMessage(method)); throw new GenericException(invalidResponseMessage(method)); } } catch (final IOException e) { throw new GenericException(e.getMessage(), e); } finally { method.releaseConnection(); } }
From source file:org.sharegov.cirm.utils.GenUtils.java
public static String httpDelete(String url, String... headers) { HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(url); if (headers != null) { if (headers.length % 2 != 0) throw new IllegalArgumentException( "Odd number of headers argument, specify HTTP headers in pairs: name then value, etc."); for (int i = 0; i < headers.length; i++) method.addRequestHeader(headers[i], headers[++i]); }//ww w . j a va 2 s . c om try { // disable retries from within the HTTP client client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) throw new RuntimeException("HTTP Error " + statusCode + " while deleting " + url.toString()); return method.getResponseBodyAsString(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { method.releaseConnection(); } }
From source file:org.sipfoundry.sipxconfig.admin.CertificateManagerImpl.java
public void deleteCA(CertificateDecorator cert) { if (isSystemGenerated(cert.getFileName())) { throw new UserException("&error.delete.default.ca", cert.getFileName()); }/*w w w. ja v a 2s .c om*/ Collection<File> files = FileUtils.listFiles(new File(m_sslAuthDirectory), SSL_CA_EXTENSIONS, false); Collection<File> filesToDelete = new ArrayList<File>(); try { for (File file : files) { if (StringUtils.equals(file.getCanonicalFile().getName(), cert.getFileName())) { filesToDelete.add(getCAFile(file.getName())); } } HttpClient httpClient = getNewHttpClient(); Location[] locations = m_locationsManager.getLocations(); for (Location curLocation : locations) { for (File file : filesToDelete) { String remoteFileName = join( new Object[] { curLocation.getHttpsServerUrl(), file.getAbsolutePath() }); DeleteMethod httpDelete = new DeleteMethod(remoteFileName); try { int statusCode = httpClient.executeMethod(httpDelete); if (statusCode != 200) { throw new UserException("&error.https.server.status.code", curLocation.getFqdn(), String.valueOf(statusCode)); } } catch (HttpException ex) { throw new UserException("&error.https.server", curLocation.getFqdn(), ex.getMessage()); } finally { httpDelete.releaseConnection(); } } } } catch (IOException ex) { throw new UserException("&error.delete.cert"); } }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.server.WsmoLiteDataServiceImpl.java
@Override public boolean deleteRepositoryFile(String fullRequestUrl) throws Exception { DeleteMethod deleteMtd = new DeleteMethod(fullRequestUrl); HttpClient httpclient = new HttpClient(); try {/*from w ww.j a v a 2 s. co m*/ int result = httpclient.executeMethod(deleteMtd); if (result != 200) { deleteMtd.releaseConnection(); throw new Exception("Error " + result + ": " + deleteMtd.getResponseHeader("Error")); } } finally { deleteMtd.releaseConnection(); } return true; }
From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java
@Override public void deleteItem(ProxyRepository repository, ResourceStoreRequest request) throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException { URL remoteURL = getAbsoluteUrlFromBase(repository, request); DeleteMethod method = new DeleteMethod(remoteURL.toString()); try {/*from ww w .j a v a 2s .c o m*/ int response = executeMethod(repository, request, method, remoteURL); if (response != HttpStatus.SC_OK && response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED) { throw new RemoteStorageException("The response to HTTP " + method.getName() + " was unexpected HTTP Code " + response + " : " + HttpStatus.getStatusText(response) + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]"); } } finally { method.releaseConnection(); } }
From source file:org.sonatype.nexus.restlight.common.AbstractRESTLightClient.java
/** * <p>//from w w w. j a v a 2 s .c o m * Low-level DELETE implementation. * </p> * <p> * Submit a DELETE request to the URL given (absolute or relative-to-base-URL depends on urlIsAbsolute flag), and * parse the response as an XML {@link Document} (JDOM) instance <b>if</b> expectResponseBody == true. Use the given * requestParams map to inject into the HTTP DELETE method. * </p> */ protected Document doDelete(final String url, final Map<String, ? extends Object> requestParams, final boolean urlIsAbsolute, final boolean expectResponseBody) throws RESTLightClientException { DeleteMethod method = urlIsAbsolute ? new DeleteMethod(url) : new DeleteMethod(baseUrl + url); addRequestParams(method, requestParams); try { client.executeMethod(method); } catch (HttpException e) { throw new RESTLightClientException("DELETE request execution failed. Reason: " + e.getMessage(), e); } catch (IOException e) { throw new RESTLightClientException("DELETE request execution failed. Reason: " + e.getMessage(), e); } int status = method.getStatusCode(); String statusText = method.getStatusText(); if (status != 200) { throw new RESTLightClientException("DELETE request failed; HTTP status: " + status + ": " + statusText); } if (expectResponseBody) { try { return new SAXBuilder().build(method.getResponseBodyAsStream()); } catch (JDOMException e) { throw new RESTLightClientException("Failed to parse response body as XML for DELETE request.", e); } catch (IOException e) { throw new RESTLightClientException("Could not retrieve body as a String from DELETE request.", e); } finally { method.releaseConnection(); } } else { method.releaseConnection(); return null; } }