Search in sources :

Example 6 with ConfigImpl

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

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

the class SMTPClient method _send.

public void _send(lucee.runtime.config.ConfigWeb config, Server[] servers) throws MailException {
    long start = System.nanoTime();
    long _timeout = getTimeout(config);
    try {
        Proxy.start(proxyData);
        Log log = ((ConfigImpl) config).getLog("mail");
        // Server[] servers = config.getMailServers();
        if (host != null) {
            int prt;
            String usr, pwd;
            ServerImpl[] nServers = new ServerImpl[host.length];
            for (int i = 0; i < host.length; i++) {
                usr = null;
                pwd = null;
                prt = Server.DEFAULT_PORT;
                if (port > 0)
                    prt = port;
                if (!StringUtil.isEmpty(username)) {
                    usr = username;
                    pwd = password;
                }
                nServers[i] = toServerImpl(host[i], prt, usr, pwd, lifeTimespan, idleTimespan);
                if (ssl == SSL_YES)
                    nServers[i].setSSL(true);
                if (tls == TLS_YES)
                    nServers[i].setTLS(true);
            }
            servers = nServers;
        }
        if (servers.length == 0) {
            // return;
            throw new MailException("no SMTP Server defined");
        }
        boolean _ssl, _tls;
        for (int i = 0; i < servers.length; i++) {
            Server server = servers[i];
            String _username = null, _password = "";
            if (server.hasAuthentication()) {
                _username = server.getUsername();
                _password = server.getPassword();
            }
            // tls
            if (tls != TLS_NONE)
                _tls = tls == TLS_YES;
            else
                _tls = ((ServerImpl) server).isTLS();
            // ssl
            if (ssl != SSL_NONE)
                _ssl = ssl == SSL_YES;
            else
                _ssl = ((ServerImpl) server).isSSL();
            MimeMessageAndSession msgSess;
            boolean recyleConnection = ((ServerImpl) server).reuseConnections();
            {
                // synchronized(LOCK) {
                try {
                    msgSess = createMimeMessage(config, server.getHostName(), server.getPort(), _username, _password, ((ServerImpl) server).getLifeTimeSpan(), ((ServerImpl) server).getIdleTimeSpan(), _tls, _ssl, ((ConfigImpl) config).isMailSendPartial(), !recyleConnection, ((ConfigImpl) config).isUserset());
                } catch (MessagingException e) {
                    // listener
                    listener(config, server, log, e, System.nanoTime() - start);
                    MailException me = new MailException(e.getMessage());
                    me.setStackTrace(e.getStackTrace());
                    throw me;
                }
                try {
                    SerializableObject lock = new SerializableObject();
                    SMTPSender sender = new SMTPSender(lock, msgSess, server.getHostName(), server.getPort(), _username, _password, recyleConnection);
                    sender.start();
                    SystemUtil.wait(lock, _timeout);
                    if (!sender.isSent()) {
                        Throwable t = sender.getThrowable();
                        if (t != null)
                            throw Caster.toPageException(t);
                        // stop when still running
                        try {
                            if (sender.isAlive())
                                sender.stop();
                        } catch (Throwable t2) {
                            ExceptionUtil.rethrowIfNecessary(t2);
                        }
                        // after thread is stopped check sent flag again
                        if (!sender.isSent()) {
                            throw new MessagingException("timeout occurred after " + (_timeout / 1000) + " seconds while sending mail message");
                        }
                    }
                    // could have an exception but was send anyway
                    if (sender.getThrowable() != null) {
                        Throwable t = sender.getThrowable();
                        if (log != null)
                            LogUtil.log(log, Log.LEVEL_ERROR, "send mail", t);
                    }
                    clean(config, attachmentz);
                    listener(config, server, log, null, System.nanoTime() - start);
                    break;
                } catch (Exception e) {
                    SystemOut.printDate(e);
                    if (i + 1 == servers.length) {
                        listener(config, server, log, e, System.nanoTime() - start);
                        MailException me = new MailException(server.getHostName() + " " + ExceptionUtil.getStacktrace(e, true) + ":" + i);
                        me.setStackTrace(e.getStackTrace());
                        throw me;
                    }
                }
            }
        }
    } finally {
        Proxy.end();
    }
}
Also used : Server(lucee.runtime.net.mail.Server) Log(lucee.commons.io.log.Log) MessagingException(javax.mail.MessagingException) MessagingException(javax.mail.MessagingException) PageException(lucee.runtime.exp.PageException) FileNotFoundException(java.io.FileNotFoundException) MailException(lucee.runtime.net.mail.MailException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) SerializableObject(lucee.commons.lang.SerializableObject) ServerImpl(lucee.runtime.net.mail.ServerImpl) MailException(lucee.runtime.net.mail.MailException) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 8 with ConfigImpl

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

the class ThreadQueueImpl method _enter.

