Search in sources :

Example 21 with Http2Msg

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

the class TestCMaxConcurrentSetting method sendTwoRequests.

private RequestsSent sendTwoRequests() {
    Http2Request request1 = Requests.createRequest();
    Http2Request request2 = Requests.createRequest();
    MockStreamWriter writer1 = new MockStreamWriter();
    MockStreamWriter writer2 = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
    // do not set default incoming response as we want to delay the resolution of the future
    MockResponseListener listener2 = new MockResponseListener();
    StreamRef streamRef1 = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef1.getWriter();
    StreamRef streamRef2 = httpSocket.openStream().process(request2, listener2);
    XFuture<StreamWriter> future2 = streamRef2.getWriter();
    RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
    RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
    RequestsSent requests = new RequestsSent(r1, r2);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(1, req.getStreamId());
    Assert.assertEquals(request1, req);
    Assert.assertTrue(future.isDone());
    Assert.assertFalse(future2.isDone());
    return requests;
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RequestsSent(org.webpieces.http2client.util.RequestsSent) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) RequestHolder(org.webpieces.http2client.util.RequestHolder) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter)

Example 22 with Http2Msg

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

the class Level2ParsingAndRemoteSettings method parseImpl.

public XFuture<Void> parseImpl(DataWrapper newData) {
    parsingState = lowLevelParser.unmarshal(parsingState, newData);
    List<Http2Msg> parsedMessages = parsingState.getParsedFrames();
    // All the below futures must be chained with previous ones in case previous ones are not
    // done which will serialize it all to be in sequence
    XFuture<Void> future = parsingState.getProcessFuture();
    for (Http2Msg lowLevelFrame : parsedMessages) {
        // VERY IMPORTANT: Writing the code like this would slam through calling process N times
        // BUT it doesn't give the clients a chance to seet a flag between packets
        // Mainly done for exceptions and streaming so you can log exc, set a boolean so you
        // don't get 100 exceptions while something is happening like socket disconnect
        // In these 2 lines of code, processCorrectly is CALLED N times RIGHT NOW
        // The code below this only calls them right now IF AND ONLY IF the client returns
        // a completed future each time!!!
        // XFuture<Void> messageFuture = process(lowLevelFrame);
        // allFutures = allFutures.thenCompose( f -> messageFuture);
        future = future.thenCompose(f -> process(lowLevelFrame));
    }
    parsingState.setProcessFuturee(future);
    return future;
}
Also used : WindowUpdateFrame(com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Http2Config(com.webpieces.http2engine.api.client.Http2Config) LoggerFactory(org.slf4j.LoggerFactory) UnknownFrame(com.webpieces.http2.api.dto.lowlevel.UnknownFrame) ByteAckTracker(org.webpieces.util.acking.ByteAckTracker) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) HpackParser(com.webpieces.hpack.api.HpackParser) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) DataWrapper(org.webpieces.data.api.DataWrapper) SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) Logger(org.slf4j.Logger) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) CancelReasonCode(com.webpieces.http2.api.dto.error.CancelReasonCode) List(java.util.List) StreamException(com.webpieces.http2.api.dto.error.StreamException) ReceivedGoAway(com.webpieces.http2engine.api.error.ReceivedGoAway) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) XFuture(org.webpieces.util.futures.XFuture) Http2Trailers(com.webpieces.http2.api.dto.highlevel.Http2Trailers) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

Example 23 with Http2Msg

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

the class AbstractTest method sendRequestToServer.

protected Http2Request sendRequestToServer(MockResponseListener listener1) {
    Http2Request request1 = Requests.createRequest();
    httpSocket.openStream().process(request1, listener1);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    return request1;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

Example 24 with Http2Msg

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

the class Level7MarshalAndPing method sendPing.

// public XFuture<Void> sendControlFrameToClient(Http2Msg msg) {
// return finalLayer.sendControlFrameToClient(msg);
// }
public XFuture<Void> sendPing() {
    PingFrame ping = new PingFrame();
    ping.setOpaqueData(8L);
    XFuture<Void> newFuture = new XFuture<>();
    boolean wasSet = pingFutureRef.compareAndSet(null, newFuture);
    if (!wasSet) {
        throw new IllegalStateException(key + "You must wait until the first ping you sent is complete.  2nd ping=" + ping);
    }
    return sendFrameToSocket(ping).thenCompose(c -> newFuture);
}
Also used : PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) XFuture(org.webpieces.util.futures.XFuture)

Example 25 with Http2Msg

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

the class Http2ChannelCache method write.

@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
    DataWrapper data = dataGen.wrapByteBuffer(b);
    parser.unmarshal(unmarshalState, data);
    List<Http2Msg> parsedFrames = unmarshalState.getParsedFrames();
    return (XFuture<Void>) super.calledMethod(Method.INCOMING_FRAME, parsedFrames);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) XFuture(org.webpieces.util.futures.XFuture) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)

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