Search in sources :

Example 6 with ApplicationContext

use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.

the class ScopeContext method getApplicationScope.

/**
 * return the application Scope for this context (cfid,cftoken,contextname)
 *
 * @param pc PageContext
 * @param isNew
 * @return session matching the context
 * @throws PageException
 */
public Application getApplicationScope(PageContext pc, RefBoolean isNew) {
    ApplicationContext appContext = pc.getApplicationContext();
    // getApplication Scope from Context
    ApplicationImpl application;
    Object objApp = applicationContexts.get(appContext.getName());
    if (objApp != null) {
        application = (ApplicationImpl) objApp;
        if (application.isExpired()) {
            application.release(pc);
            isNew.setValue(true);
        }
    } else {
        application = new ApplicationImpl();
        applicationContexts.put(appContext.getName(), application);
        isNew.setValue(true);
    }
    application.touchBeforeRequest(pc);
    return application;
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext)

Example 7 with ApplicationContext

use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.

the class ScopeContext method removeClientScope.

public void removeClientScope(PageContext pc) throws PageException {
    Client cli = getClientScope(pc);
    ApplicationContext appContext = pc.getApplicationContext();
    Map<String, Scope> context = getSubMap(cfClientContexts, appContext.getName());
    if (context != null) {
        context.remove(pc.getCFID());
        if (cli != null)
            cli.unstore(pc.getConfig());
    }
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope)

Example 8 with ApplicationContext

use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.

the class ScopeContext method getClientScope.

public Client getClientScope(PageContext pc) throws PageException {
    ApplicationContext appContext = pc.getApplicationContext();
    // get Context
    Map<String, Scope> context = getSubMap(cfClientContexts, appContext.getName());
    // get Client
    boolean isMemory = false;
    String storage = appContext.getClientstorage();
    if (StringUtil.isEmpty(storage, true)) {
        storage = ConfigImpl.DEFAULT_STORAGE_CLIENT;
    } 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;
    }
    Client existing = (Client) context.get(pc.getCFID());
    Client client = appContext.getClientCluster() ? null : existing;
    // client=doMemory?(Client) context.get(pc.getCFID()):null;
    if (client == null || client.isExpired() || !client.getStorage().equalsIgnoreCase(storage)) {
        if ("file".equals(storage)) {
            client = ClientFile.getInstance(appContext.getName(), pc, getLog());
        } else if ("cookie".equals(storage))
            client = ClientCookie.getInstance(appContext.getName(), pc, getLog());
        else if ("memory".equals(storage)) {
            if (existing != null)
                client = existing;
            client = ClientMemory.getInstance(pc, getLog());
        } else {
            DataSource ds = pc.getDataSource(storage, null);
            if (ds != null) {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        // code above could fail when an old scope is loaded, remember client scope can be easy be
                        // 180 days old
                        client = ClientDatasource.getInstance(storage, pc, getLog());
                    }
                } else
                    client = ClientDatasource.getInstance(storage, pc, getLog());
            } else {
                if (INVIDUAL_STORAGE_KEYS) {
                    try {
                        client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
                    } catch (PageException pe) {
                        // code above could fail when an old scope is loaded, remember client scope can be easy be
                        // 180 days old
                        client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
                    }
                } else
                    client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
            }
            if (client == 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.");
                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.");
            }
        }
        client.setStorage(storage);
        context.put(pc.getCFID(), client);
    } else
        getLog().log(Log.LEVEL_INFO, "scope-context", "use existing client scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
    client.touchBeforeRequest(pc);
    return client;
}
Also used : PageException(lucee.runtime.exp.PageException) 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) DataSource(lucee.runtime.db.DataSource) IKHandlerDatasource(lucee.runtime.type.scope.storage.IKHandlerDatasource)

Example 9 with ApplicationContext

use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.

the class StorageScopeCookie method touchAfterRequest.

