use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class AbstractRouteInvoker method invokeRealRoute.
protected RouterStreamRef invokeRealRoute(InvokeInfo invokeInfo, StreamService endpoint, RouteData data) {
if (endpoint == null)
throw new IllegalStateException("Bug, service should never be null at this point");
LoadedController loadedController = invokeInfo.getLoadedController();
RequestContext requestCtx = invokeInfo.getRequestCtx();
Messages messages = new Messages(invokeInfo.getI18nBundleName(), "webpieces");
requestCtx.setMessages(messages);
MethodMeta methodMeta = new MethodMeta(loadedController, requestCtx, invokeInfo.getRouteType(), data);
return endpoint.openStream(methodMeta, invokeInfo.getHandler());
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class EScopedRouter method invokeRouter.
private RouterStreamRef invokeRouter(AbstractRouter router, RequestContext ctx, ProxyStreamHandle handler, boolean isCorsRequest) {
RouterStreamRef streamRef = invokeWithProtection(router, ctx, handler, isCorsRequest);
XFuture<StreamWriter> writer = streamRef.getWriter().handle((r, t) -> {
if (t == null)
return XFuture.completedFuture(r);
XFuture<StreamWriter> fut = new XFuture<>();
Throwable exc = convert(router.getMatchInfo(), t);
fut.completeExceptionally(exc);
return fut;
}).thenCompose(Function.identity());
return new RouterStreamRef("eScoped2", writer, streamRef);
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class ServiceInvoker method invokeSvc.
public XFuture<Void> invokeSvc(MethodMeta meta, String i18nBundleName, Endpoint service, Processor processor, ProxyStreamHandle handle) {
if (processor == null || meta == null || service == null || handle == null)
throw new IllegalArgumentException("nothing can be null into this metehod");
handle.initJustBeforeInvoke(reverseRoutes, meta);
RequestContext requestCtx = meta.getCtx();
LoadedController loadedController = meta.getLoadedController();
Messages messages = new Messages(i18nBundleName, "webpieces");
requestCtx.setMessages(messages);
XFuture<Action> response = futureUtil.catchBlockWrap(() -> invokeService(service, meta), (t) -> convert(loadedController, t));
return response.thenCompose(resp -> continueProcessing(handle, meta, resp, processor));
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class RouteInvoker method processNotFound.
public CompletableFuture<Void> processNotFound(ResponseStreamer responseCb, RequestContext requestCtx, NotFoundException e, ErrorRoutes errorRoutes, Object meta) {
NotFoundException exc = (NotFoundException) e;
NotFoundInfo notFoundInfo = errorRoutes.fetchNotfoundRoute(exc);
RouteMeta notFoundResult = notFoundInfo.getResult();
RouterRequest overridenRequest = notFoundInfo.getReq();
RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), overridenRequest);
//http 404...(unless an exception happens in calling this code and that then goes to 500)
return notFound(notFoundResult, notFoundInfo.getService(), exc, overridenCtx, responseCb);
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class AbstractRouterService method incomingCompleteRequest.
@Override
public final CompletableFuture<Void> incomingCompleteRequest(RouterRequest routerRequest, ResponseStreamer responseCb) {
try {
if (!started)
throw new IllegalStateException("Either start was not called by client or start threw an exception that client ignored and must be fixed");
;
Session session = (Session) cookieTranslator.translateCookieToScope(routerRequest, new SessionImpl(translator));
FlashSub flash = (FlashSub) cookieTranslator.translateCookieToScope(routerRequest, new FlashImpl(translator));
Validation validation = (Validation) cookieTranslator.translateCookieToScope(routerRequest, new ValidationImpl(translator));
RequestContext requestCtx = new RequestContext(validation, flash, session, routerRequest);
return processRequest(requestCtx, responseCb);
} catch (BadCookieException e) {
throw e;
} catch (Throwable e) {
log.warn("uncaught exception", e);
return responseCb.failureRenderingInternalServerErrorPage(e);
}
}
Aggregations