Search in sources :

Example 6 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
    Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data1);
    DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming2.getData().getReadableSize());
    //clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    mockChannel.send(trailing);
    Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
    Assert.assertEquals(trailing, incoming);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
    Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
    writer.processPiece(trailingResp);
    Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(trailingResp, trailers);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 7 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithData.

@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data);
    DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming.getData().getReadableSize());
    //clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 8 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class IntegSingleRequest method start.

public void start() throws InterruptedException {
    log.info("starting test to download / page from google");
    boolean isHttp = true;
    String host = "www.google.com";
    //String host = "localhost"; //jetty
    //String host = "api.push.apple.com";
    //String host = "gcm-http.googleapis.com";
    //String host = "nghttp2.org";
    int port = 443;
    if (isHttp)
        port = 80;
    if ("localhost".equals(host)) {
        port = 8443;
        if (isHttp)
            port = 8080;
    }
    List<Http2Header> req = createRequest(host, isHttp);
    Http2Request request = new Http2Request(req);
    request.setEndOfStream(true);
    InetSocketAddress addr = new InetSocketAddress(host, port);
    Http2Socket socket = createHttpClient("testRunSocket", isHttp, addr);
    socket.connect(addr).thenAccept(s -> s.openStream().process(request, new ChunkedResponseListener())).exceptionally(e -> reportException(socket, e));
    Thread.sleep(10000000);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) CompletableFuture(java.util.concurrent.CompletableFuture) Http2ClientFactory(org.webpieces.http2client.api.Http2ClientFactory) ChannelManager(org.webpieces.nio.api.ChannelManager) ArrayList(java.util.ArrayList) SSLEngine(javax.net.ssl.SSLEngine) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Request(com.webpieces.hpack.api.dto.Http2Request) HpackParser(com.webpieces.hpack.api.HpackParser) Http2Socket(org.webpieces.http2client.api.Http2Socket) HpackParserFactory(com.webpieces.hpack.api.HpackParserFactory) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler) Logger(org.webpieces.util.logging.Logger) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) PushStreamHandle(com.webpieces.http2engine.api.PushStreamHandle) Http2Client(org.webpieces.http2client.api.Http2Client) List(java.util.List) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) StreamWriter(com.webpieces.http2engine.api.StreamWriter) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 9 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class IntegColoradoEdu method main.

public static void main(String[] args) throws InterruptedException {
    boolean isHttp = true;
    String host = "www.colorado.edu";
    int port = 443;
    if (isHttp)
        port = 80;
    Http2Request req = createRequest(host);
    log.info("starting socket");
    ChunkedResponseListener listener = new ChunkedResponseListener();
    InetSocketAddress addr = new InetSocketAddress(host, port);
    Http2Socket socket = IntegSingleRequest.createHttpClient("oneTimerHttp2Socket", isHttp, addr);
    socket.connect(addr).thenAccept(socet -> socket.openStream().process(req, listener)).exceptionally(e -> reportException(socket, e));
    Thread.sleep(100000);
}
Also used : Logger(org.webpieces.util.logging.Logger) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) PushStreamHandle(com.webpieces.http2engine.api.PushStreamHandle) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Request(com.webpieces.hpack.api.dto.Http2Request) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Socket(org.webpieces.http2client.api.Http2Socket) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler) Http2Request(com.webpieces.hpack.api.dto.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 10 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class Http2Requests method createRequest.

public static Http2Request createRequest(int streamId, boolean eos) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
    headers.add(new Http2Header(Http2HeaderName.AUTHORITY, "somehost.com"));
    headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
    headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
    headers.add(new Http2Header(Http2HeaderName.HOST, "somehost.com"));
    headers.add(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
    headers.add(new Http2Header(Http2HeaderName.ACCEPT_ENCODING, "gzip, deflate"));
    headers.add(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/1.15.0"));
    Http2Request request = new Http2Request(headers);
    request.setStreamId(streamId);
    request.setEndOfStream(eos);
    return request;
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Aggregations

Http2Request (com.webpieces.hpack.api.dto.Http2Request)31 Test (org.junit.Test)22 StreamWriter (com.webpieces.http2engine.api.StreamWriter)13 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)13 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)12 DataWrapper (org.webpieces.data.api.DataWrapper)11 Http2Response (com.webpieces.hpack.api.dto.Http2Response)10 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)7 Http2Push (com.webpieces.hpack.api.dto.Http2Push)5 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)4 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)4 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)3 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)3 InetSocketAddress (java.net.InetSocketAddress)3 ArrayList (java.util.ArrayList)3