Search in sources :

Example 6 with DataWrapper

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

the class TestRequestBody method testBody.

@Test
public void testBody() {
    HttpDummyRequest request = createPostRequestWithBody();
    byte[] expected = request.getHttpData().getBody().createByteArray();
    byte[] data = unwrap(request);
    DataWrapper wrap1 = dataGen.wrapByteArray(data);
    Memento memento = parser.prepareToParse();
    memento = parser.parse(memento, wrap1);
    Assert.assertEquals(2, memento.getParsedMessages().size());
    HttpPayload msg = memento.getParsedMessages().get(0);
    Assert.assertEquals(request.getRequest(), msg);
    HttpData data1 = (HttpData) memento.getParsedMessages().get(1);
    DataWrapper body = data1.getBody();
    byte[] bodyBytesActual = body.createByteArray();
    Assert.assertArrayEquals(expected, bodyBytesActual);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) Test(org.junit.Test)

Example 7 with DataWrapper

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

the class TestRequestParsing method test2AndHalfHttpMessages.

@Test
public void test2AndHalfHttpMessages() {
    HttpRequest request = createPostRequest();
    byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
    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());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Test(org.junit.Test)

Example 8 with DataWrapper

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

the class TestRequestParsing 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() {
    HttpRequest request = createPostRequest();
    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());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Test(org.junit.Test)

Example 9 with DataWrapper

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

the class TestResponseParsing method testPartialHttpMessage.

@Test
public void testPartialHttpMessage() {
    HttpResponse response = createOkResponse();
    byte[] payload = unwrap(parser.marshalToByteBuffer(state, response));
    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);
    Assert.assertEquals(response, httpMessage);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) Test(org.junit.Test)

Example 10 with DataWrapper

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

the class StaticFileReader method sendHttpChunk.

private CompletableFuture<StreamWriter> sendHttpChunk(StreamWriter writer, BufferPool pool, ByteBuffer buf, Path file, boolean isEos) {
    DataWrapper data = wrapperFactory.wrapByteBuffer(buf);
    DataFrame frame = new DataFrame();
    frame.setEndOfStream(isEos);
    frame.setData(data);
    return writer.processPiece(frame).thenApply(w -> {
        buf.position(buf.limit());
        pool.releaseBuffer(buf);
        return w;
    });
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

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