use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestS6_5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.
@Test
public void testSection6_5AckNonEmptyPayload() {
String badAckFrame = // length
"00 00 01" + // type
"04" + // flags (ack)
"01" + // R + streamid
"00 00 00 00" + //payload
"00";
//ack client frame
mockChannel.sendHexBack(badAckFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
Assert.assertTrue(mockChannel.isClosed());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestRequestBody method testPartialBody.
@Test
public void testPartialBody() {
HttpDummyRequest request = createPostRequestWithBody();
byte[] expected = request.getHttpData().getBody().createByteArray();
byte[] data = unwrap(request);
byte[] first = new byte[data.length - 20];
byte[] second = new byte[data.length - first.length];
System.arraycopy(data, 0, first, 0, first.length);
System.arraycopy(data, first.length, second, 0, second.length);
DataWrapper wrap1 = dataGen.wrapByteArray(first);
DataWrapper wrap2 = dataGen.wrapByteArray(second);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, wrap1);
Assert.assertEquals(ParsingState.BODY, memento.getUnParsedState().getCurrentlyParsing());
Assert.assertEquals(0, memento.getUnParsedState().getCurrentUnparsedSize());
HttpRequest httpRequest = memento.getParsedMessages().get(0).getHttpRequest();
Assert.assertEquals(request.getRequest(), httpRequest);
HttpData data1 = memento.getParsedMessages().get(1).getHttpData();
Assert.assertEquals(2, memento.getParsedMessages().size());
memento = parser.parse(memento, wrap2);
Assert.assertEquals(1, memento.getParsedMessages().size());
HttpData data2 = memento.getParsedMessages().get(0).getHttpData();
DataWrapper body = dataGen.chainDataWrappers(data1.getBody(), data2.getBody());
byte[] bodyBytesActual = body.createByteArray();
Assert.assertArrayEquals(expected, bodyBytesActual);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestBeans method testIncomingDataAndDataSeperate.
@Test
public void testIncomingDataAndDataSeperate() {
HttpDummyRequest req = Requests.createPostRequest("/postArray2", "user.accounts[1].name", "Account2Name", "user.accounts[1].color", "green", "user.accounts[2].addresses[0].number", "56", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller");
DataWrapperGenerator dataGen = DataWrapperGeneratorFactory.createDataWrapperGenerator();
HttpParser parser = HttpParserFactory.createParser(new BufferCreationPool());
MarshalState state = parser.prepareToMarshal();
ByteBuffer buffer = parser.marshalToByteBuffer(state, req.getRequest());
DataWrapper d1 = dataGen.wrapByteBuffer(buffer);
ByteBuffer buf2 = parser.marshalToByteBuffer(state, req.getData());
DataWrapper data = dataGen.chainDataWrappers(d1, dataGen.wrapByteBuffer(buf2));
// Split the body in half
List<? extends DataWrapper> split = dataGen.split(data, data.getReadableSize() - 20);
http11Socket.sendBytes(split.get(0));
http11Socket.sendBytes(split.get(1));
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
UserDto user = mockSomeLib.getUser();
Assert.assertEquals("D&D", user.getFirstName());
Assert.assertEquals(3, user.getAccounts().size());
Assert.assertEquals("Account2Name", user.getAccounts().get(1).getName());
Assert.assertEquals(56, user.getAccounts().get(2).getAddresses().get(0).getNumber());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockTcpChannel method write.
@Override
public CompletableFuture<Channel> write(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
memento = parser.parse(memento, data);
List<HttpPayload> parsedMessages = memento.getParsedMessages();
for (HttpPayload payload : parsedMessages) {
if (payload instanceof HttpResponse) {
sendResponse((HttpResponse) payload);
} else {
sendData((HttpData) payload);
}
}
return CompletableFuture.completedFuture(this);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class FullResponse method uncompressBodyAndAssertContainsString.
public void uncompressBodyAndAssertContainsString(String text) {
Header header = getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_ENCODING);
if (header == null)
throw new IllegalStateException("Body is not compressed as no CONTENT_ENCODING header field exists");
else if (!"gzip".equals(header.getValue()))
throw new IllegalStateException("Body has wrong compression type=" + header.getValue() + " in CONTENT_ENCODING header field");
DataWrapper wrapper = getBody();
byte[] compressed = wrapper.createByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(compressed);
byte[] out = new byte[10000];
DataWrapper output = dataGen.emptyWrapper();
try (GZIPInputStream str = new GZIPInputStream(in)) {
int read = 0;
while ((read = str.read(out)) > 0) {
ByteBuffer buffer = ByteBuffer.wrap(out, 0, read);
DataWrapper byteWrapper = dataGen.wrapByteBuffer(buffer);
output = dataGen.chainDataWrappers(output, byteWrapper);
out = new byte[10000];
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Charset charset = extractCharset();
String bodyAsString = output.createStringFrom(0, output.getReadableSize(), charset);
if (!bodyAsString.contains(text))
throw new IllegalStateException("Expected compressed body to contain='" + text + "' but body was=" + bodyAsString);
}
Aggregations