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

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

Introduction

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

Prototype

@Override
public byte[] getResponseBody() throws IOException 

Source Link

Document

Returns the response body of the HTTP method, if any, as an array of bytes.

Usage

From source file:org.apache.manifoldcf.examples.ManifoldCFAPIConnect.java

/** Perform an API DELETE operation.
*@param restPath is the URL path of the REST object, starting with "/".
*@return the json response.//from   w w w  .j  a  v a 2s .co  m
*/
public String performAPIRawDeleteOperation(String restPath) throws IOException {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(formURL(restPath));
    int response = client.executeMethod(method);
    byte[] responseData = method.getResponseBody();
    // We presume that the data is utf-8, since that's what the API
    // uses throughout.
    String responseString = new String(responseData, "utf-8");
    if (response != HttpStatus.SC_OK)
        throw new IOException("API http error; expected " + HttpStatus.SC_OK + ", saw "
                + Integer.toString(response) + ": " + responseString);
    return responseString;
}