use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class ProxyRequestStreamHandle method process.
@Override
public StreamRef process(Http2Request request, ResponseStreamHandle responseListener) {
ProxyResponseStream proxyResponse = new ProxyResponseStream(responseListener, frontendSocket);
Map<String, Object> context = Context.copyContext();
// clear context so server uses a clean context
Context.restoreContext(new HashMap<>());
try {
StreamRef streamRef = stream.incomingRequest(request, proxyResponse);
return new MockProxyStreamRef(streamRef);
} finally {
// client still in this context
Context.restoreContext(context);
}
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class ErrorCommonTest method testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive.
@Test
public void testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive() {
// 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");
// ADD a keep alive to test keeping alive
req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
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) {
Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server."));
} else {
// use DevServer template
Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
}
// We did send a keep alive so it should close
Assert.assertFalse(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class ErrorTest method testNoMethod.
@Test
public void testNoMethod() {
log.info("starting");
String moduleFileContents = NoMethodRouterModules.class.getName();
RouterService server = ErrorCommonTest.createServer(true, moduleFileContents);
try {
server.start();
Assert.fail("Should have thrown exception on start since this is prod");
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("Cannot find 'public' method='thisMethodNotExist' on class="));
}
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
// done and no exception SINCE we responded to client successfully
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String body = mockStream.getResponseBody();
Assert.assertEquals(StatusCode.HTTP_500_INTERNAL_SERVER_ERROR, response.getKnownStatusCode());
Assert.assertTrue(body.contains("There was a bug in the developers application or webpieces server"));
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class TestSimpleRoutes method testOneParamRoute.
@Test
public void testOneParamRoute() {
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.POST, "/meeting");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response resp = mockStream.getLastResponse();
Assert.assertEquals("http://" + req.getAuthority() + "/meeting/888", resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class TestSimpleRoutes method testBasicRoute.
@Test
public void testBasicRoute() {
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 resp = mockStream.getLastResponse();
Assert.assertEquals("http://" + req.getAuthority() + "/something", resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
}
Aggregations