private void _enter(PageContext pc) throws IOException {
    ConfigImpl ci = (ConfigImpl) pc.getConfig();
    // print.e("enter("+Thread.currentThread().getName()+"):"+list.size());
    long start = System.currentTimeMillis();
    long timeout = ci.getQueueTimeout();
    if (timeout <= 0)
        timeout = pc.getRequestTimeout();
    while (true) {
        synchronized (token) {
            if (list.size() < ci.getQueueMax()) {
                // print.e("- ok("+Thread.currentThread().getName()+"):"+list.size());
                list.add(pc);
                return;
            }
        }
        if (timeout > 0)
            SystemUtil.wait(token, timeout);
        else
            SystemUtil.wait(token);
        if (timeout > 0 && (System.currentTimeMillis() - start) >= timeout)
            throw new IOException("Concurrent request timeout (" + (System.currentTimeMillis() - start) + ") [" + timeout + " ms] has occurred, server is too busy handling other requests. This timeout setting can be changed in the server administrator.");
    }
}
Also used : IOException(java.io.IOException) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 9 with ConfigImpl

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

the class RHExtension method readManifestConfig.

private void readManifestConfig(Manifest manifest, String label, String _img) throws ApplicationException {
    boolean isWeb = config instanceof ConfigWeb;
    type = isWeb ? "web" : "server";
    Log logger = ((ConfigImpl) config).getLog("deploy");
    Info info = ConfigWebUtil.getEngine(config).getInfo();
    Attributes attr = manifest.getMainAttributes();
    readName(label, StringUtil.unwrap(attr.getValue("name")));
    label = name;
    readVersion(label, StringUtil.unwrap(attr.getValue("version")));
    label += " : " + version;
    readId(label, StringUtil.unwrap(attr.getValue("id")));
    readReleaseType(label, StringUtil.unwrap(attr.getValue("release-type")), isWeb);
    description = StringUtil.unwrap(attr.getValue("description"));
    trial = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("trial")), false);
    if (_img == null)
        _img = StringUtil.unwrap(attr.getValue("image"));
    image = _img;
    String cat = StringUtil.unwrap(attr.getValue("category"));
    if (StringUtil.isEmpty(cat, true))
        cat = StringUtil.unwrap(attr.getValue("categories"));
    readCategories(label, cat);
    readCoreVersion(label, StringUtil.unwrap(attr.getValue("lucee-core-version")), info);
    readLoaderVersion(label, StringUtil.unwrap(attr.getValue("lucee-loader-version")));
    startBundles = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("start-bundles")), true);
    readAMF(label, StringUtil.unwrap(attr.getValue("amf")), logger);
    readResource(label, StringUtil.unwrap(attr.getValue("resource")), logger);
    readSearch(label, StringUtil.unwrap(attr.getValue("search")), logger);
    readORM(label, StringUtil.unwrap(attr.getValue("orm")), logger);
    readMonitor(label, StringUtil.unwrap(attr.getValue("monitor")), logger);
    readCache(label, StringUtil.unwrap(attr.getValue("cache")), logger);
    readCacheHandler(label, StringUtil.unwrap(attr.getValue("cache-handler")), logger);
    readJDBC(label, StringUtil.unwrap(attr.getValue("jdbc")), logger);
    readMapping(label, StringUtil.unwrap(attr.getValue("mapping")), logger);
    readEventGatewayInstances(label, StringUtil.unwrap(attr.getValue("event-gateway-instance")), logger);
}
Also used : Log(lucee.commons.io.log.Log) Attributes(java.util.jar.Attributes) Info(lucee.Info) BundleInfo(lucee.runtime.osgi.BundleInfo) ConfigWeb(lucee.runtime.config.ConfigWeb) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 10 with ConfigImpl

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

the class CFMLFactoryImpl method terminate.

public static void terminate(PageContextImpl pc, boolean async) {
    Log log = ((ConfigImpl) pc.getConfig()).getLog("requesttimeout");
    if (log != null)
        LogUtil.log(log, Log.LEVEL_ERROR, "controler", "stop thread (" + pc.getId() + ") because run into a timeout " + getPath(pc) + "." + RequestTimeoutException.locks(pc), pc.getThread().getStackTrace());
    pc.getConfig().getThreadQueue().exit(pc);
    SystemUtil.stop(pc, log, async);
}
Also used : Log(lucee.commons.io.log.Log) ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

ConfigImpl (lucee.runtime.config.ConfigImpl)47 PageException (lucee.runtime.exp.PageException)15 Log (lucee.commons.io.log.Log)14 DatasourceConnection (lucee.runtime.db.DatasourceConnection)10 ApplicationException (lucee.runtime.exp.ApplicationException)8 Struct (lucee.runtime.type.Struct)8 StructImpl (lucee.runtime.type.StructImpl)8 DataSource (lucee.runtime.db.DataSource)7 DatasourceConnectionPool (lucee.runtime.db.DatasourceConnectionPool)7 SQLExecutor (lucee.runtime.type.scope.storage.db.SQLExecutor)7 SQLException (java.sql.SQLException)6 Resource (lucee.commons.io.res.Resource)6 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)6 QueryImpl (lucee.runtime.type.QueryImpl)5 ArrayList (java.util.ArrayList)4 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 Key (lucee.runtime.type.Collection.Key)4 IOException (java.io.IOException)3