Search in sources :

Example 6 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class Update method doEndTag.

@Override
public int doEndTag() throws PageException {
    Object ds = DBInfo.getDatasource(pageContext, datasource);
    DataSourceManager manager = pageContext.getDataSourceManager();
    DatasourceConnection dc = ds instanceof DataSource ? manager.getConnection(pageContext, (DataSource) ds, username, password) : manager.getConnection(pageContext, Caster.toString(ds), username, password);
    try {
        Struct meta = null;
        try {
            meta = Insert.getMeta(dc, tablequalifier, tableowner, tablename);
        } catch (SQLException se) {
            meta = new StructImpl();
        }
        String[] pKeys = getPrimaryKeys(dc);
        SQL sql = createSQL(dc, pKeys, meta);
        if (sql != null) {
            lucee.runtime.type.Query query = new QueryImpl(pageContext, dc, sql, -1, -1, null, "query");
            if (pageContext.getConfig().debug()) {
                String dsn = ds instanceof DataSource ? ((DataSource) ds).getName() : Caster.toString(ds);
                boolean logdb = ((ConfigImpl) pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
                if (logdb) {
                    boolean debugUsage = DebuggerUtil.debugQueryUsage(pageContext, query);
                    pageContext.getDebugger().addQuery(debugUsage ? query : null, dsn, "", sql, query.getRecordcount(), pageContext.getCurrentPageSource(), query.getExecutionTime());
                }
            }
            // log
            Log log = pageContext.getConfig().getLog("datasource");
            if (log.getLogLevel() >= Log.LEVEL_INFO) {
                log.info("update tag", "executed [" + sql.toString().trim() + "] in " + DecimalFormat.call(pageContext, query.getExecutionTime() / 1000000D) + " ms");
            }
        }
        return EVAL_PAGE;
    } catch (PageException pe) {
        pageContext.getConfig().getLog("datasource").error("update tag", pe);
        throw pe;
    } finally {
        manager.releaseConnection(pageContext, dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) Log(lucee.commons.io.log.Log) DataSourceManager(lucee.runtime.db.DataSourceManager) DataSource(lucee.runtime.db.DataSource) Struct(lucee.runtime.type.Struct) SQL(lucee.runtime.db.SQL) QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 7 with Log

use of lucee.commons.io.log.Log 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 8 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class OSGiUtil method log.

private static void log(int level, String msg) {
    try {
        Config config = ThreadLocalPageContext.getConfig();
        Log log = config != null ? config.getLog("application") : null;
        if (log != null)
            log.log(level, "OSGi", msg);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        /* this can fail when called from an old loader */
        System.out.println(msg);
    }
}
Also used : Log(lucee.commons.io.log.Log) Config(lucee.runtime.config.Config)

Example 9 with Log

use of lucee.commons.io.log.Log 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 10 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class XMLConfigAdmin method updateRHExtension.

public void updateRHExtension(Config config, RHExtension rhext, boolean reload) throws PageException {
    ConfigImpl ci = (ConfigImpl) config;
    Log logger = ci.getLog("deploy");
    String type = ci instanceof ConfigWeb ? "web" : "server";
    // load already installed previous version and uninstall the parts no longer needed
    RHExtension existingRH = getRHExtension(ci, rhext.getId(), null);
    if (existingRH != null) {
        // same version
        if (existingRH.getVersion().compareTo(rhext.getVersion()) == 0) {
            removeRHExtension(config, existingRH, rhext, false);
        } else
            removeRHExtension(config, existingRH, rhext, true);
    }
    // INSTALL
    try {
        // boolean clearTags=false,clearFunction=false;
        boolean reloadNecessary = false;
        // store to xml
        BundleDefinition[] existing = _updateExtension(ci, rhext);
        // _storeAndReload();
        // this must happen after "store"
        // clean after populating the new ones
        cleanBundles(rhext, ci, existing);
        // ConfigWebAdmin.updateRHExtension(ci,rhext);
        ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(rhext.getExtensionFile().getInputStream()));
        ZipEntry entry;
        String path;
        String fileName;
        while ((entry = zis.getNextEntry()) != null) {
            path = entry.getName();
            fileName = fileName(entry);
            // jars
            if (!entry.isDirectory() && (startsWith(path, type, "jars") || startsWith(path, type, "jar") || startsWith(path, type, "bundles") || startsWith(path, type, "bundle") || startsWith(path, type, "lib") || startsWith(path, type, "libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
                Object obj = XMLConfigAdmin.installBundle(config, zis, fileName, rhext.getVersion(), false, false);
                // jar is not a bundle, only a regular jar
                if (!(obj instanceof BundleFile)) {
                    Resource tmp = (Resource) obj;
                    Resource tmpJar = tmp.getParentResource().getRealResource(ListUtil.last(path, "\\/"));
                    tmp.moveTo(tmpJar);
                    XMLConfigAdmin.updateJar(config, tmpJar, false);
                }
            }
            // flds
            if (!entry.isDirectory() && startsWith(path, type, "flds") && (StringUtil.endsWithIgnoreCase(path, ".fld") || StringUtil.endsWithIgnoreCase(path, ".fldx"))) {
                logger.log(Log.LEVEL_INFO, "extension", "deploy fld " + fileName);
                updateFLD(zis, fileName, false);
                reloadNecessary = true;
            }
            // tlds
            if (!entry.isDirectory() && startsWith(path, type, "tlds") && (StringUtil.endsWithIgnoreCase(path, ".tld") || StringUtil.endsWithIgnoreCase(path, ".tldx"))) {
                logger.log(Log.LEVEL_INFO, "extension", "deploy tld/tldx " + fileName);
                updateTLD(zis, fileName, false);
                reloadNecessary = true;
            }
            // tags
            if (!entry.isDirectory() && startsWith(path, type, "tags")) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy tag " + sub);
                updateTag(zis, sub, false);
                // clearTags=true;
                reloadNecessary = true;
            }
            // functions
            if (!entry.isDirectory() && startsWith(path, type, "functions")) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy function " + sub);
                updateFunction(zis, sub, false);
                // clearFunction=true;
                reloadNecessary = true;
            }
            // mappings
            if (!entry.isDirectory() && (startsWith(path, type, "archives") || startsWith(path, type, "mappings"))) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy mapping " + sub);
                updateArchive(zis, sub, false);
                reloadNecessary = true;
            // clearFunction=true;
            }
            // event-gateway
            if (!entry.isDirectory() && (startsWith(path, type, "event-gateways") || startsWith(path, type, "eventGateways")) && (StringUtil.endsWithIgnoreCase(path, "." + Constants.getCFMLComponentExtension()) || StringUtil.endsWithIgnoreCase(path, "." + Constants.getLuceeComponentExtension()))) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy event-gateway " + sub);
                updateEventGateway(zis, sub, false);
            }
            // context
            String realpath;
            if (!entry.isDirectory() && startsWith(path, type, "context") && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(8);
                logger.log(Log.LEVEL_INFO, "extension", "deploy context " + realpath);
                updateContext(zis, realpath, false, false);
            }
            // web contextS
            boolean first;
            if (!entry.isDirectory() && ((first = startsWith(path, type, "webcontexts")) || startsWith(path, type, "web.contexts")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(first ? 12 : 13);
                logger.log(Log.LEVEL_INFO, "extension", "deploy webcontext " + realpath);
                updateWebContexts(zis, realpath, false, false);
            }
            // applications
            if (!entry.isDirectory() && (startsWith(path, type, "applications") || startsWith(path, type, "web.applications") || startsWith(path, type, "web")) && !StringUtil.startsWith(fileName(entry), '.')) {
                int index;
                if (startsWith(path, type, "applications"))
                    index = 13;
                else if (startsWith(path, type, "web.applications"))
                    index = 17;
                else
                    // web
                    index = 4;
                realpath = path.substring(index);
                logger.log(Log.LEVEL_INFO, "extension", "deploy application " + realpath);
                updateApplication(zis, realpath, false);
            }
            // configs
            if (!entry.isDirectory() && (startsWith(path, type, "config")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(7);
                logger.log(Log.LEVEL_INFO, "extension", "deploy config " + realpath);
                updateConfigs(zis, realpath, false, false);
            }
            // components
            if (!entry.isDirectory() && (startsWith(path, type, "components")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(11);
                logger.log(Log.LEVEL_INFO, "extension", "deploy component " + realpath);
                updateComponent(zis, realpath, false, false);
            }
            // plugins
            if (!entry.isDirectory() && (startsWith(path, type, "plugins")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(8);
                logger.log(Log.LEVEL_INFO, "extension", "deploy plugin " + realpath);
                updatePlugin(zis, realpath, false);
            }
            zis.closeEntry();
        }
        // load the bundles
        if (rhext.getStartBundles()) {
            rhext.deployBundles(ci);
            BundleInfo[] bfs = rhext.getBundles();
            for (BundleInfo bf : bfs) {
                OSGiUtil.loadBundleFromLocal(bf.getSymbolicName(), bf.getVersion(), false, null);
            }
        }
        // update cache
        if (!ArrayUtil.isEmpty(rhext.getCaches())) {
            Iterator<Map<String, String>> itl = rhext.getCaches().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _updateCache(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update cache [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update cache handler
        if (!ArrayUtil.isEmpty(rhext.getCacheHandlers())) {
            Iterator<Map<String, String>> itl = rhext.getCacheHandlers().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _id = map.get("id");
                if (!StringUtil.isEmpty(_id) && cd != null && cd.hasClass()) {
                    _updateCacheHandler(_id, cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update cache handler [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update AMF
        if (!ArrayUtil.isEmpty(rhext.getAMFs())) {
            Iterator<Map<String, String>> itl = rhext.getAMFs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateAMFEngine(cd, map.get("caster"), map.get("configuration"));
                    reloadNecessary = true;
                }
                logger.info("extension", "update AMF engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update Search
        if (!ArrayUtil.isEmpty(rhext.getSearchs())) {
            Iterator<Map<String, String>> itl = rhext.getSearchs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateSearchEngine(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update search engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update Resource
        if (!ArrayUtil.isEmpty(rhext.getResources())) {
            Iterator<Map<String, String>> itl = rhext.getResources().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String scheme = map.get("scheme");
                if (cd != null && cd.hasClass() && !StringUtil.isEmpty(scheme)) {
                    Struct args = new StructImpl();
                    copyButIgnoreClassDef(map, args);
                    args.remove("scheme");
                    _updateResourceProvider(scheme, cd, args);
                    reloadNecessary = true;
                }
                logger.info("extension", "update resource provider [" + scheme + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update orm
        if (!ArrayUtil.isEmpty(rhext.getOrms())) {
            Iterator<Map<String, String>> itl = rhext.getOrms().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateORMEngine(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update orm engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update monitor
        if (!ArrayUtil.isEmpty(rhext.getMonitors())) {
            Iterator<Map<String, String>> itl = rhext.getMonitors().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateMonitorEnabled(true);
                    _updateMonitor(cd, map.get("type"), map.get("name"), true);
                    reloadNecessary = true;
                }
                logger.info("extension", "update monitor engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update jdbc
        if (!ArrayUtil.isEmpty(rhext.getJdbcs())) {
            Iterator<Map<String, String>> itl = rhext.getJdbcs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _label = map.get("label");
                if (cd != null && cd.isBundle()) {
                    _updateJDBCDriver(_label, cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update JDBC Driver [" + _label + ":" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update mapping
        if (!ArrayUtil.isEmpty(rhext.getMappings())) {
            Iterator<Map<String, String>> itl = rhext.getMappings().iterator();
            Map<String, String> map;
            String virtual, physical, archive, primary;
            short inspect;
            int lmode, ltype;
            boolean toplevel, readonly;
            while (itl.hasNext()) {
                map = itl.next();
                virtual = map.get("virtual");
                physical = map.get("physical");
                archive = map.get("archive");
                primary = map.get("primary");
                inspect = ConfigWebUtil.inspectTemplate(map.get("inspect"), Config.INSPECT_UNDEFINED);
                lmode = ConfigWebUtil.toListenerMode(map.get("listener-mode"), -1);
                ltype = ConfigWebUtil.toListenerType(map.get("listener-type"), -1);
                toplevel = Caster.toBooleanValue(map.get("toplevel"), false);
                readonly = Caster.toBooleanValue(map.get("readonly"), false);
                _updateMapping(virtual, physical, archive, primary, inspect, toplevel, lmode, ltype, readonly);
                reloadNecessary = true;
                logger.info("extension", "update Mapping [" + virtual + "]");
            }
        }
        if (!ArrayUtil.isEmpty(rhext.getEventGatewayInstances())) {
            Iterator<Map<String, Object>> itl = rhext.getEventGatewayInstances().iterator();
            Map<String, Object> map;
            while (itl.hasNext()) {
                map = itl.next();
                // id
                String id = Caster.toString(map.get("id"), null);
                // class
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                // component path
                String cfcPath = Caster.toString(map.get("cfc-path"), null);
                if (StringUtil.isEmpty(cfcPath))
                    cfcPath = Caster.toString(map.get("component-path"), null);
                // listener component path
                String listenerCfcPath = Caster.toString(map.get("listener-cfc-path"), null);
                if (StringUtil.isEmpty(listenerCfcPath))
                    listenerCfcPath = Caster.toString(map.get("listener-component-path"), null);
                // startup mode
                String strStartupMode = Caster.toString(map.get("startup-mode"), "automatic");
                int startupMode = GatewayEntryImpl.toStartup(strStartupMode, GatewayEntryImpl.STARTUP_MODE_AUTOMATIC);
                // read only
                boolean readOnly = Caster.toBooleanValue(map.get("read-only"), false);
                // custom
                Struct custom = Caster.toStruct(map.get("custom"), null);
                if (!StringUtil.isEmpty(id) && (!StringUtil.isEmpty(cfcPath) || (cd != null && cd.hasClass()))) {
                    _updateGatewayEntry(id, cd, cfcPath, listenerCfcPath, startupMode, custom, readOnly);
                }
                logger.info("extension", "update event gateway entry [" + id + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // reload
        // if(reloadNecessary){
        reloadNecessary = true;
        if (reload && reloadNecessary)
            _storeAndReload();
        else
            _store();
    // }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(rhext.getExtensionFile().getParentResource(), rhext.getExtensionFile());
        try {
            XMLConfigAdmin.removeRHExtension((ConfigImpl) config, rhext.getId(), false);
        } catch (Throwable t2) {
            ExceptionUtil.rethrowIfNecessary(t2);
        }
        throw Caster.toPageException(t);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) BundleInfo(lucee.runtime.osgi.BundleInfo) BundleFile(lucee.runtime.osgi.BundleFile) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) RHExtension(lucee.runtime.extension.RHExtension) ZipInputStream(java.util.zip.ZipInputStream) StructImpl(lucee.runtime.type.StructImpl) CreateObject(lucee.runtime.functions.other.CreateObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Log (lucee.commons.io.log.Log)35 ConfigImpl (lucee.runtime.config.ConfigImpl)14 PageException (lucee.runtime.exp.PageException)10 Resource (lucee.commons.io.res.Resource)8 ApplicationException (lucee.runtime.exp.ApplicationException)8 DatasourceConnection (lucee.runtime.db.DatasourceConnection)7 Struct (lucee.runtime.type.Struct)6 SQLException (java.sql.SQLException)5 ZipInputStream (java.util.zip.ZipInputStream)5 DataSource (lucee.runtime.db.DataSource)5 InputStream (java.io.InputStream)4 ZipEntry (java.util.zip.ZipEntry)4 StructImpl (lucee.runtime.type.StructImpl)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Attributes (java.util.jar.Attributes)3 DatabaseException (lucee.runtime.exp.DatabaseException)3 Key (lucee.runtime.type.Collection.Key)3