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

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

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods TraceMethod 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.collectionspace.services.client.test.ServiceLayerTest.java

@Test
public void traceSupported() {
    if (logger.isDebugEnabled()) {
        logger.debug(BaseServiceTest.testBanner("traceSupported", CLASS_NAME));
    }/*from   w w  w.  ja v a 2 s .  c om*/
    String url = serviceClient.getBaseURL() + "collectionobjects";
    TraceMethod method = new TraceMethod(url);
    try {
        int statusCode = httpClient.executeMethod(method);

        if (logger.isDebugEnabled()) {
            logger.debug("traceSupported url=" + url + " status=" + statusCode);
            logger.debug("traceSupported response=" + new String(method.getResponseBody()));
            for (Header h : method.getResponseHeaders()) {
                logger.debug("traceSupported header name=" + h.getName() + " value=" + h.getValue());
            }
        }
        Assert.assertEquals(statusCode, HttpStatus.SC_METHOD_NOT_ALLOWED,
                "expected " + HttpStatus.SC_METHOD_NOT_ALLOWED);
    } catch (HttpException e) {
        logger.error("Fatal protocol violation: ", e);
    } catch (IOException e) {
        logger.error("Fatal transport error", e);
    } catch (Exception e) {
        logger.error("unknown exception ", e);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}