Search in sources :

Example 21 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level5ClientStateMachine method sendPushToApp.

public XFuture<Void> sendPushToApp(Http2Push fullPromise) {
    int newStreamId = fullPromise.getPromisedStreamId();
    if (newStreamId % 2 == 1)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, logId, newStreamId, "Server sent bad push promise=" + fullPromise + " as new stream id is incorrect and is an odd number");
    ClientStream causalStream = (ClientStream) streamState.getStream(fullPromise, true);
    ClientPushStream stream = createPushStream(newStreamId, causalStream.getResponseListener());
    return firePushToClient(stream, fullPromise);
}
Also used : ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 22 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level6LocalFlowControl method fireDataToClient.

public XFuture<Void> fireDataToClient(Stream stream, StreamMsg payload) {
    if (!(payload instanceof DataFrame))
        return notifyListener.sendPieceToApp(stream, payload);
    DataFrame f = (DataFrame) payload;
    long frameLength = f.getTransmitFrameLength();
    if (frameLength > connectionLocalWindowSize) {
        throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
    } else if (frameLength > stream.getLocalWindowSize()) {
        throw new StreamException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
    }
    totalSent += frameLength;
    connectionLocalWindowSize -= frameLength;
    stream.incrementLocalWindow(-frameLength);
    log.info("received framelen=" + frameLength + " newConnectionWindowSize=" + connectionLocalWindowSize + " streamSize=" + stream.getLocalWindowSize() + " totalSent=" + totalSent);
    return notifyListener.sendPieceToApp(stream, payload).thenApply(c -> updateFlowControl(frameLength, stream));
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) StreamException(com.webpieces.http2.api.dto.error.StreamException)

Example 23 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class HeaderDecoding method addToHeaders.

private Object addToHeaders(List<Http2Header> headers, Consumer<Http2Header> knownHeaders, byte[] name, byte[] value, boolean sensitive, String logId, int streamId) {
    String h = new String(name);
    String v = new String(value);
    if (!h.equals(h.toLowerCase()))
        throw new ConnectionException(CancelReasonCode.HEADER_NOT_LOWER_CASE, logId, streamId, "header=" + h + " was not lower case in stream=" + streamId);
    Http2Header header = new Http2Header(h, v);
    headers.add(header);
    if (knownHeaders != null) {
        Http2HeaderName knownName = Http2HeaderName.lookup(h);
        if (knownName != null)
            knownHeaders.accept(header);
    }
    return null;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 24 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class GoAwayMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    GoAwayFrame frame = new GoAwayFrame();
    super.unmarshalFrame(state, frame);
    int streamId = state.getFrameHeaderData().getStreamId();
    if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "goaway frame had stream id=" + streamId);
    List<? extends DataWrapper> split = DATA_GEN.split(framePayloadData, 8);
    ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
    long lastStreamId = UnsignedData.getUnsignedInt(preludeBytes);
    long errorCode = UnsignedData.getUnsignedInt(preludeBytes);
    frame.setLastStreamId(lastStreamId);
    frame.setErrorCode(errorCode);
    frame.setDebugData(split.get(1));
    bufferPool.releaseBuffer(preludeBytes);
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
    return frame;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)

Example 25 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class PriorityMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 5)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "priority size not 5 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    PriorityFrame frame = new PriorityFrame();
    PriorityDetails priorityDetails = frame.getPriorityDetails();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    int firstInt = payloadByteBuffer.getInt();
    priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
    int streamDependency = firstInt & 0x7FFFFFFF;
    if (frame.getStreamId() == 0) {
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "priority cannot be streamid 0 and was=" + frame.getStreamId());
    } else if (streamDependency == frame.getStreamId()) {
        // Can't depend on self
        throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
    }
    priorityDetails.setStreamDependency(streamDependency);
    priorityDetails.setWeight((short) (payloadByteBuffer.get() & 0xFF));
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Aggregations

ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)26 DataWrapper (org.webpieces.data.api.DataWrapper)18 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)15 Test (org.junit.Test)13 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)8 ByteBuffer (java.nio.ByteBuffer)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)6 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)4 StreamException (com.webpieces.http2.api.dto.error.StreamException)3 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)3 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)3 PriorityDetails (com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2