use of org.webpieces.router.api.RouterResponseHandler in project webpieces by deanhiller.
the class WebpiecesStreamHandle method incomingRequest.
@Override
public StreamRef incomingRequest(Http2Request headers, ResponseStream stream) {
RouterResponseHandler handler = new RouterResponseHandlerImpl(stream);
StreamRef ref = routingService.incomingRequest(headers, handler);
return ref;
}
use of org.webpieces.router.api.RouterResponseHandler in project webpieces by deanhiller.
the class RouterServiceImpl method incomingRequest.
@Override
public StreamRef incomingRequest(Http2Request req, RouterResponseHandler handler) {
// ******************************************************************************************
// DO NOT ADD CODE HERE OR ABOVE THIS METHOD in RouterService. This is our CATCH-ALL point so
// ANY code above that is not protected from our catch and respond to clients
// ******************************************************************************************
String txId = generate();
// I do NOT like doing Guice creation on the request path(Dagger creation would probably be ok) BUT this
// is very worth it AND customers can swap out these critical classes if they need to quickly temporarily fix a bug while
// we work on the bug. We can easily give customers bug fixes like add binder.bind(ClassWithBug.class).to(BugFixCode.class)
ProxyStreamHandle proxyHandler = proxyProvider.get();
proxyHandler.init(handler, req);
MDC.put("txId", txId);
// top level handler...
try {
RouterStreamRef streamRef = incomingRequestProtected(req, proxyHandler);
XFuture<StreamWriter> writer = streamRef.getWriter().thenApply(w -> new TxStreamWriter(txId, w));
XFuture<StreamWriter> finalWriter = writer.handle((r, t) -> {
if (t == null)
return XFuture.completedFuture(r);
XFuture<StreamWriter> fut = proxyHandler.topLevelFailure(req, t);
return fut;
}).thenCompose(Function.identity());
return new RouterStreamRef("routerSevcTop", finalWriter, streamRef);
} finally {
MDC.remove("txId");
}
}
Aggregations