protected void setSessionCsrfToken(RouteContext context, String token) { context.setSession(TOKEN, token); }
/** * Removes a Flash instance from the session, binds it to the RouteContext, * and creates a new Flash instance. * * @param routeContext */ private void processFlash(RouteContext routeContext) { Flash flash = null; if (routeContext.hasSession()) { // get flash from session flash = routeContext.removeSession("flash"); // put an empty flash (outgoing flash) in session; defense against session.get("flash") routeContext.setSession("flash", new Flash()); } if (flash == null) { flash = new Flash(); } // make current flash available to templates routeContext.setLocal("flash", flash); }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }