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.wso2.raspberrypi.apicalls.HttpClient.java

public HttpResponse doDelete(String url, String token) throws IOException {
    HttpUriRequest request = new HttpDelete(url);
    addSecurityHeaders(request, token);/*from   w  w  w  .j av a 2 s .com*/
    return client.execute(request);
}

From source file:org.opencastproject.search.remote.SearchServiceRemoteImpl.java

/**
 * {@inheritDoc}/* w w  w.  j  a  v a 2  s  . c  o m*/
 * 
 * @see org.opencastproject.search.api.SearchService#delete(java.lang.String)
 */
@Override
public Job delete(String mediaPackageId) throws SearchException {
    HttpDelete del = new HttpDelete(mediaPackageId);
    HttpResponse response = getResponse(del);
    try {
        if (response != null) {
            Job job = JobParser.parseJob(response.getEntity().getContent());
            logger.info("Removing mediapackage '{}' from a remote search service", mediaPackageId);
            return job;
        }
    } catch (Exception e) {
        throw new SearchException("Unable to remove " + mediaPackageId + " from a remote search service", e);
    } finally {
        closeConnection(response);
    }

    throw new SearchException("Unable to remove " + mediaPackageId + " from a remote search service");
}

From source file:com.uber.stream.kafka.mirrormaker.common.utils.HttpClientUtils.java

public static int deleteData(final HttpClient httpClient, final RequestConfig requestConfig, final String host,
        final int port, final String path, final String src, final String dst, final int routeId)
        throws IOException, URISyntaxException {
    URI uri = new URIBuilder().setScheme("http").setHost(host).setPort(port).setPath(path)
            .addParameter("src", src).addParameter("dst", dst).addParameter("routeid", String.valueOf(routeId))
            .build();//  w  ww  .  ja va  2 s.  c o m

    HttpDelete httpDelete = new HttpDelete(uri);
    httpDelete.setConfig(requestConfig);

    return httpClient.execute(httpDelete, HttpClientUtils.createResponseCodeExtractor());
}

From source file:org.camunda.connect.httpclient.impl.AbstractHttpConnector.java

@SuppressWarnings("unchecked")
protected <T extends HttpRequestBase> T createHttpRequestBase(Q request) {
    String url = request.getUrl();
    if (url != null && !url.trim().isEmpty()) {
        String method = request.getMethod();
        if (HttpGet.METHOD_NAME.equals(method)) {
            return (T) new HttpGet(url);
        } else if (HttpPost.METHOD_NAME.equals(method)) {
            return (T) new HttpPost(url);
        } else if (HttpPut.METHOD_NAME.equals(method)) {
            return (T) new HttpPut(url);
        } else if (HttpDelete.METHOD_NAME.equals(method)) {
            return (T) new HttpDelete(url);
        } else if (HttpPatch.METHOD_NAME.equals(method)) {
            return (T) new HttpPatch(url);
        } else if (HttpHead.METHOD_NAME.equals(method)) {
            return (T) new HttpHead(url);
        } else if (HttpOptions.METHOD_NAME.equals(method)) {
            return (T) new HttpOptions(url);
        } else if (HttpTrace.METHOD_NAME.equals(method)) {
            return (T) new HttpTrace(url);
        } else {/*from   w ww.  j a va 2  s.c o  m*/
            throw LOG.unknownHttpMethod(method);
        }
    } else {
        throw LOG.requestUrlRequired();
    }
}

From source file:ca.ualberta.cmput301f13t13.storyhoard.serverClasses.ESUpdates.java

