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

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

Introduction

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

Prototype

@Override
public String getStatusText() 

Source Link

Document

Returns the status text (or "reason phrase") associated with the latest response.

Usage

From source file:com.arjuna.qa.junit.HttpUtils.java

public static HttpMethodBase accessURL(URL url, String realm, int expectedHttpCode, Header[] hdrs, int type)
        throws Exception {
    HttpClient httpConn = new HttpClient();
    HttpMethodBase request = createMethod(url, type);

    int hdrCount = hdrs != null ? hdrs.length : 0;
    for (int n = 0; n < hdrCount; n++)
        request.addRequestHeader(hdrs[n]);
    try {//from  w  w  w .j ava 2s .  com
        System.err.println("Connecting to: " + url);
        String userInfo = url.getUserInfo();

        if (userInfo != null) {
            UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
            httpConn.getState().setCredentials(realm, url.getHost(), auth);
        }
        System.err.println("RequestURI: " + request.getURI());
        int responseCode = httpConn.executeMethod(request);
        String response = request.getStatusText();
        System.err.println("responseCode=" + responseCode + ", response=" + response);
        String content = request.getResponseBodyAsString();
        System.err.println(content);
        // Validate that we are seeing the requested response code
        if (responseCode != expectedHttpCode) {
            throw new IOException("Expected reply code:" + expectedHttpCode + ", actual=" + responseCode);
        }
    } catch (IOException e) {
        throw e;
    }
    return request;
}

From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java

private ListResponse executeListRequest(final HttpMethodBase request) throws IOException {
    int status = getClient().executeMethod(request);
    return parseListResponse(status, request.getStatusText(), request.getResponseBodyAsStream(),
            request.getResponseCharSet());
}

From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java

private SimpleResponse executeSimpleRequest(final HttpMethodBase request) throws IOException {
    int status = getClient().executeMethod(request);
    return parseSimpleResponse(status, request.getStatusText(), request.getResponseBodyAsStream(),
            request.getResponseCharSet());
}

From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java

private DownloadResponse executeDownloadRequest(final HttpMethodBase request, final File outputFile)
        throws IOException {
    int status = getClient().executeMethod(request);
    return parseDownloadResponse(status, request.getStatusText(), request.getResponseBodyAsStream(),
            outputFile);/*from  w  ww.j a  va  2 s  .  c  om*/
}

From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java

private DetailedResponse executeDetailedRequest(final HttpMethodBase request,
        final ResponseProgressListener listener) throws IOException {
    int status = getClient().executeMethod(request);
    return parseDetailedResponse(status, request.getStatusText(), request.getResponseBodyAsStream(),
            request.getResponseCharSet(), listener);
}

From source file:jeeves.utils.XmlRequest.java

private String getReceivedData(HttpMethodBase httpMethod, byte[] response) {
    StringBuilder receivedData = new StringBuilder();

    try {/*ww w. j a  va2s.c o  m*/
        //--- if there is a connection error (the server is unreachable) this
        //--- call causes a NullPointerEx

        receivedData.append(httpMethod.getStatusText()).append("\r\r");

        for (Header h : httpMethod.getResponseHeaders()) {
            receivedData.append(h);
        }

        receivedData.append("\r\n");

        if (response != null) {
            receivedData.append(new String(response, "UTF8"));
        }
    } catch (Exception e) {
        receivedData.setLength(0);
    }

    return receivedData.toString();
}

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

/**
 * Determines basic information associted with an HTTP response.
 * <br/>For example: response status message, Content-Type, Content-Length
 * @param method the HttpMethod that was executed
 *//*from ww  w  . j a v  a 2  s . c  o m*/
private void determineResponseInfo(HttpMethodBase method) {
    this.getResponseInfo().setResponseMessage(method.getStatusText());
    this.getResponseInfo().setResponseHeaders(method.getResponseHeaders());
    Header contentTypeHeader = method.getResponseHeader("Content-Type");
    if (contentTypeHeader != null) {
        HeaderElement values[] = contentTypeHeader.getElements();
        // Expect only one header element to be there, no more, no less
        if (values.length == 1) {
            this.getResponseInfo().setContentType(values[0].getName());
            NameValuePair param = values[0].getParameterByName("charset");
            if (param != null) {
                // If invalid, an UnsupportedEncondingException will result
                this.getResponseInfo().setContentEncoding(param.getValue());
            }
        }
    }
    this.getResponseInfo().setContentLength(method.getResponseContentLength());
}

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  .j a  va 2  s  .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 {/*from w  w w .ja  v a  2  s  .  c  om*/
            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 {/* w  w  w  .j ava2s.co  m*/
            return method.getResponseBodyAsString(2048);
        } catch (IOException e) {
            S_LOGGER.debug("Error while loading response body", e);
        }
    }

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