List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getStatusText
@Override
public String getStatusText()
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 w w.j av a 2 s .c o m 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:it.geosolutions.figis.requester.HTTPUtils.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; try {/*from ww w . ja 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:it.geosolutions.geoserver.rest.HTTPUtils.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; HttpClient client = new HttpClient(); HttpConnectionManager connectionManager = client.getHttpConnectionManager(); try {/*from w w w .ja va 2s . c o m*/ setAuth(client, url, user, pw); httpMethod = new DeleteMethod(url); connectionManager.getParams().setConnectionTimeout(5000); int status = client.executeMethod(httpMethod); String response = ""; if (status == HttpStatus.SC_OK) { InputStream is = httpMethod.getResponseBodyAsStream(); response = IOUtils.toString(is); IOUtils.closeQuietly(is); if (response.trim().equals("")) { if (LOGGER.isTraceEnabled()) LOGGER.trace( "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 { LOGGER.info("(" + status + ") " + 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(); connectionManager.closeIdleConnections(0); } return false; }
From source file:com.zimbra.cs.store.http.HttpStoreManager.java
@Override public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator)); try {// ww w . j a v a2 s. c om int statusCode = HttpClientUtil.executeMethod(client, delete); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) { return true; } else if (statusCode == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText()); } } finally { delete.releaseConnection(); } }
From source file:com.zimbra.cs.store.triton.TritonBlobStoreManager.java
@Override public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); DeleteMethod delete = new DeleteMethod(blobApiUrl + locator); delete.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString()); try {/*from www. j a va 2 s . c o m*/ ZimbraLog.store.info("deleting %s", delete.getURI()); int statusCode = HttpClientUtil.executeMethod(client, delete); if (statusCode == HttpStatus.SC_OK) { return true; } else { throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText()); } } finally { delete.releaseConnection(); } }
From source file:it.geosolutions.geonetwork.util.HTTPUtils.java
public boolean delete(String url) { DeleteMethod httpMethod = null; try {/*w w w . j a v a 2 s.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; }
From source file:org.apache.sling.discovery.impl.topology.connector.TopologyConnectorClient.java
/** Disconnect this connector **/ public void disconnect() { final String uri = connectorUrl.toString() + "." + clusterViewService.getSlingId() + ".json"; if (logger.isDebugEnabled()) { logger.debug("disconnect: connectorUrl=" + connectorUrl + ", complete uri=" + uri); }// ww w. j a v a2s.c o m if (lastInheritedAnnouncement != null) { announcementRegistry.unregisterAnnouncement(lastInheritedAnnouncement.getOwnerId()); } HttpClient httpClient = new HttpClient(); final DeleteMethod method = new DeleteMethod(uri); try { String userInfo = connectorUrl.getUserInfo(); if (userInfo != null) { Credentials c = new UsernamePasswordCredentials(userInfo); httpClient.getState() .setCredentials(new AuthScope(method.getURI().getHost(), method.getURI().getPort()), c); } requestValidator.trustMessage(method, null); httpClient.executeMethod(method); if (logger.isDebugEnabled()) { logger.debug("disconnect: done. code=" + method.getStatusCode() + " - " + method.getStatusText()); } // ignoring the actual statuscode though as there's little we can // do about it after this point } catch (URIException e) { logger.warn("disconnect: Got URIException: " + e); } catch (IOException e) { logger.warn("disconnect: got IOException: " + e); } catch (RuntimeException re) { logger.error("disconnect: got RuntimeException: " + re, re); } finally { method.releaseConnection(); } }
From source file:org.apache.zeppelin.rest.AbstractTestRestApi.java
protected static DeleteMethod httpDelete(String path) throws IOException { LOG.info("Connecting to {}", url + path); HttpClient httpClient = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(url + path); deleteMethod.addRequestHeader("Origin", url); httpClient.executeMethod(deleteMethod); LOG.info("{} - {}", deleteMethod.getStatusCode(), deleteMethod.getStatusText()); return deleteMethod; }
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;/*w ww . j a v a 2s . c om*/ 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.geosdi.geoplatform.publish.HttpUtilsLocal.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null; try {/*from w w w.ja va 2 s . c o 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 { LOGGER.info("(" + status + ") " + 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; }