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);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class MockHttp2Channel method write.
public void write(Http2Msg msg) {
if (listener == null)
throw new IllegalStateException("Not connected so we cannot write back");
DataWrapper data = parser.marshal(marshalState, msg);
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 MockHttp2Channel method processData.
@SuppressWarnings("unchecked")
private CompletableFuture<Channel> processData(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
parser.unmarshal(unmarshalState, data);
List<Http2Msg> parsedFrames = unmarshalState.getParsedFrames();
return (CompletableFuture<Channel>) super.calledMethod(Method.INCOMING_FRAME, parsedFrames);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Level3ClntOutgoingSyncro method sendInitializationToSocket.
public CompletableFuture<Void> sendInitializationToSocket() {
//important, this forces the engine to a virtual single thread(each engine/socket has one virtual thread)
//this makes it very easy not to have bugs AND very easy to test AND for better throughput, you can
//just connect more sockets
log.info("sending preface");
DataWrapper prefaceData = dataGen.wrapByteArray(preface);
return finalLayer.sendPreface(prefaceData).thenCompose(v -> super.sendSettingsToSocket());
}
Aggregations