List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
From source file:org.eclipse.winery.highlevelrestapi.HighLevelRestApi.java
/** * This method implements the HTTP Delete Method * /* ww w . j av a 2s .c o m*/ * @param uri Resource URI * @return ResponseCode of HTTP Interaction */ public static HttpResponseMessage Delete(String uri, String acceptHeaderValue) { DeleteMethod method = new DeleteMethod(uri); HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); HighLevelRestApi.cleanResponseBody(responseMessage); return responseMessage; }
From source file:org.eclipsecon.e4rover.client.production.ProductionServer.java
public void leavePlayerQueue(String playerKey) throws IOException { DeleteMethod delete = new DeleteMethod(IServerConstants.QUEUE_RESTLET + "/" + playerKey); try {/*from w w w . j ava 2 s . co m*/ int resp = httpClient.executeMethod(delete); if (resp != HttpStatus.SC_OK) { throw new RobotServerException(resp, delete.getURI(), delete.getResponseBodyAsString()); } } finally { delete.releaseConnection(); } }
From source file:org.elasticsearch.hadoop.rest.RestClient.java
public void deleteIndex(String index) { execute(new DeleteMethod(index)); }
From source file:org.entando.entando.plugins.jpoauthclient.aps.system.httpclient.OAuthHttpClient.java
@Override public HttpResponseMessage execute(HttpMessage request, Map<String, Object> parameters) throws IOException { final String method = request.method; final String url = request.url.toExternalForm(); final InputStream body = request.getBody(); final boolean isDelete = DELETE.equalsIgnoreCase(method); final boolean isPost = POST.equalsIgnoreCase(method); final boolean isPut = PUT.equalsIgnoreCase(method); byte[] excerpt = null; HttpMethod httpMethod;/* ww w .ja va 2 s .c o m*/ if (isPost || isPut) { EntityEnclosingMethod entityEnclosingMethod = isPost ? new PostMethod(url) : new PutMethod(url); if (body != null) { ExcerptInputStream e = new ExcerptInputStream(body); String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH); entityEnclosingMethod.setRequestEntity((length == null) ? new InputStreamRequestEntity(e) : new InputStreamRequestEntity(e, Long.parseLong(length))); excerpt = e.getExcerpt(); } httpMethod = entityEnclosingMethod; } else if (isDelete) { httpMethod = new DeleteMethod(url); } else { httpMethod = new GetMethod(url); } for (Map.Entry<String, Object> p : parameters.entrySet()) { String name = p.getKey(); String value = p.getValue().toString(); if (FOLLOW_REDIRECTS.equals(name)) { httpMethod.setFollowRedirects(Boolean.parseBoolean(value)); } else if (READ_TIMEOUT.equals(name)) { httpMethod.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(value)); } } for (Map.Entry<String, String> header : request.headers) { httpMethod.addRequestHeader(header.getKey(), header.getValue()); } HttpClient client = this._clientPool.getHttpClient(new URL(httpMethod.getURI().toString())); client.executeMethod(httpMethod); return new HttpMethodResponse(httpMethod, excerpt, request.getContentCharset()); }
From source file:org.entando.entando.plugins.jpoauthclient.aps.system.services.client.ProviderConnectionManager.java
private String invokeGetDeleteMethod(String url, boolean isGet, Properties parameters) throws Throwable { String result = null;//from ww w . j a va2 s. co m HttpMethodBase method = null; InputStream inputStream = null; try { HttpClient client = new HttpClient(); if (isGet) { method = new GetMethod(url); } else { method = new DeleteMethod(url); } this.addQueryString(method, parameters); client.executeMethod(method); inputStream = method.getResponseBodyAsStream(); result = IOUtils.toString(inputStream, "UTF-8"); //byte[] responseBody = method.getResponseBody(); //result = new String(responseBody); } catch (Throwable t) { _logger.error("Error invoking Get or Delete Method", t); } finally { if (null != inputStream) { inputStream.close(); } if (null != method) { method.releaseConnection(); } } return result; }
From source file:org.exist.xquery.modules.httpclient.DELETEFunction.java
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { Sequence response = null;/* w w w. j a va2 s. com*/ // must be a URL if (args[0].isEmpty()) { return (Sequence.EMPTY_SEQUENCE); } //get the url String url = args[0].itemAt(0).getStringValue(); //get the persist state boolean persistState = args[1].effectiveBooleanValue(); //setup DELETE request DeleteMethod delete = new DeleteMethod(url); //setup DELETE Request Headers if (!args[2].isEmpty()) { setHeaders(delete, ((NodeValue) args[2].itemAt(0)).getNode()); } try { //execute the request response = doRequest(context, delete, persistState, null, null); } catch (IOException ioe) { throw (new XPathException(this, ioe.getMessage(), ioe)); } finally { delete.releaseConnection(); } return (response); }
From source file:org.fao.geonet.services.publisher.GeoServerRest.java
/** * //www .j a v a 2 s. co m * @param method * e.g. 'POST', 'GET', 'PUT' or 'DELETE' * @param urlParams * REST API parameter * @param postData * XML data * @param file * File to upload * @param contentType * type of content in case of post data or file updload. * @param saveResponse * @return * @throws IOException */ public int sendREST(String method, String urlParams, String postData, File file, String contentType, Boolean saveResponse) throws IOException { response = ""; final HttpClient c = httpClientFactory.newHttpClient(); String url = this.restUrl + urlParams; if (Log.isDebugEnabled(LOGGER_NAME)) { Log.debug(LOGGER_NAME, "url:" + url); Log.debug(LOGGER_NAME, "method:" + method); Log.debug(LOGGER_NAME, "postData:" + postData); } HttpMethod m; if (method.equals(METHOD_PUT)) { m = new PutMethod(url); if (file != null) { ((PutMethod) m).setRequestEntity(new InputStreamRequestEntity(new FileInputStream(file))); } if (postData != null) { ((PutMethod) m).setRequestEntity(new StringRequestEntity(postData, contentType, "UTF-8")); } } else if (method.equals(METHOD_DELETE)) { m = new DeleteMethod(url); } else if (method.equals(METHOD_POST)) { m = new PostMethod(url); if (postData != null) { ((PostMethod) m).setRequestEntity(new StringRequestEntity(postData, contentType, "UTF-8")); } } else { m = new GetMethod(url); } if (contentType != null && !"".equals(contentType)) { m.setRequestHeader("Content-type", contentType); } m.setDoAuthentication(true); status = c.executeMethod(m); if (Log.isDebugEnabled(LOGGER_NAME)) Log.debug(LOGGER_NAME, "status:" + status); if (saveResponse) this.response = m.getResponseBodyAsString(); return status; }
From source file:org.geosdi.geoplatform.publish.HttpUtilsLocal.java
public static boolean delete(String url, final String user, final String pw) { DeleteMethod httpMethod = null;//from w w w . ja va 2 s. c om try { 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; }
From source file:org.geotools.data.couchdb.client.CouchDBClient.java
/** * Send a DELETE request to the given relative path * @param path relative path//from w w w. j av a 2s . co m * @return CouchDBResponse * @throws IOException if an error in communication occurs */ public CouchDBResponse delete(String path) throws IOException { DeleteMethod delete = new DeleteMethod(url(path)); return executeMethod(delete); }
From source file:org.iavante.sling.commons.services.DistributionServerTestIT.java
private void deleteContent(String content) { // Delete the content DeleteMethod post_delete = new DeleteMethod(content); post_delete.setDoAuthentication(true); // post_delete.setRequestBody(data_delete); try {//from w w w. ja v a 2s . c o m client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } System.out.println(post_delete.getStatusCode()); assert 204 == post_delete.getStatusCode(); System.out.println("Borrado contenido: " + content); post_delete.releaseConnection(); }