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.github.dziga.orest.client.HttpRestClient.java

int Delete() throws IOException, URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder().setScheme(scheme).setHost(host).setPath(path);
    addQueryParams(uriBuilder);//w  ww. ja va 2  s. c  o m
    URI fullUri = uriBuilder.build();
    HttpDelete deleteMethod = new HttpDelete(fullUri);
    deleteMethod = (HttpDelete) addHeadersToMethod(deleteMethod);
    processResponse(httpClient.execute(deleteMethod));

    return getResponseCode();
}

From source file:org.bedework.util.http.HttpUtil.java

/** Specify the next method by name.
 *
 * @param name of the method/* ww  w  . ja va2 s.  co m*/
 * @param uri target
 * @return method object or null for unknown
 */
public static HttpRequestBase findMethod(final String name, final URI uri) {
    final String nm = name.toUpperCase();

    if ("PUT".equals(nm)) {
        return new HttpPut(uri);
    }

    if ("GET".equals(nm)) {
        return new HttpGet(uri);
    }

    if ("DELETE".equals(nm)) {
        return new HttpDelete(uri);
    }

    if ("POST".equals(nm)) {
        return new HttpPost(uri);
    }

    if ("PROPFIND".equals(nm)) {
        return new HttpPropfind(uri);
    }

    if ("MKCALENDAR".equals(nm)) {
        return new HttpMkcalendar(uri);
    }

    if ("MKCOL".equals(nm)) {
        return new HttpMkcol(uri);
    }

    if ("OPTIONS".equals(nm)) {
        return new HttpOptions(uri);
    }

    if ("REPORT".equals(nm)) {
        return new HttpReport(uri);
    }

    if ("HEAD".equals(nm)) {
        return new HttpHead(uri);
    }

    return null;
}

From source file:com.scoopit.weedfs.client.WeedFSClientImpl.java

@Override
public void delete(WeedFSFile file, Location location) throws IOException, WeedFSException {
    StringBuilder url = new StringBuilder();
    if (!location.publicUrl.contains("http")) {
        url.append("http://");
    }//from  w  w  w .  j av  a  2  s  .c  om
    url.append(location.publicUrl);
    url.append("/");
    url.append(file.fid);

    if (file.version > 0) {
        url.append("_");
        url.append(file.version);
    }

    HttpDelete delete = new HttpDelete(url.toString());
    try {
        HttpResponse response = httpClient.execute(delete);

        StatusLine line = response.getStatusLine();
        if (line.getStatusCode() < 200 || line.getStatusCode() > 299) {
            throw new WeedFSException(
                    "Error deleting file " + file.fid + " on " + location.publicUrl + ": "
                            + line.getStatusCode() + " " + line.getReasonPhrase(),
                    EntityUtils.toString(response.getEntity(), "UTF-8"));
        }
    } finally {
        delete.abort();
    }
}

From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java

private HttpUriRequest getRequest(String method, String url) {
    if (HttpPost.METHOD_NAME.equals(method)) {
        return new HttpPost(url);
    } else if (HttpPut.METHOD_NAME.equals(method)) {
        return new HttpPut(url);
    } else if (HttpDelete.METHOD_NAME.equals(method)) {
        return new HttpDelete(url);
    } else if (HttpOptions.METHOD_NAME.equals(method)) {
        return new HttpOptions(url);
    } else if (HttpHead.METHOD_NAME.equals(method)) {
        return new HttpHead(url);
    }/*from   w  w w. j  a v a  2  s . c  o m*/
    return new HttpGet(url);
}

From source file:org.doctester.testbrowser.TestBrowserImpl.java

private Response makeHeadGetOrDeleteRequest(Request request) {

    Response response;/*www  .j  av a2s.c  om*/

    org.apache.http.HttpResponse apacheHttpClientResponse;

    try {

        HttpUriRequest apacheHttpRequest;

        httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        if (GET.equalsIgnoreCase(request.httpRequestType)) {

            apacheHttpRequest = new HttpGet(request.uri);

        } else if (DELETE.equalsIgnoreCase(request.httpRequestType)) {

            apacheHttpRequest = new HttpDelete(request.uri);

        } else {

            apacheHttpRequest = new HttpHead(request.uri);

        }

        if (request.headers != null) {

            // add all headers
            for (Entry<String, String> header : request.headers.entrySet()) {
                apacheHttpRequest.addHeader(header.getKey(), header.getValue());
            }

        }

        setHandleRedirect(apacheHttpRequest, request.followRedirects);

        apacheHttpClientResponse = httpClient.execute(apacheHttpRequest);

        response = convertFromApacheHttpResponseToDocTesterHttpResponse(apacheHttpClientResponse);

        if (apacheHttpRequest instanceof HttpRequestBase) {
            ((HttpRequestBase) apacheHttpRequest).releaseConnection();
        }

    } catch (IOException e) {
        logger.error("Fatal problem creating GET or DELETE request in TestBrowser", e);
        throw new RuntimeException(e);
    }

    return response;
}

