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() 

Source Link

Usage

From source file:com.simple.toadiot.rtinfosdk.http.DefaultRequestHandler.java

private HttpRequestBase buildRequest(HttpMethod method, String path, Map<String, String> headers, Object body,
        Map<String, Object> params) {
    AcceptedMediaType mediaType = AppConfig.getResponseMediaType();

    HttpRequestBase request = null;/*from   ww w  .  ja  va  2  s  .c  o m*/
    StringEntity entity = getEntity(body);
    switch (method) {
    case DELETE:
        request = new HttpDelete();
        break;
    case GET:
        request = new HttpGet();
        break;
    case POST:
        request = new HttpPost();
        if (entity != null) {
            ((HttpPost) request).setEntity(entity);
        }
        break;
    case PUT:
        request = new HttpPut();
        if (entity != null) {
            ((HttpPut) request).setEntity(entity);
        }
        break;
    default:
        return null;
    }

    try {
        if (!path.toLowerCase(Locale.ENGLISH).startsWith("http")) {
            URIBuilder uriBuilder = buildUri(method, path, params, mediaType);
            request.setURI(uriBuilder.build());
        } else {
            request.setURI(new URI(path));
        }
    } catch (URISyntaxException e) {
        throw new RequestInvalidException("Invalid URI requested.", e);
    }
    //      request.addHeader("accept", mediaType.getMediaType());
    //      request.addHeader(HEADER_KEY_API, AppConfig.getInstance().getApiKey());
    //      request.addHeader(HEADER_USER_AGENT, XIVELY_USER_AGENT);
    /**
     *  Header
     */
    request.addHeader("Content-Type", mediaType.getMediaType() + ";charset=" + AppConfig.getCharset());
    if (headers != null && !headers.isEmpty()) {
        int index = 0;
        Header[] header = new Header[headers.size()];
        for (Entry<String, String> element : headers.entrySet()) {
            header[index++] = new BasicHeader(element.getKey(), element.getValue());
        }
        request.setHeaders(header);
    }
    //      if (params != null && !params.isEmpty()) {
    //         HttpParams hparams = new SyncBasicHttpParams();
    //         for (Entry<String, Object> param : params.entrySet()) {
    //            hparams.setParameter(param.getKey(), param.getValue());
    //         }
    //         request.setParams(hparams);
    //      }
    return request;
}

From source file:org.xwiki.android.rest.HttpConnector.java

/**
 * Perform HTTP Delete method execution and return its status
 * //  w  ww  .  j  a v a  2  s. c o  m
 * @param Uri URL of XWiki RESTful API
 * @return status of the HTTP method execution
 */
public String deleteRequest(String Uri) {
    initialize();

    HttpDelete request = new HttpDelete();

    try {
        requestUri = new URI(Uri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    setCredentials();

    request.setURI(requestUri);
    Log.d("Request URL", Uri);

    try {

        response = client.execute(request);
        Log.d("Response status", response.getStatusLine().toString());
        return response.getStatusLine().toString();

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return "error";
}

From source file:com.tealeaf.util.HTTP.java

public Response makeRequest(Methods method, URI uri, HashMap<String, String> requestHeaders, String data) {

    HttpRequestBase request = null;//from   w  w  w  . j  ava2s  .c o m

    try {
        if (method == Methods.GET) {
            request = new HttpGet();
        } else if (method == Methods.POST) {
            request = new HttpPost();
            if (data != null) {
                ((HttpPost) request).setEntity(new StringEntity(data, "UTF-8"));
            }
        } else if (method == Methods.PUT) {
            request = new HttpPut();
            if (data != null) {
                ((HttpPut) request).setEntity(new StringEntity(data, "UTF-8"));
            }
        } else if (method == Methods.DELETE) {
            request = new HttpDelete();
        } else if (method == Methods.HEAD) {
            request = new HttpHead();
        }
    } catch (UnsupportedEncodingException e) {
        logger.log(e);
    }
    request.setURI(uri);
    AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent);
    if (requestHeaders != null) {
        for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
            request.addHeader(new BasicHeader(entry.getKey(), entry.getValue()));
        }
    }

    HttpResponse response = null;
    Response retVal = new Response();
    retVal.headers = new HashMap<String, String>();
    try {
        response = client.execute(request, localContext);
    } catch (SocketTimeoutException e) {
        // forget it--we don't care that the user couldn't connect
        // TODO hand this back as an error to JS
    } catch (IOException e) {
        if (!caughtIOException) {
            caughtIOException = true;
            logger.log(e);
        }
    } catch (Exception e) {
        logger.log(e);
    }
    if (response != null) {
        retVal.status = response.getStatusLine().getStatusCode();
        retVal.body = readContent(response);
        for (Header header : response.getAllHeaders()) {
            retVal.headers.put(header.getName(), header.getValue());
        }
    }
    client.close();
    return retVal;
}

From source file:com.evolveum.midpoint.report.impl.ReportNodeUtils.java

private static HttpRequestBase buildHttpRequest(String typeOfRequest) {
    HttpRequestBase httpRequest;/*w w w  .jav a  2  s.  c  o m*/

    if (HttpDelete.METHOD_NAME.equals(typeOfRequest)) {
        httpRequest = new HttpDelete();
    } else {
        httpRequest = new HttpGet();
    }
    return httpRequest;
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.RestRequest.java

private HttpDelete createHttpDeleteRequest() {
    final HttpDelete result = new HttpDelete();
    result.setURI(getUri());/*from   w  w w  .  ja v a  2  s  .co  m*/
    appendHeaders(result);
    return result;
}