Search in sources :

Example 6 with ConnectionClosedException

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

the class TestC5_1StreamStates 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();
    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)

Example 7 with ConnectionClosedException

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

the class Level4PreconditionChecks method createExcepted.

public CompletableFuture<Void> createExcepted(Http2Msg payload, String extra, ConnectionCancelled closedReason) {
    log.info("returning CompletableFuture.exception since this socket is closed('" + extra + "' frame=" + payload + "):" + closedReason.getReasonCode());
    CompletableFuture<Void> future = new CompletableFuture<>();
    ConnectionClosedException exception = new ConnectionClosedException(closedReason, "Connection closed or closing:" + closedReason.getReasonCode());
    if (closedReason instanceof ConnectionFailure) {
        ConnectionFailure fail = (ConnectionFailure) closedReason;
        exception.initCause(fail.getCause());
    }
    future.completeExceptionally(exception);
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException)

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