Search in sources :

Example 51 with DataWrapper

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse)

Example 52 with DataWrapper

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GZIPInputStream(java.util.zip.GZIPInputStream) Header(org.webpieces.httpparser.api.common.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) Charset(java.nio.charset.Charset) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 53 with DataWrapper

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 54 with DataWrapper

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) CompletableFuture(java.util.concurrent.CompletableFuture) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg)

Example 55 with DataWrapper

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());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Aggregations

DataWrapper (org.webpieces.data.api.DataWrapper)115 Test (org.junit.Test)47 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)22 ByteBuffer (java.nio.ByteBuffer)20 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)18 Header (org.webpieces.httpparser.api.common.Header)17 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)17 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)16 HttpData (org.webpieces.httpparser.api.dto.HttpData)15 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 Http2Request (com.webpieces.hpack.api.dto.Http2Request)10 StreamWriter (com.webpieces.http2engine.api.StreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)7 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)6 ArrayList (java.util.ArrayList)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)5