Search in sources :

Example 26 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 27 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 28 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)

Example 29 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 30 with DataWrapper

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

the class PushPromiseMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    PushPromiseFrame castFrame = (PushPromiseFrame) frame;
    int originalStreamId = castFrame.getPromisedStreamId();
    int streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your promisedStreamId is too large per spec. frame=" + frame);
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    ByteBuffer prelude = bufferPool.nextBuffer(4);
    prelude.putInt(castFrame.getPromisedStreamId());
    prelude.flip();
    DataWrapper headersDW = castFrame.getHeaderFragment();
    DataWrapper finalDW = dataGen.chainDataWrappers(dataGen.wrapByteBuffer(prelude), headersDW);
    DataWrapper payload = PaddingUtil.padDataIfNeeded(finalDW, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) ByteBuffer(java.nio.ByteBuffer)

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