/**
 * Deletes an entry (in this case a story object) specified by the id from
 * the server. You must specify the id as a string (but in the format of
 * a UUID), and the server as a string as well. In addition, output from
 * the server (the response's content) will also be printed out to
 * System.err. </br></br>//from  ww w .  j  a v  a2s .  c o  m
 * 
 * Example call: </br>
 * Let's say the following story is on the server. </br>
 * </br> String id = f1bda3a9-4560-4530-befc-2d58db9419b7; 
 *       Story myStory = new Story(id, "The Cow", "John Wayne", 
 *                            "A story about a Cow", phoneId). 
 * </br> To delete myStory from the server, call </br>
 * String server = "http://cmput301.softwareprocess.es:8080/cmput301f13t13/stories/" </br>
 * String id = f1bda3a9-4560-4530-befc-2d58db9419b7; </br>
 * deleteStory(id, server); </br></br>
 * 
 * @param id
 *          Must be a String in the valid format of a UUID. See example
 *          above for the formatting of a UUID.
 * @param server
 *          The location on elastic search to search for the responses.
 *          It expects this information as a String.</br>
 *          See the above example for an example of a valid server string
 *          format.
 */
protected void deleteStory(String id, String server) throws IOException {
    HttpDelete httpDelete = new HttpDelete(server + id);
    httpDelete.addHeader("Accept", "application/json");

    HttpResponse response = httpclient.execute(httpDelete);

    String status = response.getStatusLine().toString();
    System.out.println(status);

    HttpEntity entity = response.getEntity();
    InputStreamReader is = new InputStreamReader(entity.getContent());
    BufferedReader br = new BufferedReader(is);
    String output;
    System.err.println("Output from ESUpdates -> ");

    while ((output = br.readLine()) != null) {
        System.err.println(output);
    }

    entity.consumeContent();
    is.close();
}

From source file:org.cloudml.connectors.PyHrapiConnector.java

private String invoke(URI uri, String method, String body) throws UnsupportedEncodingException, IOException {
    HttpUriRequest request = null;/*from   w  w  w . java2  s  .c om*/

    if ("GET".equals(method)) {
        request = new HttpGet(uri);
    } else if ("POST".equals(method)) {
        HttpPost post = new HttpPost(uri);
        if (body != null && !body.isEmpty()) {
            post.setHeader("Content-type", "application/json");
            post.setEntity(new StringEntity(body));
        }
        request = post;
    } else if ("PUT".equals(method)) {
        HttpPut put = new HttpPut(uri);
        if (body != null && !body.isEmpty()) {
            put.setHeader("Content-type", "application/json");
            put.setEntity(new StringEntity(body));
        }
        request = put;
    } else if ("DELETE".equals(method)) {
        request = new HttpDelete(uri);
    }
    HttpResponse response = httpclient.execute(request);
    String s = IOUtils.toString(response.getEntity().getContent());
    //TODO: will be removed after debug
    System.out.println(s);
    return s;
}

From source file:neal.http.impl.httpstack.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 */// w  w w. j a  v a  2  s  . com
@SuppressWarnings("deprecation")
/* protected */ static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) throws HttpErrorCollection.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());
        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;
    }
    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());
        setEntityIfNonEmptyBody(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:org.jboss.as.test.integration.web.security.servlet.methods.DenyUncoveredHttpMethodsTestCase.java

@Test
public void testDeleteMethod() throws Exception {
    HttpDelete httpDelete = new HttpDelete(getURL());
    HttpResponse response = getHttpResponse(httpDelete);

    assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN));
}

From source file:com.joyent.manta.http.MantaHttpRequestFactory.java

/**
 * Convenience method used for building DELETE operations.
 * @param path path to resource//from w w w.  j av  a  2 s  .  co m
 * @param params list of query parameters to use in operation
 * @return instance of configured {@link org.apache.http.client.methods.HttpRequestBase} object.
 */
public HttpDelete delete(final String path, final List<NameValuePair> params) {
    final HttpDelete request = new HttpDelete(uriForPath(path, params));
    prepare(request);
    return request;
}

From source file:org.lokra.seaweedfs.core.VolumeWrapper.java

/**
 * Delete file.//from  www  . j  av a 2 s  .c  o m
 *
 * @param url Server url.
 * @param fid File id.
 * @throws IOException Http connection is fail or server response within some error message.
 */
void deleteFile(String url, String fid) throws IOException {
    HttpDelete request = new HttpDelete(url + "/" + fid);
    convertResponseStatusToException(connection.fetchJsonResultByRequest(request).statusCode, url, fid, false,
            false, false, false);
}