List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete
public HttpDelete(final String uri)
From source file:com.android.volley.ssl.SslHttpStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*w w w. j ava2 s. co m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setMultiPartBody(postRequest, request); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setMultiPartBody(putRequest, request); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } // Added in source code of Volley libray. /*case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; }*/ default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.android.volley.toolbox.https.ExtHttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. * @throws IOException //from w w w .j ava 2s .co m */ /* protected */static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError, IOException { switch (request.getMethod()) { case Method.GET: return new HttpGet(mRewriter.rewriteUrl(request)); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:cn.com.zzwfang.http.HttpExecuter.java
@Override public HttpResponse delete(String url, RequestParams params, Header[] headers) { if (url == null) { return null; }//from ww w .j a v a2 s .c om if (params != null) { String paramString = params.getParamString(); if (url.indexOf("?") == -1) { url += "?" + paramString; } else { url += "&" + paramString; } } HttpDelete httpDelete = new HttpDelete(url); if (headers != null && headers.length > 0) { httpDelete.setHeaders(headers); } return execute(httpDelete); }
From source file:org.deviceconnect.android.profile.restful.test.FailSystemProfileTestCase.java
/** * DELETE?????.//from w ww. j ava 2 s . c o m * <pre> * ?HTTP * Method: DELETE * Path: /system/device?deviceId=123456789&deviceId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetSystemInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(SystemProfileConstants.PROFILE_NAME); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:org.commonjava.couch.test.fixture.RemoteRESTFixture.java
public HttpResponse delete(final String url) throws Exception { final HttpDelete request = new HttpDelete(fixup(url)); try {// w w w . j a va 2 s .c om final HttpResponse response = http.execute(request); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_OK)); return response; } finally { request.abort(); } }
From source file:org.openihs.seendroid.lib.Connection.java
public HttpDelete getHttpDelete(String uri) { HttpDelete post = new HttpDelete(this.base_api_url + uri); this.addHeaders(post); post.addHeader("Content-type", "application/atom+xml;type=entry"); return post;//w ww. j av a2 s . com }
From source file:org.wso2.carbon.dynamic.client.web.proxy.RegistrationProxy.java
@DELETE @Produces(MediaType.APPLICATION_JSON)/*from ww w . j av a 2s. c om*/ public Response unregister(@QueryParam("applicationName") String applicationName, @QueryParam("userId") String userId, @QueryParam("consumerKey") String consumerKey) { Response response; DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient(); String host = DCRProxyUtils.getKeyManagerHost(); try { URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL) .setHost(host).setPath(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT) .setParameter("applicationName", applicationName).setParameter("userId", userId) .setParameter("consumerKey", consumerKey).build(); HttpDelete httpDelete = new HttpDelete(uri); CloseableHttpResponse serverResponse = httpClient.execute(httpDelete); HttpEntity responseData = serverResponse.getEntity(); int status = serverResponse.getStatusLine().getStatusCode(); String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8); response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build(); } catch (URISyntaxException e) { String msg = "Server error occurred while deleting the client '" + applicationName + "'"; log.error(msg, e); response = Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (UnsupportedEncodingException e) { String msg = "Request data encoding error occurred while deleting the client '" + applicationName + "'"; log.error(msg, e); response = Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity(msg).build(); } catch (IOException e) { String msg = "Service invoke error occurred while deleting the client '" + applicationName + "'"; log.error(msg, e); response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } finally { httpClient.close(); } return response; }
From source file:kindleclippings.quizlet.QuizletAPI.java
public void deleteSet(String setId) throws IOException { HttpDelete delete = new HttpDelete("https://api.quizlet.com/2.0/sets/" + setId); delete.addHeader("Authorization", "Bearer " + accessToken); HttpResponse response = new DefaultHttpClient().execute(delete); if (response.getStatusLine().getStatusCode() != 204) throw new IOException(response.getStatusLine().toString()); }
From source file:com.infostretch.volydemo.network.volly.ssl.SslHttpStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//* w ww . j a v a2 s .c o m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setMultiPartBody(postRequest, request); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setMultiPartBody(putRequest, request); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } // Added in source code of Volley libray. case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:azkaban.utils.RestfulApiClient.java
/** function to perform a Delete http request. * @param uri the URI of the request./*from w w w. ja v a 2 s . c o m*/ * @param headerEntries extra entries to be added to request header. * @return the response object type of which is specified by user. * @throws IOException */ public T httpDelete(URI uri, List<NameValuePair> headerEntries) throws IOException { // shortcut if the passed url is invalid. if (null == uri) { logger.error(" unable to perform httpDelete as the passed uri is null."); return null; } HttpDelete delete = new HttpDelete(uri); return this.sendAndReturn((HttpDelete) completeRequest(delete, headerEntries)); }