Example usage for org.apache.http.client.methods HttpDelete HttpDelete

List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpDelete HttpDelete.

Prototype

public HttpDelete(final String uri) 

Source Link

Usage

From source file:com.navercorp.volleyextensions.volleyer.multipart.stack.MultipartHttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from  w  w w.  j  a  v  a2 s.c  om
@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());
        setEntityIfNonEmptyMultipart(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        setEntityIfNonEmptyMultipart(putRequest, request);
        return putRequest;
    }
    case Method.HEAD:
        return new HttpHead(request.getUrl());
    case Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Method.PATCH: {
        HttpPatch patchRequest = new HttpPatch(request.getUrl());
        patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyMultipart(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:org.sahli.asciidoc.confluence.publisher.client.http.HttpRequestFactory.java

HttpDelete deletePageRequest(String contentId) {
    assertMandatoryParameter(isNotBlank(contentId), "contentId");

    return new HttpDelete(this.confluenceRestApiEndpoint + "/content/" + contentId);
}

From source file:cn.dacas.emmclient.security.ssl.SslHttpStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from  www .  j ava  2  s . c om
@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.ksc.http.apache.request.impl.ApacheHttpRequestFactory.java

private HttpRequestBase createApacheRequest(Request<?> request, String uri, String encodedParams)
        throws FakeIOException {
    switch (request.getHttpMethod()) {
    case HEAD:/*  ww  w. j a v  a 2s.co  m*/
        return new HttpHead(uri);
    case GET:
        return new HttpGet(uri);
    case DELETE:
        return new HttpDelete(uri);
    case PATCH:
        return wrapEntity(request, new HttpPatch(uri), encodedParams);
    case POST:
        return wrapEntity(request, new HttpPost(uri), encodedParams);
    case PUT:
        return wrapEntity(request, new HttpPut(uri), encodedParams);
    default:
        throw new KscClientException("Unknown HTTP method name: " + request.getHttpMethod());
    }
}

From source file:com.decody.android.core.json.JSONClient.java

public <T> T delete(String url, Class<T> classOfT) throws ResourceNotFoundException, UnauthorizedException {
    return performCall(new HttpDelete(url), classOfT);
}

From source file:com.cloudant.mazha.HttpRequests.java

HttpResponse deleteResponse(URI uri) {
    HttpDelete delete = new HttpDelete(uri);
    return deleteResponse(delete);
}

From source file:it.cloudicaro.disit.kb.rdf.HttpUtil.java

public static void delete(URL url, String user, String passwd) throws Exception {
    //System.out.println("DELETE "+url);
    HttpClient client = HttpClients.createDefault();
    HttpDelete request = new HttpDelete(url.toURI());

    HttpClientContext context = HttpClientContext.create();
    if (user != null && passwd != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, passwd));
        context.setCredentialsProvider(credsProvider);
    }//from  w w w .j  a va2s  .c  om

    HttpResponse response = client.execute(request, context);

    StatusLine s = response.getStatusLine();
    int code = s.getStatusCode();
    //System.out.println(code);
    if (code != 204 && code != 404)
        throw new Exception(
                "failed access to " + url.toString() + " code: " + code + " " + s.getReasonPhrase());
}

From source file:com.kolich.http.common.HttpClient4ClosureBase.java

public T delete(final URI uri) {
    return delete(new HttpDelete(uri));
}

From source file:org.apache.activemq.transport.discovery.http.HTTPDiscoveryAgent.java

@SuppressWarnings("unused")
synchronized private void doUnRegister(String service) {
    String url = registryURL;//from w  w w.j a  v  a  2 s . c om
    try {
        HttpDelete method = new HttpDelete(url);
        method.addHeader("service", service);
        ResponseHandler<String> handler = new BasicResponseHandler();
        String responseBody = httpClient.execute(method, handler);
        LOG.debug("DELETE to " + url + " got a " + responseBody);
    } catch (Exception e) {
        LOG.debug("DELETE to " + url + " failed with: " + e);
    }
}

From source file:org.activiti.rest.service.api.runtime.ProcessInstanceResourceTest.java

/**
 * Test deleting an unexisting process instance.
 *///from  ww w . j a  va 2 s  .c  o  m
public void testDeleteUnexistingProcessInstance() {
    closeResponse(executeRequest(
            new HttpDelete(SERVER_URL_PREFIX
                    + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, "unexistingpi")),
            HttpStatus.SC_NOT_FOUND));
}