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

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

Introduction

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

Prototype

public abstract Header getResponseHeader(String paramString);

Source Link

Usage

From source file:uk.org.openeyes.oink.facade.ITFacadeRoute.java

@Test
@DirtiesContext/*  w  ww.j  a  v a2  s.co  m*/
public void testSimplePatientGet() throws Exception {

    /*
     * Set up Third Party Service
     */

    // Specify what the third party service should receive
    IncomingMessageVerifier v = new IncomingMessageVerifier() {
        @Override
        public void isValid(OINKRequestMessage incoming) {
            Assert.assertEquals(uk.org.openeyes.oink.domain.HttpMethod.GET, incoming.getMethod());
            Assert.assertEquals("/Patient/2342452", incoming.getResourcePath());
            Assert.assertNull(incoming.getBody());
        }
    };

    // Specify what the third party service should return
    OINKResponseMessage mockResponse = new OINKResponseMessage();
    mockResponse.setStatus(200);
    mockResponse.setBody(buildFhirBodyFromResource("/example-messages/fhir/patient.json"));

    // Start the third party service
    SimulatedThirdParty thirdp = new SimulatedThirdParty(v, mockResponse);
    thirdp.start();

    /*
     * Make REST request
     */

    // Prepare request
    HttpClient client = new HttpClient();

    HttpMethod method = new GetMethod(testProperties.getProperty("facade.uri") + "/Patient/2342452");

    client.executeMethod(method);
    thirdp.close();

    /*
     * Process REST response
     */
    byte[] responseBody = method.getResponseBody();
    String responseJson = new String(responseBody);
    int responseCode = method.getStatusCode();
    String responseContentType = method.getResponseHeader("Content-Type").getValue();
    method.releaseConnection();

    if (thirdPartyAssertionError != null) {
        throw thirdPartyAssertionError;
    }

    Assert.assertEquals(HttpStatus.SC_OK, responseCode);
    Assert.assertEquals("application/json+fhir", responseContentType);
    Assert.assertEquals(IOUtils.toString(
            this.getClass().getResourceAsStream("/example-messages/fhir/patient.json"), "UTF-8"), responseJson);
}

From source file:ws.antonov.config.provider.HttpConfigProvider.java

protected ContentType determineContentType(HttpMethod getMethod) throws IOException {
    Header configContentType = getMethod.getResponseHeader(CONTENT_TYPE);
    Header configServerKind = getMethod.getResponseHeader("Server");
    if (configContentType.getValue().endsWith("xml"))
        return ContentType.XML;
    else if (configServerKind.getValue().contains("CouchDB"))
        return ContentType.COUCHDB;
    else if (configContentType.getValue().endsWith("js") || configContentType.getValue().endsWith("json"))
        return ContentType.JSON;
    else if (configContentType.getValue().endsWith("text/plain"))
        return ContentType.TEXT;
    else if (configContentType.getValue().endsWith("properties"))
        return ContentType.PROPS;
    else/*w  w  w . ja  v a  2s.  c o m*/
        return ContentType.PROTOBUF;
}