Search in sources :

Example 1 with Session

use of org.webpieces.ctx.api.Session in project webpieces by deanhiller.

the class ScopesController method home.

public Action home() {
    Session session = Current.session();
    session.put("age", 30);
    session.put("boolean", true);
    session.put("name", "Dean");
    return Actions.renderThis();
}
Also used : Session(org.webpieces.ctx.api.Session)

Example 2 with Session

use of org.webpieces.ctx.api.Session in project webpieces by deanhiller.

the class ScopesController method displaySession.

public Action displaySession() {
    Session session = Current.session();
    Integer age = session.get("age", Integer.class);
    Boolean b = session.get("boolean", Boolean.class);
    String name = session.get("name");
    return Actions.renderThis("age", age, "result", b, "name", name);
}
Also used : Session(org.webpieces.ctx.api.Session)

Example 3 with Session

use of org.webpieces.ctx.api.Session 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);
    }
}
Also used : Validation(org.webpieces.ctx.api.Validation) BadCookieException(org.webpieces.router.api.exceptions.BadCookieException) SessionImpl(org.webpieces.router.impl.ctx.SessionImpl) FlashImpl(org.webpieces.router.impl.ctx.FlashImpl) RequestContext(org.webpieces.ctx.api.RequestContext) FlashSub(org.webpieces.ctx.api.FlashSub) Session(org.webpieces.ctx.api.Session) ValidationImpl(org.webpieces.router.impl.ctx.ValidationImpl)

Example 4 with Session

use of org.webpieces.ctx.api.Session in project webpieces by deanhiller.

the class LoginFilter method filter.

@Override
public CompletableFuture<Action> filter(MethodMeta meta, Service<MethodMeta, Action> next) {
    Session session = Current.session();
    if (session.containsKey(token)) {
        Current.addModifyResponse(resp -> addCacheHeaders(resp));
        return next.invoke(meta);
    }
    RouterRequest request = Current.request();
    if (request.isAjaxRequest) {
        if (request.referrer != null) {
            Current.flash().put("url", request.referrer);
            Current.flash().keep();
        }
        return CompletableFuture.completedFuture(Actions.ajaxRedirect(loginRoute));
    } else if (request.method == HttpMethod.GET) {
        //store url requested in flash so after logging in, we can redirect the user
        //back to the original page
        Current.flash().put("url", request.relativePath);
        Current.flash().keep();
    } else if (request.method == HttpMethod.POST) {
        //adding a validation error avoids the posting of the form so they post AFTER logging in
        if (request.referrer != null)
            Current.flash().put("url", request.referrer);
        else
            Current.flash().put("url", request.relativePath);
        Current.flash().keep();
    }
    //redirect to login page..
    return CompletableFuture.completedFuture(Actions.redirect(loginRoute));
}
Also used : Session(org.webpieces.ctx.api.Session) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 5 with Session

use of org.webpieces.ctx.api.Session in project webpieces by deanhiller.

the class ScopesController method sessionTooLarge.

public Action sessionTooLarge() {
    Session session = Current.session();
    String someValue = create50LongString();
    for (int i = 0; i < 100; i++) {
        session.put("someKey" + i, someValue);
    }
    return Actions.renderThis();
}
Also used : Session(org.webpieces.ctx.api.Session)

Aggregations

Session (org.webpieces.ctx.api.Session)6 FlashSub (org.webpieces.ctx.api.FlashSub)1 RequestContext (org.webpieces.ctx.api.RequestContext)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 Validation (org.webpieces.ctx.api.Validation)1 BadCookieException (org.webpieces.router.api.exceptions.BadCookieException)1 FlashImpl (org.webpieces.router.impl.ctx.FlashImpl)1 SessionImpl (org.webpieces.router.impl.ctx.SessionImpl)1 ValidationImpl (org.webpieces.router.impl.ctx.ValidationImpl)1