Search in sources :

Example 1 with FullResponse

use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.

the class SingleResponseListener method incomingEndHeaders.

public void incomingEndHeaders(Http2Trailers trailingHeaders) {
    if (!trailingHeaders.isEndOfStream()) {
        responseFuture.completeExceptionally(new IllegalArgumentException("An assumption we made was wrong.  isComplete should be true here"));
        throw new IllegalArgumentException("An assumption we made was wrong.  isComplete should be true here");
    }
    FullResponse response = new FullResponse(resp, fullData, trailingHeaders);
    responseFuture.complete(response);
}
Also used : FullResponse(org.webpieces.http2client.api.dto.FullResponse)

Example 2 with FullResponse

use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.

the class TestCBasicRequestResponse method testWithNoData.

@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = new FullRequest();
    request1.setHeaders(Requests.createRequest());
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, frame.getStreamId());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    resp.setEndOfStream(true);
    mockChannel.write(resp);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(0, response.getPayload().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 3 with FullResponse

use of org.webpieces.http2client.api.dto.FullResponse 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 4 with FullResponse

use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.

the class TestCBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = Requests.createHttp2Request();
    Http2Trailers trailing = Requests.createTrailers();
    request1.setTrailingHeaders(trailing);
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(3, frames.size());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    mockChannel.write(resp);
    Assert.assertFalse(future.isDone());
    DataFrame data = Requests.createData(request1.getHeaders().getStreamId());
    data.setEndOfStream(false);
    mockChannel.write(data);
    Assert.assertFalse(future.isDone());
    mockChannel.write(trailing);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(2, response.getPayload().getReadableSize());
    Assert.assertNotNull(response.getTrailingHeaders());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 5 with FullResponse

use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.

the class TestCBasicRequestResponse method testWithData.

@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = Requests.createHttp2Request();
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    mockChannel.write(resp);
    Assert.assertFalse(future.isDone());
    DataFrame data = Requests.createData(request1.getHeaders().getStreamId());
    mockChannel.write(data);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(2, response.getPayload().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Aggregations

FullResponse (org.webpieces.http2client.api.dto.FullResponse)6 FullRequest (org.webpieces.http2client.api.dto.FullRequest)5 Test (org.junit.Test)4 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)3 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 Http2ClientEngine (com.webpieces.http2engine.api.client.Http2ClientEngine)1 Http2ClientEngineFactory (com.webpieces.http2engine.api.client.Http2ClientEngineFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 Http2Socket (org.webpieces.http2client.api.Http2Socket)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 Logger (org.webpieces.util.logging.Logger)1 LoggerFactory (org.webpieces.util.logging.LoggerFactory)1