use of org.webpieces.router.impl.ctx.ResponseProcessor in project webpieces by deanhiller.
the class RouteInvoker method invokeImpl.
public CompletableFuture<Void> invokeImpl(MatchResult result, Service<MethodMeta, Action> service, RequestContext requestCtx, ResponseStreamer responseCb) {
RouteMeta meta = result.getMeta();
ResponseProcessor processor = new ResponseProcessor(requestCtx, reverseRoutes, reverseTranslator, meta, responseCb);
if (meta.getRoute().getRouteType() == RouteType.STATIC) {
StaticRoute route = (StaticRoute) meta.getRoute();
boolean isOnClassPath = route.getIsOnClassPath();
RenderStaticResponse resp = new RenderStaticResponse(route.getTargetCacheLocation(), isOnClassPath);
if (route.isFile()) {
resp.setFilePath(route.getFileSystemPath());
} else {
String relativeUrl = result.getPathParams().get("resource");
resp.setRelativeFile(route.getFileSystemPath(), relativeUrl);
}
return processor.renderStaticResponse(resp);
}
Object obj = meta.getControllerInstance();
if (obj == null)
throw new IllegalStateException("Someone screwed up, as controllerInstance should not be null at this point, bug");
Method method = meta.getMethod();
if (service == null)
throw new IllegalStateException("Bug, service should never be null at this point");
Messages messages = new Messages(meta.getI18nBundleName(), "webpieces");
requestCtx.setMessages(messages);
RequestLocalCtx.set(processor);
Current.setContext(requestCtx);
CompletableFuture<Action> response;
try {
response = invokeMethod(service, obj, method, meta);
} finally {
RequestLocalCtx.set(null);
Current.setContext(null);
}
CompletableFuture<Void> future = response.thenCompose(resp -> continueProcessing(processor, resp, responseCb));
return future;
}
use of org.webpieces.router.impl.ctx.ResponseProcessor in project webpieces by deanhiller.
the class RouteInvoker method finalFailure.
public Void finalFailure(ResponseStreamer responseCb, Throwable e, RequestContext requestCtx) {
log.error("This is a final(secondary failure) trying to render the Internal Server Error Route", e);
ResponseProcessor processor = new ResponseProcessor(requestCtx, reverseRoutes, reverseTranslator, null, responseCb);
processor.failureRenderingInternalServerErrorPage(e);
return null;
}
Aggregations