Search in sources :

Example 91 with DataWrapper

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

the class Requests method createData.

public static DataFrame createData(int streamId) {
    DataFrame data = new DataFrame(streamId, true);
    DataWrapper wrapByteArray = dataGen.wrapByteArray(new byte[] { 2, 3 });
    data.setData(wrapByteArray);
    return data;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 92 with DataWrapper

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

the class Level6RemoteFlowControl method splitDataFrame.

private List<DataTry> splitDataFrame(DataTry dataTry, long lengthToSend) {
    if (lengthToSend > Integer.MAX_VALUE)
        throw new IllegalStateException("bug, length to send should not be this large(per spec)=" + lengthToSend);
    int len = (int) lengthToSend;
    DataFrame dataFrame = dataTry.getDataFrame();
    DataWrapper data = dataFrame.getData();
    if (dataFrame.getPadding().getReadableSize() > 0)
        throw new UnsupportedOperationException("Splitting padding under these conditions would be" + " quite difficult so we skipped it.  perhaps stop using padding or" + " modify this code but some padding would have to go in one" + " DataFrame and the rest in the next as the window size is not large enough");
    List<? extends DataWrapper> split = dataGen.split(data, len);
    DataFrame dF1 = new DataFrame();
    dF1.setData(split.get(0));
    DataFrame dF2 = new DataFrame();
    dF2.setData(split.get(1));
    List<DataTry> tuple = new ArrayList<>();
    tuple.add(new DataTry(dataTry.getStream(), dF1, null, dataTry.isWasQueuedBefore()));
    tuple.add(new DataTry(dataTry.getStream(), dF2, dataTry.getFuture(), dataTry.isWasQueuedBefore()));
    return tuple;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) DataTry(com.webpieces.http2engine.impl.DataTry)

Example 93 with DataWrapper

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

the class Level7MarshalAndPing method sendFrameToSocket.

public CompletableFuture<Void> sendFrameToSocket(Http2Msg msg) {
    log.info(key + "sending frame down to socket(from client)=\n" + msg);
    DataWrapper data = parser.marshal(marshalState, msg);
    ByteBuffer buffer = ByteBuffer.wrap(data.createByteArray());
    return sendToSocket(buffer);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 94 with DataWrapper

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

the class Level7MarshalAndPing method goAway.

public CompletableFuture<Void> goAway(ShutdownConnection shutdown) {
    CancelReasonCode reason = shutdown.getReasonCode();
    byte[] bytes = shutdown.getReason().getBytes(StandardCharsets.UTF_8);
    DataWrapper debug = dataGen.wrapByteArray(bytes);
    GoAwayFrame frame = new GoAwayFrame();
    frame.setDebugData(debug);
    frame.setKnownErrorCode(reason.getErrorCode());
    CompletableFuture<Void> future1 = sendControlDataToSocket(frame);
    finalLayer.closeSocket(shutdown);
    return future1;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame)

Example 95 with DataWrapper

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

the class HeaderEncoding method createHeaderFrames.

private List<Http2Frame> createHeaderFrames(HasHeaderFragment initialFrame, List<Http2Header> headers, Encoder encoder, long maxFrameSize) {
    int maxSize = (int) maxFrameSize;
    if (maxFrameSize > Integer.MAX_VALUE)
        throw new IllegalStateException("max frame size too large for this hpack library");
    List<Http2Frame> headerFrames = new LinkedList<>();
    DataWrapper serializedHeaders = serializeHeaders(encoder, headers);
    HasHeaderFragment currentFrame = initialFrame;
    HasHeaderFragment lastFrame = currentFrame;
    DataWrapper dataLeftOver = serializedHeaders;
    while (dataLeftOver.getReadableSize() > 0) {
        lastFrame = currentFrame;
        int splitSize = Math.min(dataLeftOver.getReadableSize(), maxSize);
        List<? extends DataWrapper> split = dataGen.split(dataLeftOver, splitSize);
        DataWrapper fragment = split.get(0);
        currentFrame.setHeaderFragment(fragment);
        headerFrames.add(currentFrame);
        currentFrame = new ContinuationFrame();
        currentFrame.setStreamId(initialFrame.getStreamId());
        dataLeftOver = split.get(1);
    }
    //last frame is currentFrame so set end header
    lastFrame.setEndHeaders(true);
    return headerFrames;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2parser.api.dto.ContinuationFrame) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame) LinkedList(java.util.LinkedList)

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