Search in sources :

Example 6 with ActionContext

use of act.app.ActionContext in project actframework by actframework.

the class SessionScope method get.

@Override
public <T> T get(String key) {
    ActionContext actionContext = ActionContext.current();
    if (null != actionContext) {
        H.Session session = actionContext.session();
        T t = session.cached(key);
        if (null != t) {
            session.cache(key, t, TTL);
        }
        return t;
    }
    CliContext cliContext = CliContext.current();
    if (null != cliContext) {
        CliSession cliSession = cliContext.session();
        return cliSession.attribute(key);
    }
    return null;
}
Also used : H(org.osgl.http.H) ActionContext(act.app.ActionContext) CliContext(act.cli.CliContext) CliSession(act.cli.CliSession)

Example 7 with ActionContext

use of act.app.ActionContext in project actframework by actframework.

the class SessionScope method put.

@Override
public <T> void put(String key, T t) {
    ActionContext actionContext = ActionContext.current();
    if (null != actionContext) {
        actionContext.session().cache(key, t, TTL);
    }
    CliContext cliContext = CliContext.current();
    if (null != cliContext) {
        CliSession cliSession = cliContext.session();
        cliSession.attribute(key, t);
    }
}
Also used : ActionContext(act.app.ActionContext) CliContext(act.cli.CliContext) CliSession(act.cli.CliSession)

Example 8 with ActionContext

use of act.app.ActionContext in project actframework by actframework.

the class ActBlockingExchange method close.

@Override
public void close() throws IOException {
    ActionContext ctx = ctx();
    if (!exchange.isComplete()) {
        try {
            UndertowRequest req = (UndertowRequest) ctx.req();
            req.closeAndDrainRequest();
        } finally {
            ActResponse resp = ctx.resp();
            resp.close();
        }
    } else {
        try {
            UndertowRequest req = (UndertowRequest) ctx.req();
            req.freeResources();
        } finally {
            UndertowResponse resp = (UndertowResponse) ctx.resp();
            resp.freeResources();
        }
    }
}
Also used : ActResponse(act.ActResponse) ActionContext(act.app.ActionContext)

Example 9 with ActionContext

use of act.app.ActionContext in project actframework by actframework.

the class ActHttpHandler method handleRequest.

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    ActionContext ctx = createActionContext(exchange);
    client.handle(ctx, new UndertowNetworkDispatcher(exchange));
}
Also used : ActionContext(act.app.ActionContext)

Example 10 with ActionContext

use of act.app.ActionContext in project actframework by actframework.

the class RenderCSV method setDownloadHeader.

private static void setDownloadHeader(ActContext context) {
    if (context instanceof ActionContext) {
        ActionContext ctx = (ActionContext) context;
        UrlPath path = ctx.urlPath();
        String fileName = S.concat(S.underscore(path.lastPart()), ".csv");
        ctx.resp().contentDisposition(fileName, false);
    }
}
Also used : UrlPath(act.route.UrlPath) ActionContext(act.app.ActionContext)

Aggregations

ActionContext (act.app.ActionContext)15 CliContext (act.cli.CliContext)4 H (org.osgl.http.H)3 CliSession (act.cli.CliSession)2 ActResponse (act.ActResponse)1 JsonDTO (act.inject.param.JsonDTO)1 UrlPath (act.route.UrlPath)1 Template (act.view.Template)1 Format (org.osgl.http.H.Format)1 MvcConfig (org.osgl.mvc.MvcConfig)1 GetAction (org.osgl.mvc.annotation.GetAction)1 ISObject (org.osgl.storage.ISObject)1 S (org.osgl.util.S)1