Search in sources :

Example 56 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class Preface method verify.

public void verify() {
    buffer.flip();
    DataWrapper data = dataGen.wrapByteBuffer(buffer);
    String content = data.createStringFromUtf8(0, data.getReadableSize());
    if (!"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".equals(content))
        throw new IllegalStateException("preface incorrect=" + content);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 57 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class DataWrapperGeneratorImpl method splitChainedWrapper.

private List<DataWrapper> splitChainedWrapper(ChainedDataWrapper dataToRead, int splitAtPosition) {
    List<SliceableDataWrapper> wrappersInBegin = new ArrayList<>();
    List<SliceableDataWrapper> wrappersInEnd = new ArrayList<>();
    boolean foundSplit = false;
    List<SliceableDataWrapper> splitBuffers = null;
    for (SliceableDataWrapper wrapper : dataToRead.getWrappers()) {
        if (!foundSplit) {
            if (splitAtPosition == wrapper.getReadableSize()) {
                wrappersInBegin.add(wrapper);
                foundSplit = true;
            } else if (splitAtPosition < wrapper.getReadableSize()) {
                splitBuffers = splitSliceableWrapper(wrapper, splitAtPosition);
                wrappersInBegin.add(splitBuffers.get(0));
                wrappersInEnd.add(splitBuffers.get(1));
                foundSplit = true;
            } else {
                wrappersInBegin.add(wrapper);
                splitAtPosition = splitAtPosition - wrapper.getReadableSize();
            }
        } else {
            wrappersInEnd.add(wrapper);
        }
    }
    DataWrapper wrapper1;
    if (wrappersInBegin.size() > 0)
        wrapper1 = new ChainedDataWrapper(wrappersInBegin);
    else
        wrapper1 = EMPTY_WRAPPER;
    DataWrapper wrapper2;
    if (wrappersInEnd.size() > 0)
        wrapper2 = new ChainedDataWrapper(wrappersInEnd);
    else
        wrapper2 = EMPTY_WRAPPER;
    List<DataWrapper> finalTwo = new ArrayList<>();
    finalTwo.add(wrapper1);
    finalTwo.add(wrapper2);
    return finalTwo;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList)

Example 58 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class RecorderImpl method recordImpl.

public void recordImpl(ByteBuffer b) throws IOException {
    DataWrapper wrapper = gen.wrapByteBuffer(b);
    int size = wrapper.getReadableSize();
    ByteBuffer sizeBuf = ByteBuffer.allocate(4);
    sizeBuf.putInt(size);
    sizeBuf.flip();
    channel.write(sizeBuf);
    ByteBuffer shallowCopy = b.duplicate();
    channel.write(shallowCopy);
    byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6 };
    ByteBuffer trailer = ByteBuffer.wrap(data);
    channel.write(trailer);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 59 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class ChainedDataWrapper method createByteArray.

@Override
public byte[] createByteArray() {
    byte[] copy = new byte[getReadableSize()];
    int offset = 0;
    for (DataWrapper wrapper : wrappers) {
        byte[] data = wrapper.createByteArray();
        int size = wrapper.getReadableSize();
        System.arraycopy(data, 0, copy, offset, size);
        offset += size;
    }
    return copy;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 60 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class TestHttp11Basic method testSendTwoRequestsStreamFirst.

@Test
public void testSendTwoRequestsStreamFirst() throws InterruptedException, ExecutionException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    req.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "20"));
    mockChannel.write(req);
    PassedIn in1 = mockListener.getSingleRequest();
    byte[] buf = new byte[10];
    DataWrapper dataWrapper = dataGen.wrapByteArray(buf);
    HttpData data1 = new HttpData(dataWrapper, false);
    mockChannel.write(data1);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    DataWrapper dataWrapper2 = dataGen.wrapByteArray(buf);
    HttpData data2 = new HttpData(dataWrapper2, true);
    mockChannel.write(data2);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    mockChannel.write(req2);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //send back request2's response first!!!! BUT verify it does not go to client per http11 pipelining rules
    HttpResponse resp1 = Requests.createResponse(1);
    resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
    Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
    in1.stream.sendResponse(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    PassedIn in2 = mockListener.getSingleRequest();
    HttpResponse resp2 = Requests.createResponse(2);
    resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
    Http2Response headers2 = Http2Translations.responseToHeaders(resp2);
    in2.stream.sendResponse(headers2);
    HttpPayload payload2 = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp2, payload2);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

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