Search in sources :

Example 26 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.

the class Level7MarshalAndPing method goAway.

public XFuture<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());
    XFuture<Void> future1 = sendControlDataToSocket(frame);
    finalLayer.closeSocket(shutdown);
    return future1;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) CancelReasonCode(com.webpieces.http2.api.dto.error.CancelReasonCode) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)

Example 27 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.

the class TestC5x1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveRstStreamFrame.

/**
 * 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_1ReceiveBadFrameAfterReceiveRstStreamFrame() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResetFromServer(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) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 28 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.

the class TestC5x1StreamStates 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);
    // endOfStream=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: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());
    // send new request on closed connection
    MockResponseListener listener1 = new MockResponseListener();
    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 29 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.

the class GoAwayFrame method toString.

@Override
public String toString() {
    String debug = null;
    if (debugData != null)
        debug = "" + debugData.getReadableSize();
    String code = errorCode + "";
    Http2ErrorCode knownErrorCode = getKnownErrorCode();
    if (knownErrorCode != null)
        code = knownErrorCode + "";
    return "GoAwayFrame{" + super.toString() + ", lastStreamId=" + lastStreamId + ", errorCode=" + code + ", debugData.len=" + debug + "}";
}
Also used : Http2ErrorCode(com.webpieces.http2.api.dto.lowlevel.lib.Http2ErrorCode)

Aggregations

GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)27 Test (org.junit.Test)25 DataWrapper (org.webpieces.data.api.DataWrapper)18 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)11 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)7 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)1