Search in sources :

Example 11 with CacheConnection

use of lucee.runtime.cache.CacheConnection in project Lucee by lucee.

the class Application method set.

private boolean set(ApplicationContext ac, boolean update) throws PageException {
    if (applicationTimeout != null)
        ac.setApplicationTimeout(applicationTimeout);
    if (sessionTimeout != null)
        ac.setSessionTimeout(sessionTimeout);
    if (clientTimeout != null)
        ac.setClientTimeout(clientTimeout);
    if (requestTimeout != null)
        ac.setRequestTimeout(requestTimeout);
    if (clientstorage != null) {
        ac.setClientstorage(clientstorage);
    }
    if (sessionstorage != null) {
        ac.setSessionstorage(sessionstorage);
    }
    if (customTagMappings != null)
        ac.setCustomTagMappings(customTagMappings);
    if (componentMappings != null)
        ac.setComponentMappings(componentMappings);
    if (mappings != null)
        ac.setMappings(mappings);
    if (loginstorage != Scope.SCOPE_UNDEFINED)
        ac.setLoginStorage(loginstorage);
    if (!StringUtil.isEmpty(datasource)) {
        ac.setDefDataSource(datasource);
        ac.setORMDataSource(datasource);
    }
    if (!StringUtil.isEmpty(defaultdatasource))
        ac.setDefDataSource(defaultdatasource);
    if (datasources != null) {
        try {
            ac.setDataSources(AppListenerUtil.toDataSources(pageContext.getConfig(), datasources, pageContext.getConfig().getLog("application")));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (logs != null) {
        try {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            acs.setLoggers(ApplicationContextSupport.initLog(logs));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (mails != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        try {
            acs.setMailServers(AppListenerUtil.toMailServers(pageContext.getConfig(), mails, null));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (caches != null) {
        try {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            Iterator<Entry<Key, Object>> it = caches.entryIterator();
            Entry<Key, Object> e;
            String name;
            Struct sct;
            while (it.hasNext()) {
                e = it.next();
                // default value by name
                if (!StringUtil.isEmpty(name = Caster.toString(e.getValue(), null))) {
                    setDefault(ac, e.getKey(), name);
                } else // cache definition
                if ((sct = Caster.toStruct(e.getValue(), null)) != null) {
                    CacheConnection cc = ModernApplicationContext.toCacheConnection(pageContext.getConfig(), e.getKey().getString(), sct);
                    if (cc != null) {
                        name = e.getKey().getString();
                        acs.setCacheConnection(name, cc);
                        // key is a cache type
                        setDefault(ac, e.getKey(), name);
                        // default key
                        Key def = Caster.toKey(sct.get(KeyConstants._default, null), null);
                        if (def != null)
                            setDefault(ac, def, name);
                    }
                }
            }
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
    if (onmissingtemplate != null && ac instanceof ClassicApplicationContext) {
        ((ClassicApplicationContext) ac).setOnMissingTemplate(onmissingtemplate);
    }
    if (scriptrotect != null)
        ac.setScriptProtect(AppListenerUtil.translateScriptProtect(scriptrotect));
    if (bufferOutput != null)
        ac.setBufferOutput(bufferOutput.booleanValue());
    if (secureJson != null)
        ac.setSecureJson(secureJson.booleanValue());
    if (typeChecking != null)
        ac.setTypeChecking(typeChecking.booleanValue());
    if (suppress != null)
        ac.setSuppressContent(suppress.booleanValue());
    if (secureJsonPrefix != null)
        ac.setSecureJsonPrefix(secureJsonPrefix);
    if (setClientCookies != null)
        ac.setSetClientCookies(setClientCookies.booleanValue());
    if (setClientManagement != null)
        ac.setSetClientManagement(setClientManagement.booleanValue());
    if (setDomainCookies != null)
        ac.setSetDomainCookies(setDomainCookies.booleanValue());
    if (setSessionManagement != null)
        ac.setSetSessionManagement(setSessionManagement.booleanValue());
    if (localMode != -1)
        ac.setLocalMode(localMode);
    if (mailListener != null)
        ((ApplicationContextSupport) ac).setMailListener(mailListener);
    if (locale != null)
        ac.setLocale(locale);
    if (timeZone != null)
        ac.setTimeZone(timeZone);
    if (webCharset != null)
        ac.setWebCharset(webCharset.toCharset());
    if (resourceCharset != null)
        ac.setResourceCharset(resourceCharset.toCharset());
    if (sessionType != -1)
        ac.setSessionType(sessionType);
    if (wsType != -1)
        ac.setWSType(wsType);
    if (triggerDataMember != null)
        ac.setTriggerComponentDataMember(triggerDataMember.booleanValue());
    if (compression != null)
        ac.setAllowCompression(compression.booleanValue());
    if (cacheFunction != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_FUNCTION, cacheFunction);
    if (cacheObject != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_OBJECT, cacheObject);
    if (cacheQuery != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_QUERY, cacheQuery);
    if (cacheResource != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_RESOURCE, cacheResource);
    if (cacheTemplate != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_TEMPLATE, cacheTemplate);
    if (cacheInclude != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_INCLUDE, cacheInclude);
    if (cacheHTTP != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_HTTP, cacheHTTP);
    if (cacheFile != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_FILE, cacheFile);
    if (cacheWebservice != null)
        ac.setDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE, cacheWebservice);
    if (antiSamyPolicyResource != null)
        ((ApplicationContextSupport) ac).setAntiSamyPolicyResource(antiSamyPolicyResource);
    if (sessionCookie != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        acs.setSessionCookie(sessionCookie);
    }
    if (authCookie != null) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        acs.setAuthCookie(authCookie);
    }
    if (tag != null)
        ac.setTagAttributeDefaultValues(pageContext, tag);
    ac.setClientCluster(clientCluster);
    ac.setSessionCluster(sessionCluster);
    ac.setCGIScopeReadonly(cgiReadOnly);
    if (s3 != null)
        ac.setS3(AppListenerUtil.toS3(s3));
    // Scope cascading
    if (scopeCascading != -1)
        ac.setScopeCascading(scopeCascading);
    // ORM
    boolean initORM = false;
    if (!update) {
        if (ormenabled == null)
            ormenabled = false;
        if (ormsettings == null)
            ormsettings = new StructImpl();
    }
    if (ormenabled != null)
        ac.setORMEnabled(ormenabled);
    if (ac.isORMEnabled()) {
        initORM = true;
        if (ormsettings != null)
            AppListenerUtil.setORMConfiguration(pageContext, ac, ormsettings);
    }
    return initORM;
}
Also used : ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ClassicApplicationContext(lucee.runtime.listener.ClassicApplicationContext) PageException(lucee.runtime.exp.PageException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 12 with CacheConnection

use of lucee.runtime.cache.CacheConnection in project Lucee by lucee.

the class ScopeContext method getCFSessionScope.

/**
 * return cf session scope
 *
 * @param pc PageContext
 * @param isNew
 * @return cf session matching the context
 * @throws PageException
 */
private Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
    ApplicationContext appContext = pc.getApplicationContext();
    // get Context
    Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
    // get Session
    boolean isMemory = false;
    String storage = appContext.getSessionstorage();
    if (StringUtil.isEmpty(storage, true)) {
        storage = ConfigImpl.DEFAULT_STORAGE_SESSION;
        isMemory = true;
    } else if ("ram".equalsIgnoreCase(storage)) {
        storage = "memory";
        isMemory = true;
    } else if ("registry".equalsIgnoreCase(storage)) {
        storage = "file";
    } else {
        storage = storage.toLowerCase();
        if ("memory".equals(storage))
            isMemory = true;
    }
    Session existing = (Session) context.get(pc.getCFID());
    if (existing != null && (existing.isExpired() || !(existing instanceof StorageScope)))
        // second should not happen
        existing = null;
    Session session = appContext.getSessionCluster() ? null : existing;
    if (session == null || !(session instanceof StorageScope) || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
        // not necessary to check session in the same way, because it is overwritten anyway
        if (isMemory) {
            if (existing != null)
                session = existing;
            else
                session = SessionMemory.getInstance(pc, isNew, getLog());
        } else if ("file".equals(storage)) {
            session = SessionFile.getInstance(appContext.getName(), pc, getLog());
        } else if ("cookie".equals(storage))
            session = SessionCookie.getInstance(appContext.getName(), pc, getLog());
        else {
            DataSource ds = pc.getDataSource(storage, null);
            if (ds != null && ds.isStorage()) {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        session = SessionDatasource.getInstance(storage, pc, getLog(), null);
                    }
                } else
                    session = SessionDatasource.getInstance(storage, pc, getLog(), null);
            } else {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
                    }
                } else
                    session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
            }
            if (session == null) {
                // datasource not enabled for storage
                if (ds != null)
                    throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage, " + "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
                CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
                if (cc != null)
                    throw new ApplicationException("cache [" + storage + "] is not enabled to be used  as a session/client storage, you have to enable it in the Lucee administrator.");
                throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
            }
        }
        if (session instanceof StorageScope)
            ((StorageScope) session).setStorage(storage);
        context.put(pc.getCFID(), session);
        isNew.setValue(true);
    } else {
        getLog().log(Log.LEVEL_INFO, "scope-context", "use existing session scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
    }
    session.touchBeforeRequest(pc);
    return session;
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) PageException(lucee.runtime.exp.PageException) DataSource(lucee.runtime.db.DataSource) IKHandlerDatasource(lucee.runtime.type.scope.storage.IKHandlerDatasource) ApplicationContext(lucee.runtime.listener.ApplicationContext) ApplicationException(lucee.runtime.exp.ApplicationException) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) CacheConnection(lucee.runtime.cache.CacheConnection) IKHandlerCache(lucee.runtime.type.scope.storage.IKHandlerCache) HttpSession(javax.servlet.http.HttpSession)

Example 13 with CacheConnection

use of lucee.runtime.cache.CacheConnection in project Lucee by lucee.

the class CacheStorageScopeCleaner method _clean.

@Override
protected void _clean() {
    ConfigWebImpl config = (ConfigWebImpl) engine.getFactory().getConfig();
    Map<String, CacheConnection> connections = config.getCacheConnections();
    CacheConnection cc;
    if (connections != null) {
        Map.Entry<String, CacheConnection> entry;
        Iterator<Entry<String, CacheConnection>> it = connections.entrySet().iterator();
        while (it.hasNext()) {
            entry = it.next();
            cc = entry.getValue();
            if (cc.isStorage()) {
                try {
                    clean(cc, config);
                } catch (IOException e) {
                    error(e);
                }
            }
        }
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) CacheEntry(lucee.commons.io.cache.CacheEntry) Entry(java.util.Map.Entry) IOException(java.io.IOException) CacheConnection(lucee.runtime.cache.CacheConnection) Map(java.util.Map)

Example 14 with CacheConnection

use of lucee.runtime.cache.CacheConnection in project Lucee by lucee.

the class Admin method doGetCacheConnection.

private void doGetCacheConnection() throws PageException {
    String name = getString("admin", action, "name");
    Map conns = config.getCacheConnections();
    Iterator it = conns.keySet().iterator();
    CacheConnection cc;
    CacheConnection dObj = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_OBJECT);
    CacheConnection dTmp = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_TEMPLATE);
    CacheConnection dQry = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_QUERY);
    CacheConnection dRes = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_RESOURCE);
    CacheConnection dUDF = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FUNCTION);
    CacheConnection dInc = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_INCLUDE);
    CacheConnection dHTT = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_HTTP);
    CacheConnection dFil = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FILE);
    CacheConnection dWSe = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_WEBSERVICE);
    Struct sct;
    String d;
    while (it.hasNext()) {
        String key = (String) it.next();
        if (key.equalsIgnoreCase(name)) {
            cc = (CacheConnection) conns.get(key);
            sct = new StructImpl();
            d = "";
            if (cc == dObj)
                d = "object";
            else if (cc == dTmp)
                d = "template";
            else if (cc == dQry)
                d = "query";
            else if (cc == dRes)
                d = "resource";
            else if (cc == dUDF)
                d = "function";
            else if (cc == dInc)
                d = "include";
            else if (cc == dHTT)
                d = "http";
            else if (cc == dFil)
                d = "file";
            else if (cc == dWSe)
                d = "webservice";
            sct.setEL(KeyConstants._name, cc.getName());
            sct.setEL(KeyConstants._class, cc.getClassDefinition().getClassName());
            sct.setEL(KeyConstants._bundleName, cc.getClassDefinition().getName());
            sct.setEL(KeyConstants._bundleVersion, cc.getClassDefinition().getVersionAsString());
            sct.setEL(KeyConstants._custom, cc.getCustom());
            sct.setEL(KeyConstants._default, d);
            sct.setEL("readOnly", Caster.toBoolean(cc.isReadOnly()));
            sct.setEL("storage", Caster.toBoolean(cc.isStorage()));
            pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
            return;
        }
    }
    throw new ApplicationException("there is no cache connection with name [" + name + "]");
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) CacheConnection(lucee.runtime.cache.CacheConnection) Struct(lucee.runtime.type.Struct)

