Search in sources :

Example 41 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class JsonController method myStream.

// Method signature cannot have RequestContext since in microservices, we implement an api as the server
// AND a client implements the same api AND client does not have a RequestContext!!
@Override
public StreamRef myStream(ResponseStreamHandle handle2) {
    RouterStreamHandle handle = (RouterStreamHandle) handle2;
    RequestContext requestCtx = Current.getContext();
    Http2Response response = handle.createBaseResponse(requestCtx.getRequest().originalRequest, "text/plain", 200, "Ok");
    response.setEndOfStream(false);
    XFuture<StreamWriter> responseWriter = handle.process(response);
    return new RequestStreamEchoWriter(requestCtx, handle, responseWriter);
}
Also used : RouterStreamHandle(org.webpieces.router.api.RouterStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 42 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithNoData.

@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
    incoming.stream.process(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 43 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testPushPromise.

@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Push push = Http2Requests.createPush(request1.getStreamId());
    XFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
    PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
    Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushRecv);
    Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
    pushWriter.processPushResponse(preEmptive);
    Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(preEmptive, preEmptRecv);
    Http2Response response = Http2Requests.createResponse(request1.getStreamId());
    incoming.stream.process(response);
    Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(response, responseRecv);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 44 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class ErrorCommonTest method testArgsTypeMismatch.

@Test
public void testArgsTypeMismatch() {
    log.info("starting");
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response response = mockStream.getLastResponse();
    String contents = mockStream.getResponseBody();
    verifyNotFoundRendered(response, contents);
    // We did not send a keep alive so it should close
    Assert.assertTrue(mockStream.isWasClosed());
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Test(org.junit.Test)

Example 45 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class ErrorCommonTest method testRedirectRouteNotEnoughArguments.

@Test
public void testRedirectRouteNotEnoughArguments() {
    // say method is something(int arg, String this)
    // we verify redirects MUST match type and number of method arguments every time
    // then when we form url, we put the stuff in the path OR put it as query params so it works on the way back in again too
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/user/5553");
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response response = mockStream.getLastResponse();
    String contents = mockStream.getResponseBody();
    Assert.assertEquals(response.getSingleHeaderValue(Http2HeaderName.STATUS), "500");
    if (isProdTest) {
        // prod template to use
        Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server"));
    } else {
        // The internalError template for DevServer should run...
        Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
    }
    // We did not send a keep alive so it should close
    Assert.assertTrue(mockStream.isWasClosed());
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Test(org.junit.Test)

Aggregations

Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)66 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)32 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)30 Test (org.junit.Test)30 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)24 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)16 StreamRef (com.webpieces.http2.api.streaming.StreamRef)15 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 DataWrapper (org.webpieces.data.api.DataWrapper)13 Header (org.webpieces.httpparser.api.common.Header)13 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 ArrayList (java.util.ArrayList)10 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)10 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)9 HttpData (org.webpieces.httpparser.api.dto.HttpData)8 XFuture (org.webpieces.util.futures.XFuture)8 RouterService (org.webpieces.router.api.RouterService)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)4