Example usage for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString

List of usage examples for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString.

Prototype

public String getResponseBodyAsString(int maxlen) throws IOException 

Source Link

Document

Returns the response body of the HTTP method, if any, as a String .

Usage

From source file:com.cloud.network.bigswitch.BigSwitchVnsApi.java

private String responseToErrorMessage(HttpMethodBase method) {
    assert method.isRequestSent() : "no use getting an error message unless the request is sent";

    if ("text/html".equals(method.getResponseHeader(CONTENT_TYPE).getValue())) {
        // The error message is the response content
        // Safety margin of 1024 characters, anything longer is probably useless
        // and will clutter the logs
        try {//from  w w w . ja va2s.  com
            return method.getResponseBodyAsString(1024);
        } catch (IOException e) {
            s_logger.debug("Error while loading response body", e);
        }
    }

    // The default
    return method.getStatusText();
}

From source file:com.cloud.utils.rest.RESTServiceConnector.java

private String responseToErrorMessage(final HttpMethodBase method) {
    assert method.isRequestSent() : "no use getting an error message unless the request is sent";

    if (TEXT_HTML_CONTENT_TYPE.equals(method.getResponseHeader(CONTENT_TYPE).getValue())) {
        // The error message is the response content
        // Safety margin of 1024 characters, anything longer is probably useless
        // and will clutter the logs
        try {//w ww  . j a  va2  s.  c o  m
            return method.getResponseBodyAsString(BODY_RESP_MAX_LEN);
        } catch (final IOException e) {
            s_logger.debug("Error while loading response body", e);
        }
    }

    // The default
    return method.getStatusText();
}

From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java

private String responseToErrorMessage(final HttpMethodBase method) {
    assert method.isRequestSent() : "no use getting an error message unless the request is sent";

    if ("text/html".equals(method.getResponseHeader(CONTENT_TYPE).getValue())) {
        // The error message is the response content
        // Safety margin of 2048 characters, anything longer is probably useless
        // and will clutter the logs
        try {//from ww w .j  a va2 s  .  c om
            return method.getResponseBodyAsString(2048);
        } catch (IOException e) {
            S_LOGGER.debug("Error while loading response body", e);
        }
    }

    // The default
    return method.getStatusText();
}

From source file:com.cloud.network.nicira.NiciraNvpApi.java

private String responseToErrorMessage(HttpMethodBase method) {
    assert method.isRequestSent() : "no use getting an error message unless the request is sent";

    if ("text/html".equals(method.getResponseHeader("Content-Type").getValue())) {
        // The error message is the response content
        // Safety margin of 1024 characters, anything longer is probably useless
        // and will clutter the logs
        try {//w  w w  .  j a va 2s  . com
            return method.getResponseBodyAsString(1024);
        } catch (IOException e) {
            s_logger.debug("Error while loading response body", e);
        }
    }

    // The default
    return method.getStatusText();
}

From source file:org.apache.cloudstack.network.opendaylight.api.resources.Action.java

private String responseToErrorMessage(final HttpMethodBase method) {
    assert method.isRequestSent() : "no use getting an error message unless the request is sent";

    final Header contentTypeHeader = method.getResponseHeader(CONTENT_TYPE);
    if (contentTypeHeader != null && TEXT_HTML_CONTENT_TYPE.equals(contentTypeHeader.getValue())) {
        // The error message is the response content
        // Safety margin of 1024 characters, anything longer is probably
        // useless and will clutter the logs
        try {/*from ww  w.jav  a 2  s  .com*/
            return method.getResponseBodyAsString(BODY_RESP_MAX_LEN);
        } catch (IOException e) {
            s_logger.debug("Error while loading response body", e);
        }
    }

    // The default
    return method.getStatusText();
}