Search in sources :

Example 11 with DataFrame

use of com.webpieces.http2parser.api.dto.DataFrame in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
	 * Receiving any type of frame other than HEADERS, RST_STREAM, 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_1BadFrameReceivedInReservedRemoteState() {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setIncomingRespDefault(CompletableFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Request request = sendRequestToServer(listener1);
    Http2Push push = sendPushFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), 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:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
    ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 12 with DataFrame

use of com.webpieces.http2parser.api.dto.DataFrame 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 13 with DataFrame

use of com.webpieces.http2parser.api.dto.DataFrame in project webpieces by deanhiller.

the class Http2SocketImpl method createData.

private DataFrame createData(FullRequest request, boolean isEndOfStream) {
    DataWrapper payload = request.getPayload();
    DataFrame data = new DataFrame();
    data.setEndOfStream(isEndOfStream);
    data.setData(payload);
    return data;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 14 with DataFrame

use of com.webpieces.http2parser.api.dto.DataFrame in project webpieces by deanhiller.

the class Http2SocketImpl method send.

/**
	 * Can't specifically backpressure with this method(ie. On the other method, if you do not ack, eventually
	 * with too many bytes, the channelmanager disregisters and stops reading from the socket placing backpressure
	 * on the socket)
	 */
@Override
public CompletableFuture<FullResponse> send(FullRequest request) {
    SingleResponseListener responseListener = new SingleResponseListener();
    StreamHandle streamHandle = openStream();
    Http2Request req = request.getHeaders();
    if (request.getPayload() == null) {
        request.getHeaders().setEndOfStream(true);
        streamHandle.process(req, responseListener);
        return responseListener.fetchResponseFuture();
    } else if (request.getTrailingHeaders() == null) {
        request.getHeaders().setEndOfStream(false);
        DataFrame data = createData(request, true);
        return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
            data.setStreamId(req.getStreamId());
            return writer.processPiece(data);
        }).thenCompose(writer -> responseListener.fetchResponseFuture());
    }
    request.getHeaders().setEndOfStream(false);
    DataFrame data = createData(request, false);
    Http2Trailers trailers = request.getTrailingHeaders();
    trailers.setEndOfStream(true);
    return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
        data.setStreamId(req.getStreamId());
        return writer.processPiece(data);
    }).thenCompose(writer -> {
        trailers.setStreamId(req.getStreamId());
        return writer.processPiece(trailers);
    }).thenCompose(writer -> responseListener.fetchResponseFuture());
}
Also used : Logger(org.webpieces.util.logging.Logger) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2ClientEngineFactory(com.webpieces.http2engine.api.client.Http2ClientEngineFactory) DataWrapper(org.webpieces.data.api.DataWrapper) FullResponse(org.webpieces.http2client.api.dto.FullResponse) LoggerFactory(org.webpieces.util.logging.LoggerFactory) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2ClientEngine(com.webpieces.http2engine.api.client.Http2ClientEngine) Http2Socket(org.webpieces.http2client.api.Http2Socket) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Request(com.webpieces.hpack.api.dto.Http2Request) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 15 with DataFrame

use of com.webpieces.http2parser.api.dto.DataFrame in project webpieces by deanhiller.

the class Requests method createData.

public static DataFrame createData(int streamId) {
    DataFrame data = new DataFrame(streamId, true);
    DataWrapper wrapByteArray = dataGen.wrapByteArray(new byte[] { 2, 3 });
    data.setData(wrapByteArray);
    return data;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Aggregations

DataFrame (com.webpieces.http2parser.api.dto.DataFrame)16 DataWrapper (org.webpieces.data.api.DataWrapper)11 Http2Request (com.webpieces.hpack.api.dto.Http2Request)7 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)6 Test (org.junit.Test)6 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)4 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)3 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 Http2ClientEngine (com.webpieces.http2engine.api.client.Http2ClientEngine)1 Http2ClientEngineFactory (com.webpieces.http2engine.api.client.Http2ClientEngineFactory)1