List of usage examples for org.apache.commons.httpclient.methods DeleteMethod releaseConnection
@Override public void releaseConnection()
From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java
/** * @see {@link GraphRepository#delete(String, QueryLanguage)} *//*from ww w. j av a2 s.co m*/ public void delete(String query, QueryLanguage ql) throws Exception { if (query == null || ql == null) { return; } // DELETE DeleteMethod del = new DeleteMethod(servletURL); try { // add the header for the query if (query != null) { query = ql.toString().toLowerCase() + "[" + trim(query) + "]"; String rangeHeader = "query[" + query + "]"; Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, rangeHeader); del.addRequestHeader(range); } // Execute the method. int sc = getHttpClient().executeMethod(del); if (sc != HttpStatus.SC_OK) { throw new IOException("HTTP-DELETE failed: " + del.getStatusLine()); } } finally { // Release the connection. del.releaseConnection(); } }
From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java
@Override public void removeCurrency(String currencyCode) { String resource = String.format(baseUrl + CURRENCY, currencyCode); DeleteMethod method = createDeleteMethod(resource); try {/*from w ww . ja v a 2 s . co m*/ // Execute the method. int statusCode = getClient().executeMethod(method); if (statusCode == HttpStatus.SC_NOT_FOUND) { return; } assertResponseCodeOK(method, statusCode); } catch (Exception e) { throw new RuntimeException("Failed removing currency via url " + resource, e); } finally { method.releaseConnection(); } }
From source file:com.tribune.uiautomation.testscripts.Photo.java
private boolean delete(String namespaceParam, String slugParam) { checkValidStateForDelete();//from w w w.j av a2 s . c o m DeleteMethod delete = new DeleteMethod(constructResourceUrl(namespaceParam, slugParam)); try { setRequestHeaders(delete); HttpClient client = new HttpClient(); int status = client.executeMethod(delete); log.debug("Photo Service delete return status: " + delete.getStatusLine()); if (status == HttpStatus.SC_OK) { return true; } } catch (HttpException e) { log.fatal("Fatal protocol violation: " + e.getMessage(), e); } catch (IOException e) { log.fatal("Fatal transport error: " + e.getMessage(), e); } finally { // Release the connection. delete.releaseConnection(); } return false; }
From source file:it.geosolutions.figis.requester.HTTPUtils.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; try {/*www. j a v a 2 s . co m*/ HttpClient client = new HttpClient(); setAuth(client, url, user, pw); httpMethod = new DeleteMethod(url); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(httpMethod); String response = ""; if (status == HttpStatus.SC_OK) { InputStream is = httpMethod.getResponseBodyAsStream(); response = IOUtils.toString(is); if (response.trim().equals("")) // sometimes gs rest fails { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ResponseBody is empty (this may be not an error since we just performed a DELETE call)"); } return true; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); } return true; } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("(" + status + ") " + httpMethod.getStatusText() + " -- " + url); LOGGER.info("Response: '" + response + "'"); } } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]", e); } catch (IOException e) { LOGGER.info("Error talking to [" + url + "]", e); } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } return false; }
From source file:com.intuit.tank.http.BaseRequest.java
/** * Execute the delete request./*from w w w . j a v a 2 s .c om*/ * * @param response * The response object to populate */ public void doDelete(BaseResponse response) { DeleteMethod httpdelete = null; try { URL url = BaseRequestHandler.buildUrl(protocol, host, port, path, urlVariables); httpdelete = new DeleteMethod(url.toString()); String requestBody = this.getBody(); // Multiple calls can be // expensive, so get it once String type = headerInformation.get("Content-Type"); if (StringUtils.isBlank(type)) { headerInformation.put("Content-Type", "application/x-www-form-urlencoded"); } sendRequest(response, httpdelete, requestBody); } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (null != httpdelete) httpdelete.releaseConnection(); } }
From source file:com.funambol.json.dao.JsonDAOImpl.java
public JsonResponse removeItem(String token, String id, long since) throws HttpException, IOException { String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL) + Utility.URL_SEP + id; if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: start removeItem with id:" + id + "and since=" + since); }/* w w w . j a v a 2 s . c om*/ DeleteMethod remove = new DeleteMethod(request); if (since != 0) { NameValuePair nvp_since = new NameValuePair(); nvp_since.setName("since"); nvp_since.setValue("" + since); NameValuePair[] nvp = { nvp_since }; remove.setQueryString(nvp); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: removeItem request:" + request); } remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token); int statusCode = 0; String responseBody = null; try { statusCode = httpClient.executeMethod(remove); responseBody = remove.getResponseBodyAsString(); } finally { remove.releaseConnection(); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: deleteItem response " + responseBody); log.trace("JsonDAOImpl: item with id:" + id + " removed"); } JsonResponse response = new JsonResponse(statusCode, responseBody); return response; }
From source file:com.funambol.json.dao.JsonDAOImpl.java
public JsonResponse removeAllItems(String token, long since) throws HttpException, IOException { String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL); if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: start removeAllItems"); }//w w w. j a v a 2s. c o m DeleteMethod remove = new DeleteMethod(request); if (since != 0) { NameValuePair nvp_since = new NameValuePair(); nvp_since.setName("since"); nvp_since.setValue("" + since); NameValuePair[] nvp = { nvp_since }; remove.setQueryString(nvp); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: removeAllItem request:" + request); } remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token); int statusCode = 0; String responseBody = null; try { statusCode = httpClient.executeMethod(remove); responseBody = remove.getResponseBodyAsString(); } finally { remove.releaseConnection(); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: deleteAllItem response " + responseBody); } JsonResponse response = new JsonResponse(statusCode, responseBody); return response; }
From source file:com.sun.faban.driver.transport.hc3.ApacheHC3Transport.java
/** * Makes a DELETE request to the URL. Reads data back and returns the data * read. Note that this method only works with text data as it does the * byte-to-char conversion. This method will return null for responses * with binary MIME types. The addTextType(String) method is used to * register additional MIME types as text types. Use getContentSize() to * obtain the bytes of binary data read. * * @param url The URL to read from/* www .j a va 2 s . c o m*/ * @param headers The request headers, or null * @return The StringBuilder buffer containing the resulting document * @throws java.io.IOException */ public StringBuilder deleteURL(String url, Map<String, String> headers) throws IOException { DeleteMethod method = new DeleteMethod(url); method.setFollowRedirects(followRedirects); setHeaders(method, headers); try { responseCode = hc.executeMethod(method); buildResponseHeaders(method); return fetchResponse(method); } finally { method.releaseConnection(); } }
From source file:edu.indiana.d2i.registryext.RegistryExtAgent.java
/** * delete a single resource//from www . j a v a2 s.c o m * * @param repoPath * path in registry * @throws HttpException * @throws IOException * @throws RegistryExtException * @throws OAuthSystemException * @throws OAuthProblemException */ public void deleteResource(String repoPath) throws HttpException, IOException, RegistryExtException, OAuthSystemException, OAuthProblemException { Map<String, Object> session = ActionContext.getContext().getSession(); int statusCode = 200; String accessToken = (String) session.get(Constants.SESSION_TOKEN); String requestURL = composeURL(FILEOPPREFIX, repoPath); if (logger.isDebugEnabled()) { logger.debug("Deletion request URL=" + requestURL); } HttpClient httpclient = new HttpClient(); DeleteMethod delete = new DeleteMethod(requestURL); delete.addRequestHeader("Authorization", "Bearer " + accessToken); try { httpclient.executeMethod(delete); statusCode = delete.getStatusLine().getStatusCode(); /* handle token expiration */ if (statusCode == 401) { logger.info(String.format("Access token %s expired, going to refresh it", accessToken)); refreshToken(session); // use refreshed access token accessToken = (String) session.get(Constants.SESSION_TOKEN); delete.addRequestHeader("Authorization", "Bearer " + accessToken); // re-send the request httpclient.executeMethod(delete); statusCode = delete.getStatusLine().getStatusCode(); } if (statusCode != 204) { throw new RegistryExtException( "Failed in delete resource : HTTP error code : " + delete.getStatusLine().getStatusCode()); } } finally { if (delete != null) delete.releaseConnection(); } }
From source file:it.geosolutions.geonetwork.util.HTTPUtils.java
public boolean delete(String url) { DeleteMethod httpMethod = null; try {//from ww w. java2s .co m // HttpClient client = new HttpClient(); setAuth(client, url, username, pw); httpMethod = new DeleteMethod(url); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); lastHttpStatus = client.executeMethod(httpMethod); String response = ""; if (lastHttpStatus == HttpStatus.SC_OK) { if (LOGGER.isDebugEnabled()) LOGGER.debug("(" + lastHttpStatus + ") " + httpMethod.getStatusText() + " -- " + url); if (!ignoreResponseContentOnSuccess) { InputStream is = httpMethod.getResponseBodyAsStream(); response = IOUtils.toString(is); if (response.trim().equals("")) { if (LOGGER.isDebugEnabled()) LOGGER.debug( "ResponseBody is empty (this may be not an error since we just performed a DELETE call)"); } } return true; } else { LOGGER.info("(" + lastHttpStatus + ") " + httpMethod.getStatusText() + " -- " + url); LOGGER.info("Response: '" + response + "'"); } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); } catch (IOException e) { LOGGER.info("Error talking to [" + url + "]", e); } finally { if (httpMethod != null) httpMethod.releaseConnection(); } return false; }