From source file:com.surevine.alfresco.connector.BaseAlfrescoHttpConnector.java

/**
 * Visit a URL using an HTTP DELETE and parse out a JSON object from the
 * response./* w w w.j  a  v  a 2 s .c om*/
 * 
 * @param url
 *          URL to delete
 * @return The JSON response
 * @throws AlfrescoException
 *           On any HTTP error
 */
protected AlfrescoHttpResponse doHttpDelete(final String url) throws AlfrescoException {
    // construct entity to post
    final HttpDelete request = new HttpDelete(url);

    return fetch(request);
}

From source file:com.ibm.iotf.client.api.DeviceFactory.java

private String connect(String httpOperation, String url, String jsonPacket) {
    final String METHOD = "connect";
    BufferedReader br = null;//  w  w w .j  a v a  2s  .c  om
    br = new BufferedReader(new InputStreamReader(System.in));

    StringEntity input = null;
    try {
        if (jsonPacket != null) {
            input = new StringEntity(jsonPacket);
        }
    } catch (UnsupportedEncodingException e) {
        LoggerUtility.warn(CLASS_NAME, METHOD, "Unable to carry out the ReST request");
        return null;
    }
    byte[] encoding = Base64.encodeBase64(new String(authKey + ":" + authToken).getBytes());
    String encodedString = new String(encoding);
    switch (httpOperation) {
    case "post":
        HttpPost post = new HttpPost(url);
        post.setEntity(input);
        post.addHeader("Content-Type", "application/json");
        post.addHeader("Accept", "application/json");
        post.addHeader("Authorization", "Basic " + encodedString);
        try {
            HttpClient client = HttpClientBuilder.create().build();
            HttpResponse response = client.execute(post);
            br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        } catch (IOException e) {
            LoggerUtility.warn(CLASS_NAME, METHOD, e.getMessage());
            return null;
        } finally {

        }
        break;
    case "get":

        HttpGet get = new HttpGet(url);
        get.addHeader("Content-Type", "application/json");
        get.addHeader("Accept", "application/json");
        get.addHeader("Authorization", "Basic " + encodedString);
        try {
            HttpClient client = HttpClientBuilder.create().build();
            HttpResponse response = client.execute(get);
            br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        } catch (IOException e) {
            LoggerUtility.warn(CLASS_NAME, METHOD, e.getMessage());
            return null;
        }
        break;
    case "delete":
        HttpDelete delete = new HttpDelete(url);
        delete.addHeader("Content-Type", "application/json");
        delete.addHeader("Accept", "application/json");
        delete.addHeader("Authorization", "Basic " + encodedString);
        try {
            HttpClient client = HttpClientBuilder.create().build();
            HttpResponse response = client.execute(delete);
            int httpCode = response.getStatusLine().getStatusCode();
            if (httpCode == 202 || httpCode == 200 || httpCode == 204) {
                return SUCCESSFULLY_DELETED;
            } else if (httpCode == 400 || httpCode == 404) {
                return RESOURCE_NOT_FOUND;
            }

        } catch (IOException e) {
            LoggerUtility.warn(CLASS_NAME, METHOD, e.getMessage());
            return UNKNOWN_ERROR;
        } finally {

        }
        break;
    }

    String line = null;
    try {
        line = br.readLine();
    } catch (IOException e) {
        LoggerUtility.warn(CLASS_NAME, METHOD, e.getMessage());
        return null;
    }
    LoggerUtility.info(CLASS_NAME, METHOD, line);
    try {
        if (br != null)
            br.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return line;
}

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

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

From source file:net.sf.jaceko.mock.it.helper.request.HttpRequestSender.java

public MockResponse sendDeleteRequest(String url, Map<String, String> headers) throws IOException {
    HttpDelete httpDelete = new HttpDelete(url);
    return executeRequest(httpDelete, headers);
}