List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:org.eclipse.lyo.testsuite.server.util.OSLCUtils.java
public static HttpResponse deleteFromUrl(String url, Credentials creds, String acceptTypes) throws IOException { getHttpClient(creds);/* ww w .j a v a 2s .c o m*/ //Create the post and add headers HttpDelete httpdelete = new HttpDelete(url); if (acceptTypes != null && !acceptTypes.isEmpty()) httpdelete.addHeader("Accept", acceptTypes); //Send the request and return the response HttpResponse resp = httpclient.execute(httpdelete, new BasicHttpContext()); return resp; }
From source file:com.linkedin.multitenant.db.RocksdbDatabase.java
@Override public DatabaseResult doDelete(Query q) { HttpDelete delete = new HttpDelete(m_connStr + q.getKey()); try {//from w w w .j a v a 2 s . c o m String responseBody = m_client.execute(delete, m_handler); m_log.debug("Delete response: " + responseBody); return DatabaseResult.OK; } catch (Exception e) { m_log.error("Error in executing doDelete", e); return DatabaseResult.FAIL; } }
From source file:org.expath.httpclient.impl.ApacheHttpConnection.java
public void setRequestMethod(String method, boolean with_content) throws HttpClientException { if (LOG.isInfoEnabled()) { LOG.debug("Request method: " + method + " (" + with_content + ")"); }/*w w w. j av a 2 s .c o m*/ String uri = myUri.toString(); String m = method.toUpperCase(); if ("DELETE".equals(m)) { myRequest = new HttpDelete(uri); } else if ("GET".equals(m)) { myRequest = new HttpGet(uri); } else if ("HEAD".equals(m)) { myRequest = new HttpHead(uri); } else if ("OPTIONS".equals(m)) { myRequest = new HttpOptions(uri); } else if ("POST".equals(m)) { myRequest = new HttpPost(uri); } else if ("PUT".equals(m)) { myRequest = new HttpPut(uri); } else if ("TRACE".equals(m)) { myRequest = new HttpTrace(uri); } else if (!checkMethodName(method)) { throw new HttpClientException("Invalid HTTP method name [" + method + "]"); } else if (with_content) { myRequest = new AnyEntityMethod(m, uri); } else { myRequest = new AnyEmptyMethod(m, uri); } }
From source file:org.hl7.fhir.client.ClientUtils.java
public static boolean issueDeleteRequest(URI resourceUri, HttpHost proxy) { HttpDelete deleteRequest = new HttpDelete(resourceUri); HttpResponse response = sendRequest(deleteRequest, proxy); int responseStatusCode = response.getStatusLine().getStatusCode(); boolean deletionSuccessful = false; if (responseStatusCode == HttpStatus.SC_NO_CONTENT) { deletionSuccessful = true;/*from w ww .ja v a 2 s . c o m*/ } return deletionSuccessful; }
From source file:com.srotya.tau.ui.rules.RulesManager.java
public void deleteRules(UserBean ub, String tenantId) throws Exception { try {/*from ww w . j ava 2 s . c om*/ CloseableHttpClient client = Utils.buildClient(am.getBaseUrl(), am.getConnectTimeout(), am.getRequestTimeout()); HttpDelete delete = new HttpDelete(am.getBaseUrl() + RULES_URL + "/" + tenantId); if (am.isEnableAuth()) { delete.addHeader(BapiLoginDAO.X_SUBJECT_TOKEN, ub.getToken()); delete.addHeader(BapiLoginDAO.HMAC, ub.getHmac()); } CloseableHttpResponse resp = client.execute(delete); if (!Utils.validateStatus(resp)) { throw new Exception("status code:" + resp.getStatusLine().getStatusCode()); } } catch (Exception e) { logger.log(Level.SEVERE, "Failed to delete all rules:" + tenantId, e); throw e; } }
From source file:com.comcast.csv.drivethru.api.HTTPRequestManager.java
/** * Create the HTTP Method.//www.j a va2 s .c om * @return the method */ private HttpUriRequest createMethod() { HttpUriRequest request = null; switch (mMethod) { case GET: request = new HttpGet(mUrl); break; case POST: request = new HttpPost(mUrl); break; case PATCH: request = new HttpPatch(mUrl); break; case OPTIONS: request = new HttpOptions(mUrl); break; case DELETE: request = new HttpDelete(mUrl); break; case PUT: request = new HttpPut(mUrl); break; case HEAD: request = new HttpHead(mUrl); break; case TRACE: request = new HttpTrace(mUrl); break; default: throw new UnsupportedOperationException("Unknown method: " + mMethod.toString()); } return request; }
From source file:org.thevortex.lighting.jinks.client.WinkClient.java
public JsonNode doDelete(String deleteUri) throws IOException { return execute(new HttpDelete(deleteUri), null); }
From source file:ch.cyberduck.core.onedrive.OneDriveCommonsHttpRequestExecutor.java
@Override public Response doDelete(final URL url, final Set<RequestHeader> headers) throws IOException { final HttpDelete request = new HttpDelete(url.toString()); for (RequestHeader header : headers) { if (header.getKey().equals(HTTP.TRANSFER_ENCODING)) { continue; }//from w ww . java2 s . com if (header.getKey().equals(HTTP.CONTENT_LEN)) { continue; } request.addHeader(new BasicHeader(header.getKey(), header.getValue())); } final CloseableHttpResponse response = client.execute(request); return new CommonsHttpResponse(response); }
From source file:de.retresco.shift.ShiftClient.java
/** * Remove an existing article from SHIFT. * * @param articleId The article ID to remove * @return {@code true} if successful, {@code false} otherwise. * @throws ShiftClientException//w w w. j a v a 2s .c om */ public boolean removeArticleById(final String articleId) throws ShiftClientException { final HttpDelete delete = new HttpDelete(this.articleUrl + articleId); final HttpResponse response = executeRequest(delete); return response.getStatusLine().getStatusCode() == 204; }
From source file:com.streamreduce.util.HTTPUtils.java
/** * Opens a connection to the specified URL with the supplied username and password, * if supplied, and then reads the contents of the URL. * * @param url the url to open and read from * @param method the method to use for the request * @param data the request body as string * @param mediaType the media type of the request * @param username the username, if any * @param password the password, if any * @param requestHeaders the special request headers to send * @param responseHeaders save response headers * @return the read string from the//from w w w .j a v a2 s . co m * @throws InvalidCredentialsException if the connection credentials are invalid * @throws IOException if there is a problem with the request */ public static String openUrl(String url, String method, String data, String mediaType, @Nullable String username, @Nullable String password, @Nullable List<Header> requestHeaders, @Nullable List<Header> responseHeaders) throws InvalidCredentialsException, IOException { String response = null; /* Set the cookie policy */ httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); /* Set the user agent */ httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Constants.NODEABLE_HTTP_USER_AGENT); HttpContext context = new BasicHttpContext(); HttpRequestBase httpMethod; if (method.equals("DELETE")) { httpMethod = new HttpDelete(url); } else if (method.equals("GET")) { httpMethod = new HttpGet(url); } else if (method.equals("POST")) { httpMethod = new HttpPost(url); } else if (method.equals("PUT")) { httpMethod = new HttpPut(url); } else { throw new IllegalArgumentException("The method you specified is not supported."); } // Put data into the request for POST and PUT requests if (method.equals("POST") || method.equals("PUT") && data != null) { HttpEntityEnclosingRequestBase eeMethod = (HttpEntityEnclosingRequestBase) httpMethod; eeMethod.setEntity(new StringEntity(data, ContentType.create(mediaType, "UTF-8"))); } /* Set the username/password if any */ if (username != null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider); } /* Add request headers if need be */ if (requestHeaders != null) { for (Header header : requestHeaders) { httpMethod.addHeader(header); } } LOGGER.debug("Making HTTP request as " + (username != null ? username : "anonymous") + ": " + method + " - " + url); /* Make the request and read the response */ try { HttpResponse httpResponse = httpClient.execute(httpMethod); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { response = EntityUtils.toString(entity); } int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == 401 || responseCode == 403) { throw new InvalidCredentialsException("The connection credentials are invalid."); } else if (responseCode < 200 || responseCode > 299) { throw new IOException( "Unexpected status code of " + responseCode + " for a " + method + " request to " + url); } if (responseHeaders != null) { responseHeaders.addAll(Arrays.asList(httpResponse.getAllHeaders())); } } catch (IOException e) { httpMethod.abort(); throw e; } return response; }