Search in sources :

Example 1 with Http2Msg

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

the class Http11SynchronousClient method startImpl.

public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
    @SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
    OutputStream output = socket.getOutputStream();
    Runnable client = new ClientWriter(parser, output);
    Thread t1 = new Thread(client);
    t1.setName("clientWriter");
    t1.start();
    InputStream input = socket.getInputStream();
    RateRecorder recorder = new RateRecorder(10);
    while (true) {
        byte[] bytes = new byte[1024];
        int read = input.read(bytes);
        if (read < 0)
            break;
        DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
        List<HttpPayload> messages = parser.parse(dataWrapper);
        // simulate going all the way to http2 like the other test does as well
        for (HttpPayload p : messages) {
            HttpResponse resp = (HttpResponse) p;
            Http2Msg translate = Http11ToHttp2.responseToHeaders(resp);
            translate.getMessageType();
            recorder.increment();
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) DataWrapper(org.webpieces.data.api.DataWrapper) RateRecorder(org.webpieces.util.time.RateRecorder) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) Socket(java.net.Socket)

Example 2 with Http2Msg

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

the class Http2SynchronousClient method startImpl.

public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
    @SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
    OutputStream output = socket.getOutputStream();
    Runnable client = new ClientWriter(parser, output);
    Thread t1 = new Thread(client);
    t1.setName("clientWriter");
    t1.start();
    InputStream input = socket.getInputStream();
    RateRecorder recorder = new RateRecorder(10);
    while (true) {
        byte[] bytes = new byte[1024];
        int read = input.read(bytes);
        if (read < 0)
            break;
        DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
        UnmarshalState state = parser.unmarshal(dataWrapper);
        List<Http2Msg> messages = state.getParsedFrames();
        // simulate going all the way to http2 like the other test does as well
        for (Http2Msg p : messages) {
            Http2Response resp = (Http2Response) p;
            resp.getStreamId();
            recorder.increment();
        }
    }
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) DataWrapper(org.webpieces.data.api.DataWrapper) RateRecorder(org.webpieces.util.time.RateRecorder) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) Socket(java.net.Socket)

Example 3 with Http2Msg

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

the class Layer2Http11Handler method processCorrectly.

private XFuture<Void> processCorrectly(FrontendSocketImpl socket, HttpPayload payload) {
    try {
        MDC.put("svrSocket", socket.getChannel().getChannelId());
        Http2Msg msg = Http11ToHttp2.translate(payload, socket.isForServingHttpsPages());
        if (payload instanceof HttpRequest) {
            return processInitialPieceOfRequest(socket, (HttpRequest) payload, (Http2Request) msg);
        } else if (msg instanceof DataFrame) {
            return processData(socket, (DataFrame) msg);
        } else {
            throw new IllegalArgumentException("payload not supported=" + payload);
        }
    } finally {
        MDC.put("svrSocket", "");
    }
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

Example 4 with Http2Msg

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

the class MockChannel method write.

@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
    DataWrapper wrapper = dataGen.wrapByteBuffer(b);
    List<HttpPayload> parsedData = parser.parse(wrapper);
    if (parsedData.size() != 1)
        throw new IllegalArgumentException("The impl should be writing out full single payloads each write call");
    HttpPayload payload = parsedData.get(0);
    Http2Msg http2 = Http11ToHttp2.translate(payload, false);
    return (XFuture<Void>) super.calledMethod(Method.WRITE, http2);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) XFuture(org.webpieces.util.futures.XFuture) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

Example 5 with Http2Msg

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

the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * reserved local
 *
 * A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
 * type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE 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() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    Http2Request request = Http2Requests.createRequest(1, true);
    mockChannel.send(request);
    PassedIn in = mockListener.getSingleRequest();
    ResponseStream stream = in.stream;
    Http2Push push = Http2Requests.createPush(request.getStreamId());
    stream.openPushStream().process(push);
    Http2Msg pushMsg = mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushMsg);
    // send bad frame in this state
    DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
    mockChannel.send(data);
    Assert.assertTrue(mockStream.isCancelled());
    // 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: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Aggregations

Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)27 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Test (org.junit.Test)12 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)7 DataWrapper (org.webpieces.data.api.DataWrapper)7 XFuture (org.webpieces.util.futures.XFuture)7 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)6 SettingsFrame (com.webpieces.http2.api.dto.lowlevel.SettingsFrame)5 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)4 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)3 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 UnmarshalState (com.webpieces.hpack.api.UnmarshalState)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)2 StreamException (com.webpieces.http2.api.dto.error.StreamException)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2