Search in sources :

Example 21 with AsyncEntityProducer

use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.

the class TestStringAsyncEntityProducer method testTextContent.

@Test
public void testTextContent() throws Exception {
    final AsyncEntityProducer producer = new StringAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
    Assertions.assertEquals(-1, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 22 with AsyncEntityProducer

use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.

the class TestAbstractCharAsyncEntityProducer method testProduceDataNoBuffering.

@Test
public void testProduceDataNoBuffering() throws Exception {
    final AsyncEntityProducer producer = new ChunkCharAsyncEntityProducer(256, 0, ContentType.TEXT_PLAIN, "this", "this and that");
    Assertions.assertEquals(-1, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertTrue(byteChannel.isOpen());
    Assertions.assertEquals("this", byteChannel.dump(StandardCharsets.US_ASCII));
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("this and that", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 23 with AsyncEntityProducer

use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.

the class TestAsyncEntityProducers method testPathEntityProducerWithTrailers.

@Test
public void testPathEntityProducerWithTrailers() throws IOException {
    final Path path = Paths.get("src/test/resources/test-ssl.txt");
    final Header header1 = new BasicHeader("Tailer1", "Value1");
    final Header header2 = new BasicHeader("Tailer2", "Value2");
    final AsyncEntityProducer producer = AsyncEntityProducers.create(path, ContentType.APPLICATION_OCTET_STREAM, header1, header2);
    try {
        Assertions.assertTrue(producer.isChunked());
        Assertions.assertEquals(-1, producer.getContentLength());
        Assertions.assertEquals(ContentType.APPLICATION_OCTET_STREAM.toString(), producer.getContentType());
    } finally {
        producer.releaseResources();
    }
}
Also used : Path(java.nio.file.Path) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) Test(org.junit.jupiter.api.Test)

Example 24 with AsyncEntityProducer

use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.

the class TestBasicAsyncEntityProducer method testTextContent.

@Test
public void testTextContent() throws Exception {
    final AsyncEntityProducer producer = new BasicAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
    Assertions.assertEquals(3, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 25 with AsyncEntityProducer

use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.

the class TestBasicAsyncEntityProducer method testBinaryContent.

@Test
public void testBinaryContent() throws Exception {
    final AsyncEntityProducer producer = new BasicAsyncEntityProducer(new byte[] { 'a', 'b', 'c' }, ContentType.DEFAULT_BINARY);
    Assertions.assertEquals(3, producer.getContentLength());
    Assertions.assertEquals(ContentType.DEFAULT_BINARY.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncEntityProducer (org.apache.hc.core5.http.nio.AsyncEntityProducer)27 DataStreamChannel (org.apache.hc.core5.http.nio.DataStreamChannel)18 Test (org.junit.jupiter.api.Test)16 WritableByteChannelMock (org.apache.hc.core5.http.WritableByteChannelMock)14 BasicDataStreamChannel (org.apache.hc.core5.http.nio.BasicDataStreamChannel)14 IOException (java.io.IOException)8 HttpException (org.apache.hc.core5.http.HttpException)8 HttpResponse (org.apache.hc.core5.http.HttpResponse)8 HttpRequest (org.apache.hc.core5.http.HttpRequest)7 Header (org.apache.hc.core5.http.Header)6 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)6 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)6 EntityDetails (org.apache.hc.core5.http.EntityDetails)5 ByteBuffer (java.nio.ByteBuffer)4 Path (java.nio.file.Path)4 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)4 List (java.util.List)3 AsyncDataConsumer (org.apache.hc.core5.http.nio.AsyncDataConsumer)3 AsyncServerExchangeHandler (org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)3 CapacityChannel (org.apache.hc.core5.http.nio.CapacityChannel)3