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

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

Introduction

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

Prototype

@Override
public Header getResponseHeader(String headerName) 

Source Link

Document

Gets the response header associated with the given name.

Usage

From source file:com.cyberway.issue.crawler.writer.WARCWriterProcessor.java

/**
 * Save a header from the given HTTP operation into the 
 * provider headers under a new name/*from   w  w w.j a  v a 2 s.  c o  m*/
 * 
 * @param origName header name to get if present
 * @param method http operation containing headers
 */
protected void saveHeader(String origName, HttpMethodBase method, ANVLRecord headers, String newName) {
    Header header = method.getResponseHeader(origName);
    if (header != null) {
        headers.addLabelValue(newName, header.getValue());
    }
}

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 {/*www.  j ava  2s . co  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 w w w  . jav a 2 s .  c o m
            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 {//from   w  w w.  j av  a  2  s. c  o m
            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.network.bigswitch.BigSwitchBcfApi.java

private String checkResponse(final HttpMethodBase m, final String errorMessageBase)
        throws BigSwitchBcfApiException, IllegalArgumentException {
    String customErrorMsg = null;
    if (m.getStatusCode() == HttpStatus.SC_OK) {
        String hash = "";
        if (m.getResponseHeader(HASH_MATCH) != null) {
            hash = m.getResponseHeader(HASH_MATCH).getValue();
            set_hash(hash);// w ww . j a  v  a2  s .c om
        }
        return hash;
    }
    if (m.getStatusCode() == HttpStatus.SC_CONFLICT) {
        if (m instanceof GetMethod) {
            return HASH_CONFLICT;
        }
        throw new BigSwitchBcfApiException("BCF topology sync required", true);
    }
    if (m.getStatusCode() == HttpStatus.SC_SEE_OTHER) {
        isMaster = false;
        set_hash(HASH_IGNORE);
        return HASH_IGNORE;
    }
    if (m.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        if (m instanceof DeleteMethod) {
            return "";
        }
    }
    if (m.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
        customErrorMsg = " Invalid data in BCF request";
        throw new IllegalArgumentException(customErrorMsg);
    }
    String errorMessage = responseToErrorMessage(m);
    m.releaseConnection();
    S_LOGGER.error(errorMessageBase + errorMessage);
    throw new BigSwitchBcfApiException(errorMessageBase + errorMessage + customErrorMsg);
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private String getFullContentType(HttpMethodBase method) {
    Header contentTypeHeader = method.getResponseHeader("Content-Type");
    return getFullContentType(contentTypeHeader);
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private String getContentType(HttpMethodBase method) {
    Header contentTypeHeader = method.getResponseHeader("Content-Type");
    return getContentType(contentTypeHeader);
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private String getContentBoundary(HttpMethodBase method) {
    Header contentTypeHeader = method.getResponseHeader("Content-Type");
    return getContentBoundary(contentTypeHeader);
}

From source file:com.xmlcalabash.library.ApacheHttpRequest.java

private String getContentCharset(HttpMethodBase method) {
    Header contentTypeHeader = method.getResponseHeader("Content-Type");
    return getContentCharset(contentTypeHeader);
}

From source file:com.esri.gpt.framework.http.HttpClientRequest.java

/**
 * Gets the HTTP response stream.// w  w w. j a  va  2  s. c om
 * @param method the HTTP method
 * @return the response stream
 * @throws IOException if an i/o exception occurs 
 */
private InputStream getResponseStream(HttpMethodBase method) throws IOException {
    // Check is Content-Encoding is gzip
    Header hdr = method.getResponseHeader("Content-Encoding");
    if (hdr != null && "gzip".equals(hdr.getValue())) {
        return new GZIPInputStream(method.getResponseBodyAsStream());
    }
    return method.getResponseBodyAsStream();
}