Search in sources :

Example 56 with StreamWriter

use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.

the class Level8NotifyClntListeners method sendPieceToApp.

@Override
public XFuture<Void> sendPieceToApp(Stream stream, Http2Trailers payload) {
    ClientStream str = (ClientStream) stream;
    StreamWriter writer = str.getResponseWriter();
    return writer.processPiece(payload).thenApply(null);
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter)

Example 57 with StreamWriter

use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.

the class DevRouteInvoker method invokeHtmlController.

@Override
public RouterStreamRef invokeHtmlController(InvokeInfo invokeInfo, StreamService dynamicInfo, RouteData data) {
    // special case for if stuff didn't compile and we flag it
    Throwable exc = (Throwable) invokeInfo.getRequestCtx().getRequest().requestState.get(ERROR_KEY);
    if (exc != null) {
        log.error("Could not compile your code", exc);
        RouteInfoForInternalError error = new RouteInfoForInternalError(exc);
        XFuture<Void> future = invokeDevelopmentErrorPage(invokeInfo, error);
        XFuture<StreamWriter> writer = future.thenApply(voidd -> new NullWriter());
        return new RouterStreamRef("notCompileError", writer, null);
    }
    if (invokeInfo.getRequestCtx().getRequest().queryParams.containsKey(DevelopmentController.INTERNAL_ERROR_KEY)) {
        // need to simulate the error to show production page
        throw new SimulateInternalError();
    }
    // }
    return super.invokeHtmlController(invokeInfo, dynamicInfo, data);
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) SimulateInternalError(org.webpieces.router.impl.routers.SimulateInternalError) NullWriter(org.webpieces.router.impl.routeinvoker.NullWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Example 58 with StreamWriter

use of com.webpieces.http2.api.streaming.StreamWriter 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 59 with StreamWriter

use of com.webpieces.http2.api.streaming.StreamWriter 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)

Example 60 with StreamWriter

use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.

the class ErrorCommonTest method testGetNotMatchPostRoute.

@Test
public void testGetNotMatchPostRoute() {
    log.info("starting");
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/postroute");
    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)

Aggregations

StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)60 Test (org.junit.Test)43 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)37 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)32 StreamRef (com.webpieces.http2.api.streaming.StreamRef)25 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)24 DataWrapper (org.webpieces.data.api.DataWrapper)19 XFuture (org.webpieces.util.futures.XFuture)17 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)15 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)13 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)11 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)9 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)8 Header (org.webpieces.httpparser.api.common.Header)8 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)8 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)7 ByteBuffer (java.nio.ByteBuffer)7 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)7 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)7