@Override
public void touchAfterRequest(PageContext pc) {
    boolean _isInit = isinit;
    super.touchAfterRequest(pc);
    if (!_isInit)
        return;
    ApplicationContext ac = pc.getApplicationContext();
    TimeSpan timespan = (getType() == SCOPE_CLIENT) ? ac.getClientTimeout() : ac.getSessionTimeout();
    Cookie cookie = pc.cookieScope();
    Date exp = new DateTimeImpl(pc, System.currentTimeMillis() + timespan.getMillis(), true);
    try {
        String ser = serializer.serializeStruct(sct, ignoreSet);
        if (hasChanges()) {
            cookie.setCookie(KeyImpl.init(cookieName), ser, exp, false, "/", null);
        }
        cookie.setCookie(KeyImpl.init(cookieName + "_LV"), Caster.toString(_lastvisit.getTime()), exp, false, "/", null);
        if (getType() == SCOPE_CLIENT) {
            cookie.setCookie(KeyImpl.init(cookieName + "_TC"), Caster.toString(timecreated.getTime()), exp, false, "/", null);
            cookie.setCookie(KeyImpl.init(cookieName + "_HC"), Caster.toString(sct.get(HITCOUNT, "")), exp, false, "/", null);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) Cookie(lucee.runtime.type.scope.Cookie) ApplicationContext(lucee.runtime.listener.ApplicationContext) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) Date(java.util.Date)

Example 10 with ApplicationContext

use of lucee.runtime.listener.ApplicationContext in project Lucee by lucee.

the class GetApplicationSettings method call.

public static Struct call(PageContext pc, boolean suppressFunctions) {
    ApplicationContext ac = pc.getApplicationContext();
    Component cfc = null;
    if (ac instanceof ModernApplicationContext)
        cfc = ((ModernApplicationContext) ac).getComponent();
    Struct sct = new StructImpl();
    sct.setEL("applicationTimeout", ac.getApplicationTimeout());
    sct.setEL("clientManagement", Caster.toBoolean(ac.isSetClientManagement()));
    sct.setEL("clientStorage", ac.getClientstorage());
    sct.setEL("sessionStorage", ac.getSessionstorage());
    sct.setEL("customTagPaths", toArray(ac.getCustomTagMappings()));
    sct.setEL("loginStorage", AppListenerUtil.translateLoginStorage(ac.getLoginStorage()));
    sct.setEL(KeyConstants._mappings, toStruct(ac.getMappings()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("scriptProtect", AppListenerUtil.translateScriptProtect(ac.getScriptProtect()));
    sct.setEL("secureJson", Caster.toBoolean(ac.getSecureJson()));
    sct.setEL("typeChecking", Caster.toBoolean(ac.getTypeChecking()));
    sct.setEL("secureJsonPrefix", ac.getSecureJsonPrefix());
    sct.setEL("sessionManagement", Caster.toBoolean(ac.isSetSessionManagement()));
    sct.setEL("sessionTimeout", ac.getSessionTimeout());
    sct.setEL("clientTimeout", ac.getClientTimeout());
    sct.setEL("setClientCookies", Caster.toBoolean(ac.isSetClientCookies()));
    sct.setEL("setDomainCookies", Caster.toBoolean(ac.isSetDomainCookies()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("localMode", ac.getLocalMode() == Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS ? Boolean.TRUE : Boolean.FALSE);
    sct.setEL(KeyConstants._locale, LocaleFactory.toString(pc.getLocale()));
    sct.setEL(KeyConstants._timezone, TimeZoneUtil.toString(pc.getTimeZone()));
    // scope cascading
    sct.setEL("scopeCascading", ConfigWebUtil.toScopeCascading(ac.getScopeCascading(), null));
    if (ac.getScopeCascading() != Config.SCOPE_SMALL) {
        sct.setEL("searchImplicitScopes", ac.getScopeCascading() == Config.SCOPE_STANDARD);
    }
    Struct cs = new StructImpl();
    cs.setEL("web", pc.getWebCharset().name());
    cs.setEL("resource", ((PageContextImpl) pc).getResourceCharset().name());
    sct.setEL("charset", cs);
    sct.setEL("sessionType", AppListenerUtil.toSessionType(((PageContextImpl) pc).getSessionType(), "application"));
    // TODO impl
    sct.setEL("serverSideFormValidation", Boolean.FALSE);
    sct.setEL("clientCluster", Caster.toBoolean(ac.getClientCluster()));
    sct.setEL("sessionCluster", Caster.toBoolean(ac.getSessionCluster()));
    sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
    sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
    Object ds = ac.getDefDataSource();
    if (ds instanceof DataSource)
        ds = _call((DataSource) ds);
    else
        ds = Caster.toString(ds, null);
    sct.setEL(KeyConstants._datasource, ds);
    sct.setEL("defaultDatasource", ds);
    Resource src = ac.getSource();
    if (src != null)
        sct.setEL(KeyConstants._source, src.getAbsolutePath());
    // orm
    if (ac.isORMEnabled()) {
        ORMConfiguration conf = ac.getORMConfiguration();
        if (conf != null)
            sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if (props != null) {
        sct.setEL(KeyConstants._s3, props.toStruct());
    }
    // ws settings
    {
        Struct wssettings = new StructImpl();
        wssettings.put(KeyConstants._type, AppListenerUtil.toWSType(ac.getWSType(), "Axis1"));
        sct.setEL("wssettings", wssettings);
    }
    // datasources
    Struct _sources = new StructImpl();
    sct.setEL(KeyConstants._datasources, _sources);
    DataSource[] sources = ac.getDataSources();
    if (!ArrayUtil.isEmpty(sources)) {
        for (int i = 0; i < sources.length; i++) {
            _sources.setEL(KeyImpl.init(sources[i].getName()), _call(sources[i]));
        }
    }
    // logs
    Struct _logs = new StructImpl();
    sct.setEL("logs", _logs);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Iterator<Key> it = acs.getLogNames().iterator();
        Key name;
        while (it.hasNext()) {
            name = it.next();
            _logs.setEL(name, acs.getLogMetaData(name.getString()));
        }
    }
    // mails
    Array _mails = new ArrayImpl();
    sct.setEL("mails", _mails);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Server[] servers = acs.getMailServers();
        Struct s;
        Server srv;
        if (servers != null) {
            for (int i = 0; i < servers.length; i++) {
                srv = servers[i];
                s = new StructImpl();
                _mails.appendEL(s);
                s.setEL(KeyConstants._host, srv.getHostName());
                s.setEL(KeyConstants._port, srv.getPort());
                if (!StringUtil.isEmpty(srv.getUsername()))
                    s.setEL(KeyConstants._username, srv.getUsername());
                if (!StringUtil.isEmpty(srv.getPassword()))
                    s.setEL(KeyConstants._password, srv.getPassword());
                s.setEL(KeyConstants._readonly, srv.isReadOnly());
                s.setEL("ssl", srv.isSSL());
                s.setEL("tls", srv.isTLS());
                if (srv instanceof ServerImpl) {
                    ServerImpl srvi = (ServerImpl) srv;
                    s.setEL("lifeTimespan", TimeSpanImpl.fromMillis(srvi.getLifeTimeSpan()));
                    s.setEL("idleTimespan", TimeSpanImpl.fromMillis(srvi.getIdleTimeSpan()));
                }
            }
        }
    }
    // tag
    Map<Key, Map<Collection.Key, Object>> tags = ac.getTagAttributeDefaultValues(pc);
    if (tags != null) {
        Struct tag = new StructImpl();
        Iterator<Entry<Key, Map<Collection.Key, Object>>> it = tags.entrySet().iterator();
        Entry<Collection.Key, Map<Collection.Key, Object>> e;
        Iterator<Entry<Collection.Key, Object>> iit;
        Entry<Collection.Key, Object> ee;
        Struct tmp;
        // TagLib lib = ((ConfigImpl)pc.getConfig()).getCoreTagLib();
        while (it.hasNext()) {
            e = it.next();
            iit = e.getValue().entrySet().iterator();
            tmp = new StructImpl();
            while (iit.hasNext()) {
                ee = iit.next();
                // lib.getTagByClassName(ee.getKey());
                tmp.setEL(ee.getKey(), ee.getValue());
            }
            tag.setEL(e.getKey(), tmp);
        }
        sct.setEL(KeyConstants._tag, tag);
    }
    // cache
    String fun = ac.getDefaultCacheName(Config.CACHE_TYPE_FUNCTION);
    String obj = ac.getDefaultCacheName(Config.CACHE_TYPE_OBJECT);
    String qry = ac.getDefaultCacheName(Config.CACHE_TYPE_QUERY);
    String res = ac.getDefaultCacheName(Config.CACHE_TYPE_RESOURCE);
    String tmp = ac.getDefaultCacheName(Config.CACHE_TYPE_TEMPLATE);
    String inc = ac.getDefaultCacheName(Config.CACHE_TYPE_INCLUDE);
    String htt = ac.getDefaultCacheName(Config.CACHE_TYPE_HTTP);
    String fil = ac.getDefaultCacheName(Config.CACHE_TYPE_FILE);
    String wse = ac.getDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE);
    // cache connections
    Struct conns = new StructImpl();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Key[] names = acs.getCacheConnectionNames();
        for (Key name : names) {
            CacheConnection data = acs.getCacheConnection(name.getString(), null);
            Struct _sct = new StructImpl();
            conns.setEL(name, _sct);
            _sct.setEL(KeyConstants._custom, data.getCustom());
            _sct.setEL(KeyConstants._storage, data.isStorage());
            ClassDefinition cd = data.getClassDefinition();
            if (cd != null) {
                _sct.setEL(KeyConstants._class, cd.getClassName());
                if (!StringUtil.isEmpty(cd.getName()))
                    _sct.setEL(KeyConstants._bundleName, cd.getClassName());
                if (cd.getVersion() != null)
                    _sct.setEL(KeyConstants._bundleVersion, cd.getVersionAsString());
            }
        }
    }
    if (!conns.isEmpty() || fun != null || obj != null || qry != null || res != null || tmp != null || inc != null || htt != null || fil != null || wse != null) {
        Struct cache = new StructImpl();
        sct.setEL(KeyConstants._cache, cache);
        if (fun != null)
            cache.setEL(KeyConstants._function, fun);
        if (obj != null)
            cache.setEL(KeyConstants._object, obj);
        if (qry != null)
            cache.setEL(KeyConstants._query, qry);
        if (res != null)
            cache.setEL(KeyConstants._resource, res);
        if (tmp != null)
            cache.setEL(KeyConstants._template, tmp);
        if (inc != null)
            cache.setEL(KeyConstants._include, inc);
        if (htt != null)
            cache.setEL(KeyConstants._http, htt);
        if (fil != null)
            cache.setEL(KeyConstants._file, fil);
        if (wse != null)
            cache.setEL(KeyConstants._webservice, wse);
        if (conns != null)
            cache.setEL(KeyConstants._connections, conns);
    }
    // java settings
    JavaSettings js = ac.getJavaSettings();
    StructImpl jsSct = new StructImpl();
    jsSct.put("loadCFMLClassPath", js.loadCFMLClassPath());
    jsSct.put("reloadOnChange", js.reloadOnChange());
    jsSct.put("watchInterval", new Double(js.watchInterval()));
    jsSct.put("watchExtensions", ListUtil.arrayToList(js.watchedExtensions(), ","));
    Resource[] reses = js.getResources();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reses.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(reses[i].getAbsolutePath());
    }
    jsSct.put("loadCFMLClassPath", sb.toString());
    sct.put("javaSettings", jsSct);
    if (cfc != null) {
        sct.setEL(KeyConstants._component, cfc.getPageSource().getDisplayPath());
        try {
            ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
            Iterator<Key> it = cw.keyIterator();
            Collection.Key key;
            Object value;
            while (it.hasNext()) {
                key = it.next();
                value = cw.get(key);
                if (suppressFunctions && value instanceof UDF)
                    continue;
                if (!sct.containsKey(key))
                    sct.setEL(key, value);
            }
        } catch (PageException e) {
            SystemOut.printDate(e);
        }
    }
    return sct;
}
Also used : Server(lucee.runtime.net.mail.Server) ArrayImpl(lucee.runtime.type.ArrayImpl) Properties(lucee.runtime.net.s3.Properties) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) Entry(java.util.Map.Entry) ServerImpl(lucee.runtime.net.mail.ServerImpl) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) ORMConfiguration(lucee.runtime.orm.ORMConfiguration) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) PageException(lucee.runtime.exp.PageException) JavaSettings(lucee.runtime.listener.JavaSettings) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) DataSource(lucee.runtime.db.DataSource) Array(lucee.runtime.type.Array) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) Map(java.util.Map) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Aggregations

ApplicationContext (lucee.runtime.listener.ApplicationContext)28 MemoryScope (lucee.runtime.type.scope.storage.MemoryScope)10 StorageScope (lucee.runtime.type.scope.storage.StorageScope)10 HttpSession (javax.servlet.http.HttpSession)6 DataSource (lucee.runtime.db.DataSource)4 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)4 Key (lucee.runtime.type.Collection.Key)4 CacheConnection (lucee.runtime.cache.CacheConnection)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 PageException (lucee.runtime.exp.PageException)3 TimeSpan (lucee.runtime.type.dt.TimeSpan)3 IKHandlerCache (lucee.runtime.type.scope.storage.IKHandlerCache)3 IKHandlerDatasource (lucee.runtime.type.scope.storage.IKHandlerDatasource)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Resource (lucee.commons.io.res.Resource)2 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 ClassicApplicationContext (lucee.runtime.listener.ClassicApplicationContext)2 ModernApplicationContext (lucee.runtime.listener.ModernApplicationContext)2