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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations