List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:com.cordys.coe.ac.httpconnector.impl.StandardRequestHandler.java
/** * @see IRequestHandler#process(int, IServerConnection, HttpClient) *///ww w . j av a 2s . c om @Override public HttpMethod process(int requestNode, IServerConnection connection, HttpClient httpClient) throws HandlerException { String uri = getRequestUri(requestNode, connection, httpClient); EntityEnclosingMethod httpMethod; if (LOG.isDebugEnabled()) { LOG.debug("HTTP method is: " + m_method.getHttpMethodType()); } switch (m_method.getHttpMethodType()) { case GET: HttpMethod httpMethodGet = new GetMethod(uri); // Get method does not have a body. setRequestHeaders(httpMethodGet); return httpMethodGet; case POST: httpMethod = new PostMethod(uri); break; case PUT: httpMethod = new PutMethod(uri); break; case DELETE: HttpMethod httpMethodDelete = new DeleteMethod(uri); // Delete method does not have a body. setRequestHeaders(httpMethodDelete); return httpMethodDelete; default: throw new HandlerException(HandlerExceptionMessages.UNKNOWN_HTTP_METHOD); } int reqNode = requestNode; try { reqNode = preProcessXml(reqNode, reqNode != requestNode); if (xsltNode != 0) { reqNode = executeXslt(reqNode, m_method, reqNode != requestNode); } if (m_requestRootXPath != null) { reqNode = handleRequestXPath(reqNode, m_method, reqNode != requestNode); } if ((m_removeNamespaceUriSet != null) || m_removeAllNamespaces) { XmlUtils.removeNamespacesRecursively(reqNode, m_removeNamespaceUriSet); } reqNode = postProcessXml(reqNode, reqNode != requestNode); if (LOG.isDebugEnabled()) { LOG.debug("Final Request XML: " + Node.writeToString(reqNode, true)); } // Get the data that should be posted. byte[] reqData = getPostData(reqNode, connection); String contentType = getContentType(); httpMethod.setRequestEntity(new ByteArrayRequestEntity(reqData, contentType)); if (LOG.isDebugEnabled()) { LOG.debug("Sending data: " + new String(reqData)); } httpMethod.setRequestHeader("Content-type", contentType); setRequestHeaders(httpMethod); } finally { if ((reqNode != 0) && (reqNode != requestNode)) { Node.delete(reqNode); reqNode = 0; } } return httpMethod; }
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 w w w.j a v a2s.co 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:edu.htwm.vsp.phoebook.rest.client.RestClient.java
public void verifyDeleteUser(String userID, int expectedStatusCode) throws IOException { System.out.println("Deleting User: " + userID + " ...\n"); HttpClient client = new HttpClient(); // -- build HTTP DELETE request DeleteMethod method = new DeleteMethod(getServiceBaseURI() + "/users" + "/" + userID); int responseCode = client.executeMethod(method); assertEquals(expectedStatusCode, responseCode); }
From source file:com.tribune.uiautomation.testscripts.Photo.java
private boolean delete(String namespaceParam, String slugParam) { checkValidStateForDelete();//from w ww .j a v a 2s . c om 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:com.buglabs.dragonfly.util.WSHelper.java
protected static String delete(String url) throws HttpException, IOException { HttpClient c = new HttpClient(); DeleteMethod delete = new DeleteMethod(url); int response = c.executeMethod(delete); if (response >= 400) throw new HttpException("Unable to complete delete operation with HTTP error code " + response + "."); return delete.getResponseBodyAsString(); }
From source file:com.orange.mmp.net.http.HttpConnection.java
/** * Inner method used to execute request//from w ww.jav a 2 s. c o m * * @param dataStream The data stream to send in request (null for GET only) * @throws MMPNetException */ @SuppressWarnings("unchecked") protected void doExecute(InputStream dataStream) throws MMPNetException { try { this.currentHttpClient = HttpConnectionManager.httpClientPool.take(); } catch (InterruptedException ie) { throw new MMPNetException("Corrupted HTTP client pool", ie); } if (this.httpConnectionProperties.containsKey(HttpConnectionParameters.PARAM_IN_CREDENTIALS_USER)) { this.currentHttpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( (String) this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_CREDENTIALS_USER), (String) this.httpConnectionProperties .get(HttpConnectionParameters.PARAM_IN_CREDENTIALS_PASSWORD))); this.currentHttpClient.getParams().setAuthenticationPreemptive(true); } // Config HostConfiguration config = new HostConfiguration(); if (this.timeout > 0) this.currentHttpClient.getParams().setParameter(HttpConnectionParameters.PARAM_IN_HTTP_SOCKET_TIMEOUT, this.timeout); if (HttpConnectionManager.proxyHost != null && (this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) != null && this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) .toString().equals("true")) || (this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) == null && this.useProxy)) { config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort); } else { config.setProxyHost(null); } this.currentHttpClient.setHostConfiguration(config); this.currentHttpClient.getHostConfiguration().setHost(new HttpHost(this.endPointUrl.getHost())); String methodStr = (String) this.httpConnectionProperties .get(HttpConnectionParameters.PARAM_IN_HTTP_METHOD); if (methodStr == null || methodStr.equals(HttpConnectionParameters.HTTP_METHOD_GET)) { this.method = new GetMethod(endPointUrl.toString().replace(" ", "+")); } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_POST)) { this.method = new PostMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); if (dataStream != null) { InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(dataStream); ((PostMethod) this.method).setRequestEntity(inputStreamRequestEntity); } } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_PUT)) { this.method = new PutMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); if (dataStream != null) { InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(dataStream); ((PutMethod) this.method).setRequestEntity(inputStreamRequestEntity); } } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_DEL)) { this.method = new DeleteMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); } else throw new MMPNetException("HTTP method not supported"); //Add headers if (this.httpConnectionProperties != null) { for (Object headerName : this.httpConnectionProperties.keySet()) { if (!((String) headerName).startsWith("http.")) { this.method.addRequestHeader((String) headerName, this.httpConnectionProperties.get(headerName).toString()); } } } // Set Connection/Proxy-Connection close to avoid TIME_WAIT sockets this.method.addRequestHeader("Connection", "close"); this.method.addRequestHeader("Proxy-Connection", "close"); try { int httpCode = this.currentHttpClient.executeMethod(config, method); this.currentStatusCode = httpCode; for (org.apache.commons.httpclient.Header responseHeader : method.getResponseHeaders()) { this.httpConnectionProperties.put(responseHeader.getName(), responseHeader.getValue()); } if (this.currentStatusCode >= 400) { throw new MMPNetException("HTTP " + this.currentStatusCode + " on '" + endPointUrl + "'"); } else { this.inDataStream = this.method.getResponseBodyAsStream(); } } catch (IOException ioe) { throw new MMPNetException("I/O error on " + this.endPointUrl + " : " + ioe.getMessage()); } catch (Exception e) { e.printStackTrace(); } }
From source file:gr.upatras.ece.nam.fci.uop.UoPGWClient.java
/** * It makes a DELETE towards the gateway * @author ctranoris//from w ww .jav a2s . c o m * @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) { log.info("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; log.info("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(); log.info("Response body=" + "\n" + convertStreamToString(response_stream)); response_stream.reset(); // log.info("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:gr.upatras.ece.nam.fci.panlab.PanlabGWClient.java
/** * It makes a DELETE towards the gateway * @author ctranoris// w ww. jav a 2 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 = panlabGWAddress + "/" + 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:com.atlantbh.jmeter.plugins.oauth.OAuthSampler.java
private HttpMethodBase createHttpMethod(String method, String urlStr) { HttpMethodBase httpMethod;// w ww . j ava 2 s .co m // May generate IllegalArgumentException if (method.equals(POST)) { httpMethod = new PostMethod(urlStr); } else if (method.equals(PUT)) { httpMethod = new PutMethod(urlStr); } else if (method.equals(HEAD)) { httpMethod = new HeadMethod(urlStr); } else if (method.equals(TRACE)) { httpMethod = new TraceMethod(urlStr); } else if (method.equals(OPTIONS)) { httpMethod = new OptionsMethod(urlStr); } else if (method.equals(DELETE)) { httpMethod = new DeleteMethod(urlStr); } else if (method.equals(GET)) { httpMethod = new GetMethod(urlStr); } else { log.error("Unexpected method (converted to GET): " + method); httpMethod = new GetMethod(urlStr); } return httpMethod; }
From source file:edu.stanford.epad.epadws.xnat.XNATDeletionOperations.java
public static int deleteXNATProject(String xnatProjectLabelOrID, String jsessionID) { String xnatProjectDeleteURL = XNATUtil.buildXNATProjectDeletionURL(xnatProjectLabelOrID); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod(xnatProjectDeleteURL); int xnatStatusCode; method.setRequestHeader("Cookie", "JSESSIONID=" + jsessionID); try {/*from www. jav a2s. co m*/ log.info("Invoking XNAT with URL " + xnatProjectDeleteURL); xnatStatusCode = client.executeMethod(method); if (unexpectedDeletionStatusCode(xnatStatusCode)) log.warning("Failure calling XNAT to delete project; status code = " + xnatStatusCode); else { eventTracker.recordProjectEvent(jsessionID, xnatProjectLabelOrID); } } catch (IOException e) { log.warning("Error calling XNAT to delete for project " + xnatProjectLabelOrID, e); xnatStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } finally { method.releaseConnection(); } return xnatStatusCode; }