Example usage for org.apache.commons.httpclient.methods DeleteMethod getRequestHeaders

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getRequestHeaders

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod getRequestHeaders.

Prototype

@Override
public Header[] getRequestHeaders() 

Source Link

Document

Returns an array of the requests headers that the HTTP method currently has

Usage

From source file:com.funambol.json.api.dao.FunambolJSONApiDAO.java

protected String sendDeleteRequest(String REQUEST, long since, long until) throws IOOperationException {

    String response = null;/*from   www  . j  a  v  a2  s .  c  om*/
    DeleteMethod method = null;
    try {

        HttpClient httpClient = new HttpClient();

        method = new DeleteMethod(REQUEST);

        addSinceUntil(method, since, until);

        if (log.isTraceEnabled()) {
            log.trace("\nREQUEST: " + REQUEST + "");
        }
        if (this.sessionid != null) {
            method.setRequestHeader("Authorization", this.sessionid);
        }

        printHeaderFields(method.getRequestHeaders(), "REQUEST");

        int code = httpClient.executeMethod(method);

        response = method.getResponseBodyAsString();

        if (log.isTraceEnabled()) {
            log.trace("RESPONSE code: " + code);
        }
        printHeaderFields(method.getResponseHeaders(), "RESPONSE");

    } catch (Exception e) {
        throw new IOOperationException("Error GET Request ", e);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }

    return response;
}

From source file:org.dasein.persist.riak.RiakCache.java

@Override
public void remove(Transaction xaction, T item) throws PersistenceException {
    startCall("remove");
    try {/* w  w  w  .  jav  a2  s  .co m*/
        StringBuilder url = new StringBuilder();

        url.append(getEndpoint());
        url.append("buckets/");
        url.append(getBucket());
        url.append("/keys/");
        url.append(getKeyValue(item));

        HttpClient client = getClient();
        DeleteMethod delete = new DeleteMethod(url.toString());
        int code;

        try {
            if (wire.isDebugEnabled()) {
                try {
                    wire.debug(delete.getName() + " " + url.toString());
                    wire.debug("");
                    for (Header h : delete.getRequestHeaders()) {
                        wire.debug(h.getName() + ": " + h.getValue());
                    }
                    wire.debug("");
                } catch (Throwable ignore) {
                    // ignore
                }
            }
            code = client.executeMethod(delete);
        } catch (HttpException e) {
            throw new PersistenceException("HttpException during GET: " + e.getMessage());
        } catch (IOException e) {
            throw new PersistenceException("IOException during GET: " + e.getMessage());
        }
        try {
            String body = delete.getResponseBodyAsString();

            if (wire.isDebugEnabled()) {
                try {
                    wire.debug("----------------------------------------");
                    wire.debug("");
                    wire.debug(delete.getStatusLine().getStatusCode() + " "
                            + delete.getStatusLine().getReasonPhrase());
                    wire.debug("");
                    if (body != null) {
                        wire.debug(body);
                        wire.debug("");
                    }
                } catch (Throwable ignore) {
                    // ignore
                }
            }
            if (code != HttpStatus.SC_NO_CONTENT && code != HttpStatus.SC_NOT_FOUND) {
                throw new PersistenceException(code + ": " + body);
            }
            getCache().release(item);
        } catch (IOException e) {
            throw new PersistenceException(e);
        }
    } finally {
        endCall("remove");
    }
}