Search in sources :

Example 1 with ConnectionClosedException

use of com.webpieces.http2engine.api.ConnectionClosedException in project webpieces by deanhiller.

the class TestC5_1StreamStates 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(CompletableFuture.<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();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    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) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 2 with ConnectionClosedException

use of com.webpieces.http2engine.api.ConnectionClosedException in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_2FrameTooLarge.

/**
	 * An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame 
	 * exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any 
	 * limit defined for the frame type, or is too small to contain 
	 * mandatory frame data. A frame size error in a frame that could alter 
	 * the state of the entire connection MUST be treated as a connection 
	 * error (Section 5.4.1); this includes any frame carrying a header 
	 * block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and 
	 * CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
	 */
@Test
public void testSection4_2FrameTooLarge() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(dataGen.wrapByteArray(buf));
    //endOfStream=false
    mockChannel.write(dataFrame);
    //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:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, failResp.getCause().getReasonCode());
    //send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    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) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 3 with ConnectionClosedException

use of com.webpieces.http2engine.api.ConnectionClosedException in project webpieces by deanhiller.

the class Level2ParsingAndRemoteSettings method handleError.

private Void handleError(Object object, Throwable e) {
    if (e == null)
        return null;
    else if (e instanceof ConnectionClosedException) {
        log.error("Normal exception since we are closing and they do not know yet", e);
    } else if (e instanceof StreamException) {
        log.error("shutting the stream down due to error", e);
        syncro.sendRstToServerAndApp((StreamException) e).exceptionally(t -> logExc("stream", t));
    } else if (e instanceof ConnectionException) {
        log.error("shutting the connection down due to error", e);
        ConnectionFailure reset = new ConnectionFailure((ConnectionException) e);
        //send GoAway
        syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
    } else {
        log.error("shutting the connection down due to error(MAKE sure your clients try..catch, exceptions)", e);
        ConnectionException exc = new ConnectionException(CancelReasonCode.BUG, logId, 0, e.getMessage(), e);
        ConnectionFailure reset = new ConnectionFailure((ConnectionException) exc);
        //send GoAwa
        syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
    }
    return null;
}
Also used : Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) Http2Config(com.webpieces.http2engine.api.client.Http2Config) CompletableFuture(java.util.concurrent.CompletableFuture) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) HpackParser(com.webpieces.hpack.api.HpackParser) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) DataWrapper(org.webpieces.data.api.DataWrapper) StreamException(com.webpieces.http2parser.api.dto.error.StreamException) Logger(org.webpieces.util.logging.Logger) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) PingFrame(com.webpieces.http2parser.api.dto.PingFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) List(java.util.List) ReceivedGoAway(com.webpieces.http2engine.api.error.ReceivedGoAway) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) WindowUpdateFrame(com.webpieces.http2parser.api.dto.WindowUpdateFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) LoggerFactory(org.webpieces.util.logging.LoggerFactory) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Example 4 with ConnectionClosedException

use of com.webpieces.http2engine.api.ConnectionClosedException in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders method testSection4_2FrameTooLarge.

/**
	 * An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame 
	 * exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any 
	 * limit defined for the frame type, or is too small to contain 
	 * mandatory frame data. A frame size error in a frame that could alter 
	 * the state of the entire connection MUST be treated as a connection 
	 * error (Section 5.4.1); this includes any frame carrying a header 
	 * block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and 
	 * CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
	 * @throws TimeoutException 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
@Test
public void testSection4_2FrameTooLarge() throws InterruptedException, ExecutionException, TimeoutException {
    int streamId = 1;
    PassedIn info = sendRequestToServer(streamId, false);
    ResponseStream stream = info.stream;
    Http2Request request = info.request;
    //send data that goes with request
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(dataGen.wrapByteArray(buf));
    //endOfStream=false
    mockChannel.send(dataFrame);
    //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:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Cancel failResp = mockListener.getCancelInfo();
    ShutdownStream reset = (ShutdownStream) failResp.reset;
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, reset.getCause().getReasonCode());
    //send response with request not complete but failed as well anyways
    Http2Response response = Http2Requests.createResponse(request.getStreamId());
    CompletableFuture<StreamWriter> future = stream.sendResponse(response);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) StreamWriter(com.webpieces.http2engine.api.StreamWriter) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Test(org.junit.Test)

Example 5 with ConnectionClosedException

use of com.webpieces.http2engine.api.ConnectionClosedException in project webpieces by deanhiller.

the class TestC5_1StreamStates 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(CompletableFuture.<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();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    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) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Aggregations

ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)7 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)6 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)6 DataWrapper (org.webpieces.data.api.DataWrapper)6 Http2Request (com.webpieces.hpack.api.dto.Http2Request)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)5 Test (org.junit.Test)5 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)4 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)4 ConnectionFailure (com.webpieces.http2engine.api.error.ConnectionFailure)2 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 HpackParser (com.webpieces.hpack.api.HpackParser)1 UnmarshalState (com.webpieces.hpack.api.UnmarshalState)1 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 Http2Config (com.webpieces.http2engine.api.client.Http2Config)1 ReceivedGoAway (com.webpieces.http2engine.api.error.ReceivedGoAway)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)1