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

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

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods HeadMethod 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.sling.launchpad.webapp.integrationtest.servlets.HeadServletTest.java

@Test
public void htmlHead() throws IOException {
    final HeadMethod head = new HeadMethod(HTML_URL);
    final int status = H.getHttpClient().executeMethod(head);
    assertEquals(200, status);/*w  w w  . ja va 2 s.c om*/
    assertNull("Expecting null body", head.getResponseBody());
    assertCommonHeaders(head, "text/html");
}

From source file:org.apache.sling.launchpad.webapp.integrationtest.servlets.HeadServletTest.java

@Test
public void pngHead() throws IOException {
    final HeadMethod head = new HeadMethod(PNG_URL);
    final int status = H.getHttpClient().executeMethod(head);
    assertEquals(200, status);//w  w  w . j  a  v  a2s  . c o m
    assertNull("Expecting null body", head.getResponseBody());
    assertCommonHeaders(head, "image/png");
}

From source file:org.collectionspace.services.client.test.ServiceLayerTest.java

@Test
public void headSupported() {
    if (logger.isDebugEnabled()) {
        logger.debug(BaseServiceTest.testBanner("headSupported", CLASS_NAME));
    }//from   w w w  .j a v  a 2s  . c  o m
    String url = serviceClient.getBaseURL() + "intakes";
    HeadMethod method = new HeadMethod(url);
    try {
        int statusCode = httpClient.executeMethod(method);
        Assert.assertEquals(method.getResponseBody(), null, "expected null");
        if (logger.isDebugEnabled()) {
            logger.debug("headSupported url=" + url + " status=" + statusCode);
            for (Header h : method.getResponseHeaders()) {
                logger.debug("headSupported header name=" + h.getName() + " value=" + h.getValue());
            }
        }
        Assert.assertEquals(statusCode, HttpStatus.SC_OK, "expected " + HttpStatus.SC_OK);
    } 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();
    }
}