Search in sources :

Example 6 with ConfigWeb

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

the class Controler method control.

private void control(CFMLFactoryImpl cfmlFactory, boolean do10Seconds, boolean doMinute, boolean doHour, boolean firstRun) {
    try {
        boolean isRunning = cfmlFactory.getUsedPageContextLength() > 0;
        if (isRunning) {
            cfmlFactory.checkTimeout();
        }
        ConfigWeb config = null;
        if (firstRun) {
            config = cfmlFactory.getConfig();
            ThreadLocalConfig.register(config);
            config.reloadTimeServerOffset();
            checkOldClientFile(config);
            // try{checkStorageScopeFile(config,Session.SCOPE_SESSION);}catch(Throwable t) {ExceptionUtil.rethrowIfNecessary(t);}
            try {
                config.reloadTimeServerOffset();
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            try {
                checkTempDirectorySize(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            try {
                checkCacheFileSize(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            try {
                cfmlFactory.getScopeContext().clearUnused();
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
        if (config == null) {
            config = cfmlFactory.getConfig();
        }
        ThreadLocalConfig.register(config);
        if (do10Seconds) {
        // try{DeployHandler.deploy(config);}catch(Throwable t){ExceptionUtil.rethrowIfNecessary(t);}
        }
        // every Minute
        if (doMinute) {
            if (config == null) {
                config = cfmlFactory.getConfig();
            }
            ThreadLocalConfig.register(config);
            // double check templates
            try {
                ((ConfigWebImpl) config).getCompiler().checkWatched();
            } catch (Exception e) {
                SystemOut.printDate(e);
            }
            // deploy extensions, archives ...
            try {
                DeployHandler.deploy(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // clear unused DB Connections
            try {
                ((ConfigImpl) config).getDatasourceConnectionPool().clear(false);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // clear all unused scopes
            try {
                cfmlFactory.getScopeContext().clearUnused();
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // try{checkPermGenSpace((ConfigWebImpl) config);}catch(Throwable t) {ExceptionUtil.rethrowIfNecessary(t);}
            try {
                doCheckMappings(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            try {
                doClearMailConnections();
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // clean LockManager
            if (cfmlFactory.getUsedPageContextLength() == 0)
                try {
                    ((LockManagerImpl) config.getLockManager()).clean();
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
            try {
                XMLConfigAdmin.checkForChangesInConfigFile(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
        // every hour
        if (doHour) {
            if (config == null) {
                config = cfmlFactory.getConfig();
            }
            ThreadLocalConfig.register(config);
            // time server offset
            try {
                config.reloadTimeServerOffset();
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // check temp directory
            try {
                checkTempDirectorySize(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
            // check cache directory
            try {
                checkCacheFileSize(config);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
        try {
            configServer.checkPermGenSpace(true);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    } finally {
        ThreadLocalConfig.release();
    }
}
Also used : ConfigWeb(lucee.runtime.config.ConfigWeb) IOException(java.io.IOException)

Example 7 with ConfigWeb

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

the class PageExceptionImpl method _getTagContext.

private static void _getTagContext(Config config, Array tagContext, StackTraceElement[] traces, LinkedList<PageSource> sources) {
    // StackTraceElement[] traces = getStackTraceElements(t);
    int line = 0;
    String template = "", tlast;
    Struct item;
    StackTraceElement trace = null;
    int index = -1;
    PageSource ps;
    PageContextImpl pc = null;
    if (config instanceof ConfigWeb)
        pc = (PageContextImpl) ThreadLocalPageContext.get();
    for (int i = 0; i < traces.length; i++) {
        trace = traces[i];
        tlast = template;
        template = trace.getFileName();
        if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        // content
        if (!StringUtil.emptyIfNull(tlast).equals(template))
            index++;
        String[] content = null;
        String dspPath = template;
        try {
            Resource res = config.getResource(template);
            if (!res.exists()) {
                PageSource _ps = pc == null ? null : pc.getPageSource(template);
                res = _ps == null ? null : _ps.getPhyscalFile();
                if (res == null || !res.exists()) {
                    res = config.getResource(_ps.getDisplayPath());
                    if (res != null && res.exists())
                        dspPath = res.getAbsolutePath();
                } else
                    dspPath = res.getAbsolutePath();
            } else
                dspPath = res.getAbsolutePath();
            // class was not build on the local filesystem
            if (!res.exists()) {
                SourceInfo si = pc != null ? MappingUtil.getMatch(pc, trace) : MappingUtil.getMatch(config, trace);
                if (si != null && si.relativePath != null) {
                    dspPath = si.relativePath;
                    res = ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), si.relativePath, true, true);
                    if (!res.exists()) {
                        PageSource _ps = PageSourceImpl.best(config.getPageSources(ThreadLocalPageContext.get(), null, si.relativePath, false, false, true));
                        if (_ps != null && _ps.exists()) {
                            res = _ps.getResource();
                            if (res != null && res.exists())
                                dspPath = res.getAbsolutePath();
                        } else
                            dspPath = res.getAbsolutePath();
                    } else
                        dspPath = res.getAbsolutePath();
                }
            }
            if (res.exists()) {
                InputStream is = res.getInputStream();
                if (ClassUtil.isBytecode(is)) {
                    // empty code array to show ??
                    content = new String[] {};
                } else
                    content = IOUtil.toStringArray(IOUtil.getReader(res, config.getTemplateCharset()));
                IOUtil.closeEL(is);
            } else {
                if (sources.size() > index)
                    ps = sources.get(index);
                else
                    ps = null;
                if (ps != null && trace.getClassName().equals(ps.getClassName())) {
                    if (ps.physcalExists())
                        content = IOUtil.toStringArray(IOUtil.getReader(ps.getPhyscalFile(), config.getTemplateCharset()));
                    template = ps.getDisplayPath();
                }
            }
        } catch (Throwable th) {
        }
        // check last
        if (tagContext.size() > 0) {
            try {
                Struct last = (Struct) tagContext.getE(tagContext.size());
                if (last.get(KeyConstants._Raw_Trace).equals(trace.toString()))
                    continue;
            } catch (Exception e) {
            }
        }
        item = new StructImpl();
        line = trace.getLineNumber();
        item.setEL(KeyConstants._template, dspPath);
        item.setEL(KeyConstants._line, new Double(line));
        item.setEL(KeyConstants._id, "??");
        item.setEL(KeyConstants._Raw_Trace, trace.toString());
        item.setEL(KeyConstants._type, "cfml");
        item.setEL(KeyConstants._column, new Double(0));
        if (content != null) {
            if (content.length > 0) {
                item.setEL(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
                item.setEL(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
            } else {
                item.setEL(KeyConstants._codePrintHTML, "??");
                item.setEL(KeyConstants._codePrintPlain, "??");
            }
        } else {
            item.setEL(KeyConstants._codePrintHTML, "");
            item.setEL(KeyConstants._codePrintPlain, "");
        }
        // FUTURE id
        tagContext.appendEL(item);
    }
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl)

Example 8 with ConfigWeb

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

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

the class CustomTagUtil method loadInitFile.

public static InitFile loadInitFile(PageContext pc, String name) throws PageException {
    InitFile initFile = loadInitFile(pc, name, null);
    if (initFile != null) {
        return initFile;
    }
    // EXCEPTION
    ConfigWeb config = pc.getConfig();
    // message
    StringBuilder msg = new StringBuilder("Custom tag \"").append(getDisplayName(config, name)).append("\" was not found.");
    List<String> dirs = new ArrayList();
    if (config.doLocalCustomTag()) {
        dirs.add(ResourceUtil.getResource(pc, pc.getCurrentPageSource()).getParent());
    }
    Mapping[] actms = pc.getApplicationContext().getCustomTagMappings();
    Mapping[] cctms = config.getCustomTagMappings();
    Resource r;
    if (actms != null) {
        for (Mapping m : actms) {
            r = m.getPhysical();
            if (r != null)
                dirs.add(r.toString());
        }
    }
    if (cctms != null) {
        for (Mapping m : cctms) {
            r = m.getPhysical();
            if (r != null)
                dirs.add(r.toString());
        }
    }
    if (!dirs.isEmpty()) {
        msg.append(" Directories searched: ");
        Iterator<String> it = dirs.iterator();
        while (it.hasNext()) {
            msg.append('"').append(it.next()).append('"');
            if (it.hasNext())
                msg.append(", ");
        }
    }
    throw new ExpressionException(msg.toString());
}
Also used : ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.Mapping) ConfigWeb(lucee.runtime.config.ConfigWeb) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 10 with ConfigWeb

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

the class DatasourceStorageScopeCleaner method _clean.

@Override
protected void _clean() {
    ConfigWeb config = engine.getFactory().getConfig();
    DataSource[] datasources = config.getDataSources();
    for (int i = 0; i < datasources.length; i++) {
        if (datasources[i].isStorage()) {
            try {
                clean(config, datasources[i]);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                error(t);
            }
        }
    }
}
Also used : ConfigWeb(lucee.runtime.config.ConfigWeb) DataSource(lucee.runtime.db.DataSource)

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