Search in sources :

Example 1 with ConnectionException

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

the class TestC5x1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveEndStream.

/**
 * An endpoint MUST NOT send frames other than PRIORITY on a closed stream. An endpoint
 * that receives any frame other than PRIORITY after receiving a RST_STREAM MUST
 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an
 * endpoint that receives any frames after receiving a frame with the
 * -----END_STREAM flag---- set MUST treat that as a connection error (Section 5.4.1) of
 * type STREAM_CLOSED, unless the frame is permitted as described below.
 */
@Test
public void testSection5_1ReceiveBadFrameAfterReceiveEndStream() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendEosResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    mockChannel.write(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:" + "(CLOSED_STREAM) Stream must have been closed as it no longer exists.  " + "high mark=1  your frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    // send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 2 with ConnectionException

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

the class TestC5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY on a
 * stream in this state MUST be treated as a connection
 * error (Section 5.4.1) of type PROTOCOL_ERROR.
 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setIncomingRespDefault(XFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Request request = sendRequestToServer(listener1);
    Http2Push push = sendPushFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
    mockChannel.write(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
    ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 3 with ConnectionException

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

the class TestS4FrameSizeAndHeaders method testSection4_3BadDecompression.

/**
 *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
 */
@Test
public void testSection4_3BadDecompression() {
    String badHeaderFrame = // length
    "00 00 10" + // type
    "01" + // flags (ack)
    "05" + // R + streamid
    "00 00 00 01" + // payload
    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
    // endOfStream=false
    mockChannel.sendHexBack(badHeaderFrame);
    // no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertTrue(mockListener.isClosed());
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream1:(HEADER_DECODE) Error from hpack library", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 4 with ConnectionException

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

the class TestS4FrameSizeAndHeaders method testBadSizePriorityFrame.

/**
 *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
 */
@Test
public void testBadSizePriorityFrame() {
    String priorityFrame = // length
    "00 00 06" + // type
    "02" + // flags
    "00" + // R + streamid
    "00 00 00 01" + // stream dependency
    "80 00 00 04" + // weight
    "05 00";
    // endOfStream=false
    mockChannel.sendHexBack(priorityFrame);
    // no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertTrue(mockListener.isClosed());
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream1:(FRAME_SIZE_INCORRECT) priority size not 5 and instead is=6", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 5 with ConnectionException

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

the class SettingsMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int payloadLength = frameHeaderData.getPayloadLength();
    int streamId = frameHeaderData.getStreamId();
    SettingsFrame frame = new SettingsFrame();
    super.unmarshalFrame(state, frame);
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setAck((flags & 0x1) == 0x1);
    if (frame.isAck()) {
        if (payloadLength != 0) {
            throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "size of payload of a settings frame ack must be 0 but was=" + payloadLength);
        }
    } else if (payloadLength % 6 != 0) {
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "payload size must be a multiple of 6 but was=" + state.getFrameHeaderData().getPayloadLength());
    } else if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "settings frame had stream id=" + streamId);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
    List<Http2Setting> settingsList = unmarshal(payloadByteBuffer);
    frame.setSettings(settingsList);
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) 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