Search in sources :

Example 1 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class Module method initFile.

@Override
public void initFile() throws MissingIncludeException, ExpressionException {
    ConfigWeb config = pageContext.getConfig();
    // MUSTMUST cache like ct
    // String[] filenames=getFileNames(config,getAppendix());// = appendix+'.'+config.getCFMLExtension();
    Object objTemplate = attributesScope.get(KeyConstants._template, null);
    Object objName = attributesScope.get(KeyConstants._name, null);
    source = null;
    if (objTemplate != null) {
        attributesScope.removeEL(KeyConstants._template);
        String template = objTemplate.toString();
        if (StringUtil.startsWith(template, '/')) {
            PageSource[] sources = ((PageContextImpl) pageContext).getPageSources(template);
            PageSource ps = MappingImpl.isOK(sources);
            if (ps == null)
                throw new MissingIncludeException(sources[0], "could not find template [" + template + "], file [" + sources[0].getDisplayPath() + "] doesn't exist");
            source = new InitFile(pageContext, ps, template);
        } else {
            source = new InitFile(pageContext, pageContext.getCurrentPageSource().getRealPage(template), template);
            if (!MappingImpl.isOK(source.getPageSource())) {
                throw new MissingIncludeException(source.getPageSource(), "could not find template [" + template + "], file [" + source.getPageSource().getDisplayPath() + "] doesn't exist");
            }
        }
        // attributesScope.removeEL(TEMPLATE);
        setAppendix(source.getPageSource());
    } else if (objName != null) {
        attributesScope.removeEL(KeyConstants._name);
        String[] filenames = toRealPath(config, objName.toString());
        boolean exist = false;
        // appcontext mappings
        Mapping[] ctms = pageContext.getApplicationContext().getCustomTagMappings();
        if (ctms != null) {
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        // config mappings
        if (!exist) {
            ctms = config.getCustomTagMappings();
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    // TODO optimieren siehe CFTag
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        if (!exist)
            throw new ExpressionException("custom tag (" + CustomTagUtil.getDisplayName(config, objName.toString()) + ") is not defined in custom tag directory [" + (ctms.length == 0 ? "no custom tag directory defined" : CustomTagUtil.toString(ctms)) + "]");
        setAppendix(source.getPageSource());
    } else {
        throw new ExpressionException("you must define attribute template or name for tag module");
    }
}
Also used : MissingIncludeException(lucee.runtime.exp.MissingIncludeException) InitFile(lucee.runtime.customtag.InitFile) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 2 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class Admin method doTerminateRunningThread.

private void doTerminateRunningThread() throws PageException {
    int id = getInt("admin", "RemoveRunningThread", "id");
    if (type == TYPE_WEB) {
        terminateRunningThread(pageContext.getConfig(), id);
    } else {
        ConfigServer cs = pageContext.getConfig().getConfigServer(password);
        ConfigWeb[] webs = cs.getConfigWebs();
        for (int i = 0; i < webs.length; i++) {
            if (terminateRunningThread(webs[i], id))
                break;
        }
    }
}
Also used : ConfigServer(lucee.runtime.config.ConfigServer) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 3 with ConfigWeb

use of lucee.runtime.config.ConfigWeb 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 4 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class SMTPClient method send.

public void send(PageContext pc, long sendTime) throws MailException {
    if (plainText == null && htmlText == null)
        throw new MailException("you must define plaintext or htmltext");
    Server[] servers = ((PageContextImpl) pc).getMailServers();
    ConfigWeb config = pc.getConfig();
    if (ArrayUtil.isEmpty(servers) && ArrayUtil.isEmpty(host))
        throw new MailException("no SMTP Server defined");
    if (spool == SPOOL_YES || (spool == SPOOL_UNDEFINED && config.isMailSpoolEnable())) {
        MailSpoolerTask mst = new MailSpoolerTask(this, servers, sendTime);
        if (listener instanceof Component)
            mst.setListener(new ComponentSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (Component) listener));
        else if (listener instanceof UDF)
            mst.setListener(new UDFSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (UDF) listener));
        config.getSpoolerEngine().add(mst);
    } else
        _send(config, servers);
}
Also used : Server(lucee.runtime.net.mail.Server) UDFSpoolerTaskListener(lucee.runtime.spooler.UDFSpoolerTaskListener) UDF(lucee.runtime.type.UDF) MailException(lucee.runtime.net.mail.MailException) PageContextImpl(lucee.runtime.PageContextImpl) MailSpoolerTask(lucee.runtime.spooler.mail.MailSpoolerTask) Component(lucee.runtime.Component) ConfigWeb(lucee.runtime.config.ConfigWeb) ComponentSpoolerTaskListener(lucee.runtime.spooler.ComponentSpoolerTaskListener)

Example 5 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class Admin method doStopThread.

private void doStopThread() throws PageException {
    String contextId = getString("admin", "stopThread", "contextId");
    String threadId = getString("admin", "stopThread", "threadId");
    String stopType = getString("stopType", "exception");
    if (!(config instanceof ConfigServer))
        throw new ApplicationException("invalid context for this action");
    ConfigServer cs = (ConfigServer) config;
    ConfigWeb[] webs = cs.getConfigWebs();
    boolean has = false;
    for (int i = 0; i < webs.length; i++) {
        ConfigWebImpl cw = (ConfigWebImpl) webs[i];
        if (!cw.getIdentification().getId().equals(contextId))
            continue;
        ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
        has = true;
        break;
    }
    if (!has) {
        for (int i = 0; i < webs.length; i++) {
            ConfigWebImpl cw = (ConfigWebImpl) webs[i];
            if (!contextId.equals(cw.getLabel()))
                continue;
            ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
            has = true;
            break;
        }
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ConfigServer(lucee.runtime.config.ConfigServer) ConfigWeb(lucee.runtime.config.ConfigWeb)

Aggregations

ConfigWeb (lucee.runtime.config.ConfigWeb)34 Resource (lucee.commons.io.res.Resource)9 PageContextImpl (lucee.runtime.PageContextImpl)9 StructImpl (lucee.runtime.type.StructImpl)7 PageSource (lucee.runtime.PageSource)6 ConfigServer (lucee.runtime.config.ConfigServer)6 IOException (java.io.IOException)5 CFMLFactory (lucee.runtime.CFMLFactory)5 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)5 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 PageException (lucee.runtime.exp.PageException)5 Struct (lucee.runtime.type.Struct)5 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)4 PageContext (lucee.runtime.PageContext)4 Config (lucee.runtime.config.Config)4 Log (lucee.commons.io.log.Log)3 Pair (lucee.commons.lang.Pair)3 Component (lucee.runtime.Component)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3