Search in sources :

Example 1 with DevNullOutputStream

use of lucee.commons.io.DevNullOutputStream in project Lucee by lucee.

the class ChildThreadImpl method execute.

public PageException execute(Config config) {
    PageContext oldPc = ThreadLocalPageContext.get();
    Page p = page;
    PageContextImpl pc = null;
    try {
        // deamon
        if (this.pc != null) {
            pc = this.pc;
            ThreadLocalPageContext.register(pc);
        } else // task
        {
            ConfigWebImpl cwi;
            try {
                cwi = (ConfigWebImpl) config;
                DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
                pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
                pc.setRequestTimeout(requestTimeout);
                p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
            // p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
            } catch (PageException e) {
                return e;
            }
            pc.addPageSource(p.getPageSource(), true);
        }
        threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
        pc.setCurrentThreadScope(new ThreadsImpl(this));
        pc.setThread(Thread.currentThread());
        // String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
        Undefined undefined = pc.us();
        Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
        LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
        // Key[] keys = attrs.keys();
        Iterator<Entry<Key, Object>> it = attrs.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            newArgs.setEL(e.getKey(), e.getValue());
        }
        newLocal.setEL(KEY_ATTRIBUTES, newArgs);
        Argument oldArgs = pc.argumentsScope();
        Local oldLocal = pc.localScope();
        int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
        pc.setFunctionScopes(newLocal, newArgs);
        try {
            p.threadCall(pc, threadIndex);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!Abort.isSilentAbort(t)) {
                ConfigWeb c = pc.getConfig();
                if (c instanceof ConfigImpl) {
                    ConfigImpl ci = (ConfigImpl) c;
                    Log log = ci.getLog("thread");
                    if (log != null)
                        LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
                }
                PageException pe = Caster.toPageException(t);
                if (!serializable)
                    catchBlock = pe.getCatchBlock(pc.getConfig());
                return pe;
            }
        } finally {
            completed = true;
            pc.setFunctionScopes(oldLocal, oldArgs);
            undefined.setMode(oldMode);
            // pc.getScopeFactory().recycle(newArgs);
            pc.getScopeFactory().recycle(pc, newLocal);
            if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
                HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
                pc.flush();
                contentType = rsp.getContentType();
                Pair<String, Object>[] _headers = rsp.getHeaders();
                if (_headers != null)
                    for (int i = 0; i < _headers.length; i++) {
                        if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
                            contentEncoding = Caster.toString(_headers[i].getValue(), null);
                    }
            }
        }
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        pc = null;
        if (oldPc != null)
            ThreadLocalPageContext.register(oldPc);
    }
    return null;
}
Also used : Argument(lucee.runtime.type.scope.Argument) Page(lucee.runtime.Page) Entry(java.util.Map.Entry) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) LocalImpl(lucee.runtime.type.scope.LocalImpl) Pair(lucee.commons.lang.Pair) PageException(lucee.runtime.exp.PageException) Undefined(lucee.runtime.type.scope.Undefined) Log(lucee.commons.io.log.Log) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) ArgumentThreadImpl(lucee.runtime.type.scope.ArgumentThreadImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) Key(lucee.runtime.type.Collection.Key) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 2 with DevNullOutputStream

use of lucee.commons.io.DevNullOutputStream in project Lucee by lucee.

the class CFMLSpoolerTaskListener method listen.

@Override
public void listen(Config config, Exception e) {
    if (!(config instanceof ConfigWeb))
        return;
    ConfigWeb cw = (ConfigWeb) config;
    PageContext pc = ThreadLocalPageContext.get();
    boolean pcCreated = false;
    if (pc == null) {
        pcCreated = true;
        Pair[] parr = new Pair[0];
        DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
        pc = ThreadUtil.createPageContext(cw, os, "localhost", "/", "", new Cookie[0], parr, null, parr, new StructImpl(), true, -1);
        pc.setRequestTimeout(config.getRequestTimeout().getMillis());
    }
    try {
        Struct args = new StructImpl();
        long l = task.lastExecution();
        if (l > 0)
            args.set("lastExecution", new DateTimeImpl(pc, l, true));
        l = task.nextExecution();
        if (l > 0)
            args.set("nextExecution", new DateTimeImpl(pc, l, true));
        args.set("created", new DateTimeImpl(pc, task.getCreation(), true));
        args.set(KeyConstants._id, task.getId());
        args.set(KeyConstants._type, task.getType());
        args.set(KeyConstants._detail, task.detail());
        args.set(KeyConstants._tries, task.tries());
        args.set("remainingtries", e == null ? 0 : task.getPlans().length - task.tries());
        args.set("closed", task.closed());
        args.set("passed", e == null);
        if (e != null)
            args.set("exception", new CatchBlockImpl(Caster.toPageException(e)));
        Struct curr = new StructImpl();
        args.set("caller", curr);
        curr.set("template", currTemplate.template);
        curr.set("line", new Double(currTemplate.line));
        Struct adv = new StructImpl();
        args.set("advanced", adv);
        adv.set("exceptions", task.getExceptions());
        adv.set("executedPlans", task.getPlans());
        _listen(pc, args);
    } catch (PageException pe) {
        SystemOut.printDate(pe);
    } finally {
        if (pcCreated)
            ThreadLocalPageContext.release();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) PageException(lucee.runtime.exp.PageException) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) Struct(lucee.runtime.type.Struct) StructImpl(lucee.runtime.type.StructImpl) CatchBlockImpl(lucee.runtime.exp.CatchBlockImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Pair(lucee.commons.lang.Pair)

Aggregations

DevNullOutputStream (lucee.commons.io.DevNullOutputStream)2 Pair (lucee.commons.lang.Pair)2 PageContext (lucee.runtime.PageContext)2 ConfigWeb (lucee.runtime.config.ConfigWeb)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 PageException (lucee.runtime.exp.PageException)2 Entry (java.util.Map.Entry)1 Cookie (javax.servlet.http.Cookie)1 Log (lucee.commons.io.log.Log)1 Page (lucee.runtime.Page)1 PageContextImpl (lucee.runtime.PageContextImpl)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 CatchBlockImpl (lucee.runtime.exp.CatchBlockImpl)1 HttpServletResponseDummy (lucee.runtime.net.http.HttpServletResponseDummy)1 Key (lucee.runtime.type.Collection.Key)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)1 Argument (lucee.runtime.type.scope.Argument)1