use of org.webpieces.router.impl.ctx.SessionImpl 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);
}
}
use of org.webpieces.router.impl.ctx.SessionImpl in project webpieces by deanhiller.
the class AbstractRouterService method incomingRequest.
public RouterStreamRef incomingRequest(RouterRequest routerRequest, ProxyStreamHandle handler) {
try {
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));
ApplicationContext ctx = webInjector.getAppContext();
RequestContext requestCtx = new RequestContext(validation, flash, session, routerRequest, ctx);
String user = session.get("userId");
MDC.put("userId", user);
// TODO(dhiller): This is request heaaders choke point but need ot also perhaps setup streaming choke point
// here as well
Current.setContext(requestCtx);
try {
return incomingRequestImpl(requestCtx, handler);
} finally {
Current.setContext(null);
}
} catch (BadCookieException e) {
// CHEAT: we know this is syncrhonous exception from the translateCookieToScope
log.warn("This occurs if secret key changed, or you booted another webapp with different key on same port or someone modified the cookie", e);
XFuture<StreamWriter> writer = handler.sendRedirectAndClearCookie(routerRequest, e.getCookieName());
return new RouterStreamRef("cookieFailed", writer, null);
}
}
Aggregations