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.thingsee.tracker.REST.KiiRemoveTrackerAsyncTask.java

@Override
protected Boolean doInBackground(String... params) {

    InputStream inputStream = null;
    Boolean result = false;/*from   w  w  w  .j ava 2 s  .c  om*/

    try {
        String dataString = "https://api.kii.com/api/apps/" + mAppId + "/users/me/buckets/trackers/objects/"
                + mObjectID;
        HttpDelete deleteRequest = new HttpDelete(dataString);
        deleteRequest.addHeader("x-kii-appid", mAppId);
        deleteRequest.addHeader("x-kii-appkey", mAppKey);
        deleteRequest.addHeader("Authorization", mOwnerToken);
        deleteRequest.addHeader("If-match", "1");
        HttpResponse response = mHttpClient.execute(deleteRequest);
        Log.e(LOG_TAG, "REST HttpResponse = " + response.getStatusLine());
        if (response != null && response.getStatusLine().getStatusCode() == 204) {
            inputStream = response.getEntity().getContent();
            if (inputStream != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                String currentBatch = "";
                while ((line = reader.readLine()) != null) {
                    currentBatch += line;
                }
                reader.close();
                Log.e(LOG_TAG, "REST bucket query response = " + currentBatch);
                reader.close();
                currentBatch = null;
            }
            result = true;
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage());
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (Exception e) {
            }
        }
    }
    return result;
}

From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpSession.java

HttpResult delete(String endpoint) throws IOException {
    return httpClient.execute(new HttpDelete(getPeerInfo().getDirectUrl() + endpoint),
            new HttpResponseHandler());
}

From source file:org.apache.abdera2.common.protocol.RequestHelper.java

public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity,
        RequestOptions options) {//  www  .ja v  a 2  s .  c  om
    if (method == null)
        return null;
    if (options == null)
        options = createAtomDefaultRequestOptions().get();
    Method m = Method.get(method);
    Method actual = null;
    HttpUriRequest httpMethod = null;
    if (options.isUsePostOverride() && !nopostoveride.contains(m)) {
        actual = m;
        m = Method.POST;
    }
    if (m == GET)
        httpMethod = new HttpGet(uri);
    else if (m == POST) {
        httpMethod = new HttpPost(uri);
        if (entity != null)
            ((HttpPost) httpMethod).setEntity(entity);
    } else if (m == PUT) {
        httpMethod = new HttpPut(uri);
        if (entity != null)
            ((HttpPut) httpMethod).setEntity(entity);
    } else if (m == DELETE)
        httpMethod = new HttpDelete(uri);
    else if (m == HEAD)
        httpMethod = new HttpHead(uri);
    else if (m == OPTIONS)
        httpMethod = new HttpOptions(uri);
    else if (m == TRACE)
        httpMethod = new HttpTrace(uri);
    //        else if (m == PATCH)
    //          httpMethod = new ExtensionRequest(m.name(),uri,entity);
    else
        httpMethod = new ExtensionRequest(m.name(), uri, entity);
    if (actual != null) {
        httpMethod.addHeader("X-HTTP-Method-Override", actual.name());
    }
    initHeaders(options, httpMethod);
    HttpParams params = httpMethod.getParams();
    if (!options.isUseExpectContinue()) {
        params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    } else {
        if (options.getWaitForContinue() > -1)
            params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue());
    }
    if (!(httpMethod instanceof HttpEntityEnclosingRequest))
        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects());
    return httpMethod;
}

From source file:es.bsc.demiurge.core.utils.HttpUtils.java

/**
 * Builds an HTTP Request./*from  w w  w .ja  v  a  2 s.  c o  m*/
 *
 * @param methodType Type of the request (GET, POST, etc.).
 * @param uri URI of the request.
 * @param header Headers of the request.
 * @param entity Entity of the request.
 * @return The HTTP Request built.
 */
