Search in sources :

Example 11 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class TestHttp11Errors method testCloseBeforeFirstRequestCompletes.

@Test
public void testCloseBeforeFirstRequestCompletes() throws InterruptedException, ExecutionException, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    XFuture<StreamWriter> futA = XFuture.completedFuture(null);
    MockStreamRef mockStreamRefA = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStreamRefA);
    mockChannel.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    XFuture<StreamWriter> futB = XFuture.completedFuture(null);
    MockStreamRef mockStreamRefB = new MockStreamRef(futB);
    mockListener.addMockStreamToReturn(mockStreamRefB);
    XFuture<Void> fut1 = mockChannel.sendToSvrAsync(req2);
    Assert.assertFalse(fut1.isDone());
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    HttpResponse resp1 = Requests.createResponse(1);
    resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
    Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
    XFuture<StreamWriter> future = in1.stream.process(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Assert.assertFalse(fut1.isDone());
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertFalse(mockStreamRefA.isCancelled());
    Assert.assertFalse(mockStreamRefB.isCancelled());
    mockChannel.simulateClose();
    // this request is done, nothing to cancel
    Assert.assertTrue(mockStreamRefA.isCancelled());
    Assert.assertFalse(mockStreamRefB.isCancelled());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 12 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload 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 13 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class TestBeansAndSplit method create.

private ResponseWrapper create() {
    List<HttpPayload> payloads = parser.parse(dataReceived);
    HttpResponse response = (HttpResponse) payloads.get(0);
    DataWrapper all = dataGen.emptyWrapper();
    for (int i = 1; i < payloads.size(); i++) {
        HttpData d = (HttpData) payloads.get(i);
        all = dataGen.chainDataWrappers(all, d.getBodyNonNull());
    }
    HttpFullResponse fResponse = new HttpFullResponse(response, all);
    return new ResponseWrapper(fResponse);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper)

Example 14 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload 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 15 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload 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);
    return (XFuture<Void>) super.calledMethod(Method.WRITE, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) XFuture(org.webpieces.util.futures.XFuture)

Aggregations

HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)35 DataWrapper (org.webpieces.data.api.DataWrapper)30 Test (org.junit.Test)24 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)23 Header (org.webpieces.httpparser.api.common.Header)18 HttpData (org.webpieces.httpparser.api.dto.HttpData)14 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)13 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)6 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)4 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)4 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)3 ByteBuffer (java.nio.ByteBuffer)3 Memento (org.webpieces.httpparser.api.Memento)3 HttpLastData (org.webpieces.httpparser.api.dto.HttpLastData)3 XFuture (org.webpieces.util.futures.XFuture)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2