Search in sources :

Example 86 with DataWrapper

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

the class TestRequestParsing method testPartialHttpMessage.

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

Example 87 with DataWrapper

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

the class TestResponseParsing 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() {
    HttpResponse request = createOkResponse();
    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 : DataWrapper(org.webpieces.data.api.DataWrapper) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) Test(org.junit.Test)

Example 88 with DataWrapper

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

the class TestResponseParsing method test2AndHalfHttpMessages.

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

Example 89 with DataWrapper

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

the class MockHttp2Channel method writeFrame.

public void writeFrame(Http2Frame frame) {
    DataWrapper data = frameParser.marshal(frame);
    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 90 with DataWrapper

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

the class Level2ParsingAndRemoteSettings method parseImpl.

public CompletableFuture<Void> parseImpl(DataWrapper newData) {
    parsingState = lowLevelParser.unmarshal(parsingState, newData);
    List<Http2Msg> parsedMessages = parsingState.getParsedFrames();
    CompletableFuture<Void> future = CompletableFuture.completedFuture((Void) null);
    for (Http2Msg lowLevelFrame : parsedMessages) {
        future = future.thenCompose(v -> {
            return process(lowLevelFrame);
        });
    }
    return future;
}
Also used : Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) Http2Config(com.webpieces.http2engine.api.client.Http2Config) CompletableFuture(java.util.concurrent.CompletableFuture) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) HpackParser(com.webpieces.hpack.api.HpackParser) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) DataWrapper(org.webpieces.data.api.DataWrapper) StreamException(com.webpieces.http2parser.api.dto.error.StreamException) Logger(org.webpieces.util.logging.Logger) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) PingFrame(com.webpieces.http2parser.api.dto.PingFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) List(java.util.List) ReceivedGoAway(com.webpieces.http2engine.api.error.ReceivedGoAway) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) WindowUpdateFrame(com.webpieces.http2parser.api.dto.WindowUpdateFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) LoggerFactory(org.webpieces.util.logging.LoggerFactory) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg)

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