Search in sources :

Example 36 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_OB__C1_XC__C2_AC__EE.

// C1 PC/OB; C1 XC; C2 AC; EE
@Test(expected = IOException.class)
public void testS_C1_PC_OB__C1_XC__C2_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();
    replay.getContent();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 37 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_FC_IB__C1_XC__C2_FC.

// C1 FC/IB; C1 XC; C2 FC.
@Test
public void testS_C1_FC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);
    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
    stream.close();
    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 38 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testGetContentEncoding.

@Test
public void testGetContentEncoding() throws Exception {
    String input = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.getContentEncoding(), nullValue());
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
    basic.setContentEncoding(StandardCharsets.UTF_8.name());
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.getContentEncoding().getValue(), is(StandardCharsets.UTF_8.name()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 39 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_IB__C2_PC_IB__C2_PC_IB.

// C1 PC/IB; C2 PC/IB; C1 PC/IB; C2 PC/IB - Back and forth before buffer overflow is OK.
@Test
public void testS_C1_PC_IB__C2_PC_IB__C2_PC_IB() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    InputStream stream1, stream2;
    String text;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);
    stream1 = replay.getContent();
    text = byteRead(stream1, 3);
    assertThat(text, is("012"));
    stream2 = replay.getContent();
    text = byteRead(stream2, 4);
    assertThat(text, is("0123"));
    text = byteRead(stream1, 3);
    assertThat(text, is("345"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 40 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_IB__C2_FC.

// C1 PC/IB; C2 FC.
@Test
public void testS_C1_PC_IB__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);
    stream = replay.getContent();
    text = byteRead(stream, 4);
    assertThat(text, is("0123"));
    stream.close();
    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Aggregations

BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)139 ByteArrayInputStream (java.io.ByteArrayInputStream)104 Test (org.junit.Test)89 InputStream (java.io.InputStream)60 IOException (java.io.IOException)24 HttpResponse (org.apache.http.HttpResponse)15 StatusLine (org.apache.http.StatusLine)12 BasicStatusLine (org.apache.http.message.BasicStatusLine)11 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)9 HttpException (org.apache.http.HttpException)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpContext (org.apache.http.protocol.HttpContext)8 URISyntaxException (java.net.URISyntaxException)7 Map (java.util.Map)7 URI (java.net.URI)6 Header (org.apache.http.Header)6 ProtocolVersion (org.apache.http.ProtocolVersion)6 HttpGet (org.apache.http.client.methods.HttpGet)6 ChunkedInputStream (org.apache.http.impl.io.ChunkedInputStream)6 ContentLengthInputStream (org.apache.http.impl.io.ContentLengthInputStream)6