Search in sources :

Example 1 with RstStreamFrame

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

the class TestCancelStream method testClientCancelWithKeepAlive.

// @Test
// public void testRequestResponseXFutureCancelNoKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
// 
// @Test
// public void testRequestResponseXFutureCancelWithKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
@Test
public void testClientCancelWithKeepAlive() {
    XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
    MockResponseListener mockListener = new MockResponseListener();
    Http2Request req = Requests.createRequest(false);
    req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    RequestStreamHandle requestStream = httpSocket.openStream();
    StreamRef ref = requestStream.process(req, mockListener);
    CancelReason reason = new RstStreamFrame();
    XFuture<Void> cancelDone = ref.cancel(reason);
    Assert.assertTrue(cancelDone.isDone());
    // Assert the socket is NOT closed
    Assert.assertFalse(mockChannel.isClosed());
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) StreamRef(com.webpieces.http2.api.streaming.StreamRef) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) MockResponseListener(org.webpieces.httpclient.api.mocks.MockResponseListener) Test(org.junit.Test)

Example 2 with RstStreamFrame

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

the class TestCancelStream method testClientCancelNoKeepAlive.

@Test
public void testClientCancelNoKeepAlive() {
    XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
    MockResponseListener mockListener = new MockResponseListener();
    Http2Request req = Requests.createRequest(false);
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    RequestStreamHandle requestStream = httpSocket.openStream();
    StreamRef ref = requestStream.process(req, mockListener);
    CancelReason reason = new RstStreamFrame();
    XFuture<Void> cancelDone = ref.cancel(reason);
    Assert.assertTrue(cancelDone.isDone());
    // Assert the socket is NOT closed
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) StreamRef(com.webpieces.http2.api.streaming.StreamRef) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) InetSocketAddress(java.net.InetSocketAddress) MockResponseListener(org.webpieces.httpclient.api.mocks.MockResponseListener) Test(org.junit.Test)

Example 3 with RstStreamFrame

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

the class RstStreamMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 4)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "rststream size not 4 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    else if (frameHeaderData.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frameHeaderData.getStreamId(), "rst stream cannot be streamid 0 and was=" + frameHeaderData.getStreamId());
    RstStreamFrame frame = new RstStreamFrame();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    long errorCode = UnsignedData.getUnsignedInt(payloadByteBuffer);
    frame.setErrorCode(errorCode);
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 4 with RstStreamFrame

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

the class RstStreamMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    RstStreamFrame castFrame = (RstStreamFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(4);
    UnsignedData.putUnsignedInt(payload, castFrame.getErrorCode());
    payload.flip();
    DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
    return super.marshalFrame(frame, (byte) 0, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) ByteBuffer(java.nio.ByteBuffer)

Example 5 with RstStreamFrame

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

the class TestHttp2RstStream method testParseRstStream.

@Test
public void testParseRstStream() {
    DataWrapper data = Util.hexToBytes(connectError());
    parser.parse(memento, data);
    RstStreamFrame frame = (RstStreamFrame) assertGood();
    Assert.assertEquals(4, frame.getStreamId());
    Assert.assertEquals(10, frame.getErrorCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) Test(org.junit.Test)

Aggregations

RstStreamFrame (com.webpieces.http2.api.dto.lowlevel.RstStreamFrame)11 Test (org.junit.Test)6 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)4 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)3 StreamRef (com.webpieces.http2.api.streaming.StreamRef)3 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)3 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 MockResponseListener (org.webpieces.httpclient.api.mocks.MockResponseListener)2 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 Stream (com.webpieces.http2engine.impl.shared.data.Stream)1 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1