Example usage for org.apache.http.entity BasicHttpEntity BasicHttpEntity

List of usage examples for org.apache.http.entity BasicHttpEntity BasicHttpEntity

Introduction

In this page you can find the example usage for org.apache.http.entity BasicHttpEntity BasicHttpEntity.

Prototype

public BasicHttpEntity() 

Source Link

Usage

From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java

private CloseableHttpResponse getAccessTokenReponse() throws IOException {
    CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
    String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("accesstoken-response.json");
    BasicHttpEntity responseEntity = new BasicHttpEntity();
    responseEntity.setContent(/*  w w  w .  j a  v a2s .  co m*/
            new ByteArrayInputStream(getContent(dcrResponseFile).getBytes(StandardCharsets.UTF_8.name())));
    responseEntity.setContentType(TestUtils.CONTENT_TYPE);
    mockDCRResponse.setEntity(responseEntity);
    mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK"));
    return mockDCRResponse;
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_OB__C2_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;// w  w  w .jav a 2 s. c o m
    CappedBufferHttpEntity replay;
    InputStream stream;
    String text;

    try {
        basic = new BasicHttpEntity();
        basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
        replay = new CappedBufferHttpEntity(basic, 5);

        stream = replay.getContent();
        text = byteRead(stream, 7);
        assertThat(text, is("0123456"));
        stream.close();
        fail("Expected IOException");
    } catch (IOException e) {
        // Expected.
    }
}

From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java

@Test
public void testS_C1_PC_OB__C2_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;/*from   w  w  w.j  a v a 2  s . co  m*/
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);

    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();

    try {
        replay.getContent();
        fail("Expected IOException");
    } catch (IOException e) {
        // Expected.
    }
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_PC_OB__C2_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;//w  w  w .  j a v  a  2  s .  c  o m
    CappedBufferHttpEntity replay;
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 5);

    stream = replay.getContent();
    try {
        text = blockRead(stream, UTF8, 7, 2);
        fail("Expected IOExceptin");
    } catch (IOException e) {
        // expected
    }
}

From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java

private CloseableHttpResponse getValidationResponse() throws UnsupportedEncodingException {
    ValidationResponce response = new ValidationResponce();
    response.setDeviceId("1234");
    response.setDeviceType("testdevice");
    response.setJWTToken("1234567788888888");
    response.setTenantId(-1234);/*from ww w .  j av  a  2s .  c om*/
    Gson gson = new Gson();
    String jsonReponse = gson.toJson(response);
    CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
    BasicHttpEntity responseEntity = new BasicHttpEntity();
    responseEntity.setContent(new ByteArrayInputStream(jsonReponse.getBytes(StandardCharsets.UTF_8.name())));
    responseEntity.setContentType(TestUtils.CONTENT_TYPE);
    mockDCRResponse.setEntity(responseEntity);
    mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK"));
    return mockDCRResponse;
}

From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java

@Test
public void testB_C1_PC_OB__C2_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;/*ww  w.  ja v  a2s. c  om*/
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);

    stream = replay.getContent();
    text = blockRead(stream, UTF8, 7, 2);
    assertThat(text, is("0123456"));
    stream.close();

    try {
        replay.getContent();
        fail("Expected IOException");
    } catch (IOException e) {
        // Expected.
    }
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;/*from w ww.  j  av  a2 s .c o m*/
    CappedBufferHttpEntity replay;
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);

    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();

    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
}

From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java

private CloseableHttpResponse getInvalidResponse() throws UnsupportedEncodingException {
    CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
    BasicHttpEntity responseEntity = new BasicHttpEntity();
    responseEntity//from w ww.j a va 2  s .  co m
            .setContent(new ByteArrayInputStream("invalid response".getBytes(StandardCharsets.UTF_8.name())));
    responseEntity.setContentType(TestUtils.CONTENT_TYPE);
    mockDCRResponse.setEntity(responseEntity);
    mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 400, "Bad Request"));
    return mockDCRResponse;
}

From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;/* ww w .  ja  v a 2 s  . c o  m*/
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);

    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();

    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
}