Example 15 with CacheConnection

use of lucee.runtime.cache.CacheConnection in project Lucee by lucee.

the class Admin method doGetCacheConnections.

private void doGetCacheConnections() throws PageException {
    Map conns = config.getCacheConnections();
    Iterator it = conns.entrySet().iterator();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "class", "bundleName", "bundleVersion", "name", "custom", "default", "readOnly", "storage" }, 0, "connections");
    Map.Entry entry;
    CacheConnection cc;
    CacheConnection defObj = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_OBJECT);
    CacheConnection defTmp = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_TEMPLATE);
    CacheConnection defQry = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_QUERY);
    CacheConnection defRes = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_RESOURCE);
    CacheConnection defUDF = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FUNCTION);
    CacheConnection defInc = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_INCLUDE);
    CacheConnection defHTT = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_HTTP);
    CacheConnection defFil = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FILE);
    CacheConnection defWSe = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_WEBSERVICE);
    int row = 0;
    String def;
    while (it.hasNext()) {
        row++;
        entry = (Entry) it.next();
        cc = (CacheConnection) entry.getValue();
        qry.addRow();
        def = "";
        if (cc == defObj)
            def = "object";
        if (cc == defTmp)
            def = "template";
        if (cc == defQry)
            def = "query";
        if (cc == defRes)
            def = "resource";
        if (cc == defUDF)
            def = "function";
        if (cc == defInc)
            def = "include";
        if (cc == defHTT)
            def = "http";
        if (cc == defFil)
            def = "file";
        if (cc == defWSe)
            def = "webservice";
        qry.setAtEL(KeyConstants._class, row, cc.getClassDefinition().getClassName());
        qry.setAtEL(KeyConstants._bundleName, row, cc.getClassDefinition().getName());
        qry.setAtEL(KeyConstants._bundleVersion, row, cc.getClassDefinition().getVersionAsString());
        qry.setAtEL(KeyConstants._name, row, cc.getName());
        qry.setAtEL(KeyConstants._custom, row, cc.getCustom());
        qry.setAtEL(KeyConstants._default, row, def);
        qry.setAtEL(KeyConstants._readonly, row, Caster.toBoolean(cc.isReadOnly()));
        qry.setAtEL(KeyConstants._storage, row, Caster.toBoolean(cc.isStorage()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Entry(java.util.Map.Entry) QueryImpl(lucee.runtime.type.QueryImpl) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) CacheConnection(lucee.runtime.cache.CacheConnection) Query(lucee.runtime.type.Query)

Aggregations

CacheConnection (lucee.runtime.cache.CacheConnection)21 Struct (lucee.runtime.type.Struct)9 ApplicationException (lucee.runtime.exp.ApplicationException)7 Entry (java.util.Map.Entry)6 Map (java.util.Map)5 DataSource (lucee.runtime.db.DataSource)4 PageException (lucee.runtime.exp.PageException)4 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)4 StructImpl (lucee.runtime.type.StructImpl)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 lucee.aprint (lucee.aprint)3 ServerCacheConnection (lucee.runtime.cache.ServerCacheConnection)3 ClassDefinition (lucee.runtime.db.ClassDefinition)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 ApplicationContext (lucee.runtime.listener.ApplicationContext)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 CacheConnectionImpl (lucee.runtime.cache.CacheConnectionImpl)2