public static HttpRequestBase buildHttpRequest(String methodType, URI uri, Map<String, String> header,
        String entity) {
    HttpRequestBase request;

    //instantiate the request according to its type (GET, POST...)
    switch (methodType) {
    case "GET":
        request = new HttpGet(uri);
        break;
    case "POST":
        request = new HttpPost(uri);
        break;
    case "DELETE":
        request = new HttpDelete(uri);
        break;
    default:
        request = null;
        break;
    }

    if (request == null) {
        throw new IllegalArgumentException("Method not supported.");
    }

    //set the headers of the request
    for (Map.Entry<String, String> entry : header.entrySet()) {
        request.setHeader(entry.getKey(), entry.getValue());
    }

    //if the type of the request is POST, set the entity of the request
    if (request instanceof HttpPost && !entity.equals("")) {
        try {
            ((HttpPost) request).setEntity(new StringEntity(entity));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    return request;
}

From source file:jp.co.gui.aruga.watch.ClockHttpRequest.java

public void delete(String id) throws IOException {
    HttpDelete request = new HttpDelete(url + "/json/" + id);

    HttpResponse hr = httpClient.execute(request);
    if (hr.getStatusLine().getStatusCode() >= 400)
        throw new UnsupportedOperationException();
}

From source file:org.mule.modules.constantcontact.RequestExecutor.java

public Response doDeleteRequest(String s) throws ConstantContactException {
    HttpDelete httpDelete = new HttpDelete(s);
    return executeRequest(httpDelete);
}

From source file:com.connectsdk.etc.helper.HttpMessage.java

public static HttpDelete getHttpDelete(String url) {
    return new HttpDelete(url);
}

From source file:org.chaplib.HttpResource.java

public void delete() {
    consumeBodyOf(execute(new HttpDelete(uri)));
}

From source file:com.google.sample.devicelab.io.HttpCallHelper.java

/**
 * Use this constructor for a DELETE request
 *
 * @param url    The full url, including parameters
 * @param delete Pass in true for DELETE, false for GET
 * @throws IOException        If the connection cannot be made
 * @throws URISyntaxException If url is malformed
 *///from   w  w w .  j  a  v  a 2  s .c  o  m
public HttpCallHelper(String url, boolean delete) throws IOException, URISyntaxException {
    executeCall(delete ? new HttpDelete(url) : new HttpGet(url), null);
}

From source file:com.intel.iotkitlib.LibHttp.HttpDeleteTask.java

private CloudResponse doWork(HttpClient httpClient, String url) {
    try {/*from   w w w.  ja v  a 2s .  com*/
        HttpContext localContext = new BasicHttpContext();
        HttpDelete httpDelete = new HttpDelete(url);
        //adding headers one by one
        for (NameValuePair nvp : headerList) {
            httpDelete.addHeader(nvp.getName(), nvp.getValue());
        }
        if (debug) {
            Log.e(TAG, "URI is : " + httpDelete.getURI());
            Header[] headers = httpDelete.getAllHeaders();
            for (int i = 0; i < headers.length; i++) {
                Log.e(TAG, "Header " + i + " is :" + headers[i].getName() + ":" + headers[i].getValue());
            }
        }
        HttpResponse response = httpClient.execute(httpDelete, localContext);
        if (response != null && response.getStatusLine() != null) {
            if (debug)
                Log.d(TAG, "response: " + response.getStatusLine().getStatusCode());
        }
        HttpEntity responseEntity = response != null ? response.getEntity() : null;
        StringBuilder builder = new StringBuilder();
        if (responseEntity != null) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(responseEntity.getContent(), HTTP.UTF_8));
            for (String line = null; (line = reader.readLine()) != null;) {
                builder.append(line).append("\n");
            }
            if (debug)
                Log.d(TAG, "Response received is :" + builder.toString());
        }
        CloudResponse cloudResponse = new CloudResponse();
        if (response != null) {
            cloudResponse.code = response.getStatusLine().getStatusCode();
        }
        cloudResponse.response = builder.toString();
        return cloudResponse;
    } catch (java.net.ConnectException cEx) {
        Log.e(TAG, cEx.getMessage());
        return null;
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        return null;
    }
}