use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestRequestParsing method testPartialHttpMessage.
@Test
public void testPartialHttpMessage() {
HttpRequest request = createPostRequest();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
byte[] firstPart = new byte[10];
byte[] secondPart = new byte[payload.length - firstPart.length];
//let's split the payload up into two pieces
System.arraycopy(payload, 0, firstPart, 0, firstPart.length);
System.arraycopy(payload, firstPart.length, secondPart, 0, secondPart.length);
DataWrapper data1 = dataGen.wrapByteArray(firstPart);
DataWrapper data2 = dataGen.wrapByteArray(secondPart);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(0, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
HttpPayload httpMessage = memento.getParsedMessages().get(0);
HttpRequest req = (HttpRequest) httpMessage;
Assert.assertEquals(request.getRequestLine(), req.getRequestLine());
Assert.assertEquals(request.getHeaders(), req.getHeaders());
Assert.assertEquals(request, httpMessage);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestResponseParsing method testHalfThenTwoHalvesNext.
/**
* Send in 1/2 first http message and then send in
* next 1/2 AND 1/2 of second message TOGETHER in 2nd
* payload of bytes to make sure it is handled correctly
* and then finally last 1/2
*/
@Test
public void testHalfThenTwoHalvesNext() {
HttpResponse request = createOkResponse();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
byte[] first = new byte[20];
byte[] second = new byte[payload.length];
byte[] third = new byte[payload.length - first.length];
System.arraycopy(payload, 0, first, 0, first.length);
System.arraycopy(payload, first.length, second, 0, payload.length - first.length);
System.arraycopy(payload, 0, second, payload.length - first.length, first.length);
System.arraycopy(payload, first.length, third, 0, third.length);
DataWrapper data1 = dataGen.wrapByteArray(first);
DataWrapper data2 = dataGen.wrapByteArray(second);
DataWrapper data3 = dataGen.wrapByteArray(third);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(0, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
memento = parser.parse(memento, data3);
Assert.assertEquals(1, memento.getParsedMessages().size());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestResponseParsing method test2AndHalfHttpMessages.
@Test
public void test2AndHalfHttpMessages() {
HttpResponse response = createOkResponse();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, response));
byte[] first = new byte[2 * payload.length + 20];
byte[] second = new byte[payload.length - 20];
System.arraycopy(payload, 0, first, 0, payload.length);
System.arraycopy(payload, 0, first, payload.length, payload.length);
System.arraycopy(payload, 0, first, 2 * payload.length, 20);
System.arraycopy(payload, 20, second, 0, second.length);
DataWrapper data1 = dataGen.wrapByteArray(first);
DataWrapper data2 = dataGen.wrapByteArray(second);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(2, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method writeFrame.
public void writeFrame(Http2Frame frame) {
DataWrapper data = frameParser.marshal(frame);
byte[] bytes = data.createByteArray();
if (bytes.length == 0)
throw new IllegalArgumentException("how do you marshal to 0 bytes...WTF");
ByteBuffer buf = ByteBuffer.wrap(bytes);
listener.incomingData(this, buf);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level2ParsingAndRemoteSettings method parseImpl.
public CompletableFuture<Void> parseImpl(DataWrapper newData) {
parsingState = lowLevelParser.unmarshal(parsingState, newData);
List<Http2Msg> parsedMessages = parsingState.getParsedFrames();
CompletableFuture<Void> future = CompletableFuture.completedFuture((Void) null);
for (Http2Msg lowLevelFrame : parsedMessages) {
future = future.thenCompose(v -> {
return process(lowLevelFrame);
});
}
return future;
}
Aggregations