Search in sources :

Example 11 with ConnectionException

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

the class HeadersMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    HeadersFrame castFrame = (HeadersFrame) frame;
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    if (castFrame.isPriority())
        value |= 0x20;
    DataWrapper preludeDW;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    if (priorityDetails != null) {
        preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
    } else {
        preludeDW = DATA_GEN.emptyWrapper();
    }
    DataWrapper unpadded = DATA_GEN.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
    DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 12 with ConnectionException

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

the class SettingsMarshaller method validateMaxFrameSize.

private void validateMaxFrameSize(long value) {
    // frame size must be between 16384 and 2^24 - 1
    int min = 16384;
    int max = 1677215;
    if (value < min || value > max)
        throw new ConnectionException(CancelReasonCode.INVALID_SETTING, 0, "window size must be between " + min + " and " + max + " but was=" + value);
}
Also used : ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 13 with ConnectionException

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

the class SettingsMarshaller method validateWindowSize.

private void validateWindowSize(long value) {
    // 2^31 - 1 - max flow control window
    int min = 0;
    int max = 2147483647;
    if (value < min || value > max)
        throw new ConnectionException(CancelReasonCode.SETTINGS_WINDOW_SIZE_INVALID, 0, "window size must be between " + min + " and " + max + " but was=" + value);
}
Also used : ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 14 with ConnectionException

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

the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInIdleState.

/**
 * Receiving any frame other than HEADERS 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_1BadFrameReceivedInIdleState() {
    DataFrame dataFrame = new DataFrame(1, false);
    mockChannel.send(dataFrame);
    // no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertTrue(mockListener.isClosed());
    // 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: HttpSocket[Http2ChannelCache1]:stream1:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "Stream in idle state and received this frame which should not happen in idle state.  " + "frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 15 with ConnectionException

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

the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * reserved local
 *
 * A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
 * type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE 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() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    Http2Request request = Http2Requests.createRequest(1, true);
    mockChannel.send(request);
    PassedIn in = mockListener.getSingleRequest();
    ResponseStream stream = in.stream;
    Http2Push push = Http2Requests.createPush(request.getStreamId());
    stream.openPushStream().process(push);
    Http2Msg pushMsg = mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushMsg);
    // send bad frame in this state
    DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
    mockChannel.send(data);
    Assert.assertTrue(mockStream.isCancelled());
    // 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: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

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