Search in sources :

Example 1 with HttpStatefulParser

use of org.webpieces.httpparser.api.HttpStatefulParser in project webpieces by deanhiller.

the class TestHttp11Backpressure method create4SplitPayloads.

private List<ByteBuffer> create4SplitPayloads() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    req.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    HttpChunk chunk = new HttpChunk();
    String bodyStr = "hi here and there";
    DataWrapper data = DATA_GEN.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
    chunk.setBody(data);
    HttpLastChunk lastChunk = new HttpLastChunk();
    HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
    ByteBuffer buf1 = parser.marshalToByteBuffer(req);
    ByteBuffer buf2 = parser.marshalToByteBuffer(chunk);
    ByteBuffer buf3 = parser.marshalToByteBuffer(lastChunk);
    byte[] part1 = new byte[10];
    byte[] part2 = new byte[buf1.remaining()];
    buf1.get(part1);
    int toWrite = buf1.remaining();
    buf1.get(part2, 0, toWrite);
    buf2.get(part2, toWrite, part2.length - toWrite);
    byte[] part3 = new byte[buf2.remaining() + 2];
    int toWrite2 = buf2.remaining();
    buf2.get(part3, 0, toWrite2);
    buf3.get(part3, toWrite2, 2);
    byte[] part4 = new byte[buf3.remaining()];
    buf3.get(part4);
    List<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.wrap(part1));
    buffers.add(ByteBuffer.wrap(part2));
    buffers.add(ByteBuffer.wrap(part3));
    buffers.add(ByteBuffer.wrap(part4));
    return buffers;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) DataWrapper(org.webpieces.data.api.DataWrapper) HttpLastChunk(org.webpieces.httpparser.api.dto.HttpLastChunk) Header(org.webpieces.httpparser.api.common.Header) HttpStatefulParser(org.webpieces.httpparser.api.HttpStatefulParser) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk)

Example 2 with HttpStatefulParser

use of org.webpieces.httpparser.api.HttpStatefulParser in project webpieces by deanhiller.

the class TestHttp1Backpressure method create4BuffersWith3Messags.

private List<ByteBuffer> create4BuffersWith3Messags(Http2Response response1, HttpChunk response2, HttpLastChunk lastChunk) {
    HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
    HttpResponse resp1 = Http2ToHttp11.translateResponse(response1);
    ByteBuffer buf1 = parser.marshalToByteBuffer(resp1);
    ByteBuffer buf2 = parser.marshalToByteBuffer(response2);
    ByteBuffer buf3 = parser.marshalToByteBuffer(lastChunk);
    byte[] part1 = new byte[10];
    byte[] part2 = new byte[buf1.remaining()];
    buf1.get(part1);
    int toWrite = buf1.remaining();
    buf1.get(part2, 0, toWrite);
    buf2.get(part2, toWrite, part2.length - toWrite);
    byte[] part3 = new byte[buf2.remaining() + 2];
    int toWrite2 = buf2.remaining();
    buf2.get(part3, 0, toWrite2);
    buf3.get(part3, toWrite2, 2);
    byte[] part4 = new byte[buf3.remaining()];
    buf3.get(part4);
    List<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.wrap(part1));
    buffers.add(ByteBuffer.wrap(part2));
    buffers.add(ByteBuffer.wrap(part3));
    buffers.add(ByteBuffer.wrap(part4));
    return buffers;
}
Also used : HttpStatefulParser(org.webpieces.httpparser.api.HttpStatefulParser) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) ByteBuffer(java.nio.ByteBuffer)

Example 3 with HttpStatefulParser

use of org.webpieces.httpparser.api.HttpStatefulParser in project webpieces by deanhiller.

the class TestHttp1Backpressure method create3BuffersWithTwoMessags.

private List<ByteBuffer> create3BuffersWithTwoMessags(Http2Response response1, HttpData response2) {
    HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
    HttpResponse resp1 = Http2ToHttp11.translateResponse(response1);
    ByteBuffer buf1 = parser.marshalToByteBuffer(resp1);
    ByteBuffer buf2 = parser.marshalToByteBuffer(response2);
    byte[] part1 = new byte[10];
    byte[] part2 = new byte[buf1.remaining()];
    buf1.get(part1);
    int toWrite = buf1.remaining();
    buf1.get(part2, 0, toWrite);
    buf2.get(part2, toWrite, part2.length - toWrite);
    byte[] part3 = new byte[buf2.remaining()];
    buf2.get(part3);
    List<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.wrap(part1));
    buffers.add(ByteBuffer.wrap(part2));
    buffers.add(ByteBuffer.wrap(part3));
    return buffers;
}
Also used : HttpStatefulParser(org.webpieces.httpparser.api.HttpStatefulParser) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) ByteBuffer(java.nio.ByteBuffer)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 TwoPools (org.webpieces.data.api.TwoPools)3 HttpStatefulParser (org.webpieces.httpparser.api.HttpStatefulParser)3 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)2 DataWrapper (org.webpieces.data.api.DataWrapper)1 Header (org.webpieces.httpparser.api.common.Header)1 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)1 HttpLastChunk (org.webpieces.httpparser.api.dto.HttpLastChunk)1 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)1