use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level5AStates method translateException.
private XFuture<Void> translateException(Stream stream, Throwable t) {
XFuture<Void> fut = new XFuture<>();
if (t instanceof NoTransitionConnectionError)
fut.completeExceptionally(new ConnectionException(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, logId, stream.getStreamId(), t.getMessage(), t));
else if (t instanceof NoTransitionStreamError)
fut.completeExceptionally(new StreamException(CancelReasonCode.CLOSED_STREAM, logId, stream.getStreamId(), t.getMessage(), t));
else
fut.completeExceptionally(t);
return fut;
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class HeaderDecoding method decodeImpl.
private List<Http2Header> decodeImpl(UnmarshalStateImpl state, DataWrapper data, int streamId, Consumer<Http2Header> knownHeaders) throws IOException {
List<Http2Header> headers = new ArrayList<>();
byte[] bytes = data.createByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Decoder decoder = state.getDecoder();
// TODO(dhiller): make this an async syncrhonized block instead so threads can keep running!!!
synchronized (decoder) {
decoder.decode(in, (n, v, s) -> addToHeaders(headers, knownHeaders, n, v, s, state.getLogId(), streamId));
decoder.endHeaderBlock();
}
if (data.getReadableSize() > 0 && headers.size() == 0)
throw new ConnectionException(CancelReasonCode.COMPRESSION_ERROR, state.getLogId(), streamId, "Header data came in, but no headers came out");
return headers;
}
use of com.webpieces.http2.api.dto.error.ConnectionException 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());
}
use of com.webpieces.http2.api.dto.error.ConnectionException 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());
}
Aggregations