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

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

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods HeadMethod getResponseContentLength.

Prototype

public long getResponseContentLength() 

Source Link

Document

Return the length (in bytes) of the response body, as specified in a Content-Length header.

Usage

From source file:org.apache.hadoop.fs.swift.http.SwiftRestClient.java

/**
 * Returns object length/*from ww w .j  a  va 2 s .  c om*/
 *
 * @param uri file URI
 * @return object length
 * @throws SwiftException on swift-related issues
 * @throws IOException on network/IO problems
 */
public long getContentLength(URI uri) throws IOException {
    preRemoteCommand("getContentLength");
    return perform(uri, new HeadMethodProcessor<Long>() {
        @Override
        public Long extractResult(HeadMethod method) throws IOException {
            return method.getResponseContentLength();
        }

        @Override
        protected void setup(HeadMethod method) throws IOException {
            super.setup(method);
            method.addRequestHeader(NEWEST);
        }
    });
}

From source file:org.dataconservancy.dcs.access.http.DatastreamServletTest.java

public void testHead() throws Exception {
    // ServletTester has internal errors processing head requests so use http client

    String baseurl = servletContainer.createSocketConnector(true);

    HttpClient client = new HttpClient();

    HeadMethod head = new HeadMethod(baseurl + "/access/datastream/" + ds_entity.getId());
    int status = client.executeMethod(head);

    assertEquals(200, status);/*from   w  ww .  j a  va2s  . c o  m*/

    assertEquals(ds_entity.getSizeBytes(), head.getResponseContentLength());
    assertNotNull(head.getResponseHeader("ETag"));
    assertNotNull(head.getResponseHeader("Content-Type"));
    assertEquals("application/xbox", head.getResponseHeader("Content-Type").getValue());

    head = new HeadMethod(baseurl + "/access/datastream/doesnotexist");
    status = client.executeMethod(head);
    assertEquals(404, status);
}

From source file:org.dataconservancy.dcs.access.http.EntityServletTest.java

public void testHead() throws Exception {
    HttpClient client = new HttpClient();

    for (DcsEntity entity : entities) {
        HeadMethod head = new HeadMethod(entity.getId());

        int status = client.executeMethod(head);
        assertEquals(200, status);//from   w w  w  .  j  a  va2s . com

        assertEquals("application/xml", head.getResponseHeader("Content-Type").getValue());
        assertTrue(head.getResponseContentLength() > 0);
        assertNotNull(head.getResponseHeader("ETag"));
    }

    HeadMethod head = new HeadMethod(entities.get(0).getId() + "blah");
    int status = client.executeMethod(head);
    assertEquals(404, status);
}