Search in sources :

Example 6 with ApplicationListener

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

the class SessionEndCacheEvent method _doEnd.

private void _doEnd(CFMLFactoryImpl factory, String appName, String cfid) {
    ApplicationListener listener = factory.getConfig().getApplicationListener();
    try {
        factory.getScopeContext().info("call onSessionEnd for " + appName + "/" + cfid);
        listener.onSessionEnd(factory, appName, cfid);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        ExceptionHandler.log(factory.getConfig(), Caster.toPageException(t));
    }
}
Also used : ApplicationListener(lucee.runtime.listener.ApplicationListener)

Example 7 with ApplicationListener

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

the class SessionEndListener method doEnd.

@Override
public void doEnd(StorageScopeEngine engine, StorageScopeCleaner cleaner, String appName, String cfid) {
    CFMLFactoryImpl factory = engine.getFactory();
    ApplicationListener listener = factory.getConfig().getApplicationListener();
    try {
        cleaner.info("call onSessionEnd for " + appName + "/" + cfid);
        listener.onSessionEnd(factory, appName, cfid);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        ExceptionHandler.log(factory.getConfig(), Caster.toPageException(t));
    }
}
Also used : CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ApplicationListener(lucee.runtime.listener.ApplicationListener)

Example 8 with ApplicationListener

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

the class ScopeContext method clearApplication.

public void clearApplication(PageContext pc) throws PageException {
    if (applicationContexts.size() == 0)
        throw new ApplicationException("there is no application context defined");
    String name = pc.getApplicationContext().getName();
    CFMLFactoryImpl jspFactory = (CFMLFactoryImpl) pc.getCFMLFactory();
    Application application = applicationContexts.get(name);
    if (application == null)
        throw new ApplicationException("there is no application context defined with name [" + name + "]");
    ApplicationListener listener = PageContextUtil.getApplicationListener(pc);
    application.touch();
    try {
        listener.onApplicationEnd(jspFactory, name);
    } finally {
        applicationContexts.remove(name);
        application.release(pc);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ApplicationListener(lucee.runtime.listener.ApplicationListener)

Example 9 with ApplicationListener

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

the class PageContextImpl method execute.

private final void execute(PageSource ps, boolean throwExcpetion, boolean onlyTopLevel) throws PageException {
    ApplicationListener listener = getRequestDialect() == CFMLEngine.DIALECT_CFML ? (gatewayContext ? config.getApplicationListener() : ((MappingImpl) ps.getMapping()).getApplicationListener()) : ModernAppListener.getInstance();
    Throwable _t = null;
    try {
        initallog();
        listener.onRequest(this, ps, null);
        if (ormSession != null) {
            releaseORM();
            removeLastPageSource(true);
        }
        log(false);
    } catch (Throwable t) {
        PageException pe;
        if (t instanceof ThreadDeath && getTimeoutStackTrace() != null) {
            t = pe = new RequestTimeoutException(this, (ThreadDeath) t);
        } else
            pe = Caster.toPageException(t, false);
        _t = t;
        if (!Abort.isSilentAbort(pe)) {
            this.pe = pe;
            log(true);
            if (fdEnabled) {
                FDSignal.signal(pe, false);
            }
            listener.onError(this, pe);
        } else
            log(false);
        if (throwExcpetion) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw pe;
        }
    } finally {
        if (enablecfoutputonly > 0) {
            setCFOutputOnly((short) 0);
        }
        if (!gatewayContext && getConfig().debug()) {
            try {
                listener.onDebug(this);
            } catch (Exception e) {
                pe = Caster.toPageException(e);
                if (!Abort.isSilentAbort(pe))
                    listener.onError(this, pe);
                ExceptionUtil.rethrowIfNecessary(e);
            }
        }
        ps = null;
        if (_t != null)
            ExceptionUtil.rethrowIfNecessary(_t);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationListener(lucee.runtime.listener.ApplicationListener) PageException(lucee.runtime.exp.PageException) CasterException(lucee.runtime.exp.CasterException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) DatabaseException(lucee.runtime.exp.DatabaseException) ServletException(javax.servlet.ServletException) ModernAppListenerException(lucee.runtime.listener.ModernAppListenerException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 10 with ApplicationListener

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

the class XMLConfigWebFactory method loadMappings.

/**
 * load mapings from XML Document
 *
 * @param configServer
 * @param config
 * @param doc
 * @throws IOException
 */
private static void loadMappings(ConfigServerImpl configServer, ConfigImpl config, Document doc, int mode) throws IOException {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAPPING);
    Element el = getChildByName(doc.getDocumentElement(), "mappings");
    Element[] _mappings = getChildren(el, "mapping");
    Map<String, Mapping> mappings = MapFactory.<String, Mapping>getConcurrentMap();
    Mapping tmp;
    boolean finished = false;
    if (configServer != null && config instanceof ConfigWeb) {
        Mapping[] sm = configServer.getMappings();
        for (int i = 0; i < sm.length; i++) {
            if (!sm[i].isHidden()) {
                if ("/".equals(sm[i].getVirtual()))
                    finished = true;
                if (sm[i] instanceof MappingImpl) {
                    tmp = ((MappingImpl) sm[i]).cloneReadOnly(config);
                    mappings.put(tmp.getVirtualLowerCase(), tmp);
                } else {
                    tmp = sm[i];
                    mappings.put(tmp.getVirtualLowerCase(), tmp);
                }
            }
        }
    }
    if (hasAccess) {
        boolean hasServerContext = false;
        for (int i = 0; i < _mappings.length; i++) {
            el = _mappings[i];
            String physical = el.getAttribute("physical");
            String archive = el.getAttribute("archive");
            String virtual = getAttr(el, "virtual");
            String listType = getAttr(el, "listener-type");
            String listMode = getAttr(el, "listener-mode");
            boolean readonly = toBoolean(getAttr(el, "readonly"), false);
            boolean hidden = toBoolean(getAttr(el, "hidden"), false);
            boolean toplevel = toBoolean(getAttr(el, "toplevel"), true);
            if (config instanceof ConfigServer && (virtual.equalsIgnoreCase("/lucee-server/") || virtual.equalsIgnoreCase("/lucee-server-context/"))) {
                hasServerContext = true;
            }
            // lucee
            if (virtual.equalsIgnoreCase("/lucee/")) {
                if (StringUtil.isEmpty(listType, true))
                    listType = "modern";
                if (StringUtil.isEmpty(listMode, true))
                    listMode = "curr2root";
                toplevel = true;
            }
            int listenerMode = ConfigWebUtil.toListenerMode(listMode, -1);
            int listenerType = ConfigWebUtil.toListenerType(listType, -1);
            ApplicationListener listener = ConfigWebUtil.loadListener(listenerType, null);
            if (listener != null || listenerMode != -1) {
                // type
                if (mode == ConfigImpl.MODE_STRICT)
                    listener = new ModernAppListener();
                else if (listener == null)
                    listener = ConfigWebUtil.loadListener(ConfigWebUtil.toListenerType(config.getApplicationListener().getType(), -1), null);
                if (// this should never be true
                listener == null)
                    listener = new ModernAppListener();
                // mode
                if (listenerMode == -1) {
                    listenerMode = config.getApplicationListener().getMode();
                }
                listener.setMode(listenerMode);
            }
            // physical!=null &&
            if ((physical != null || archive != null)) {
                short insTemp = inspectTemplate(el);
                if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual) || "/lucee-server-context".equalsIgnoreCase(virtual))
                    insTemp = ConfigImpl.INSPECT_ONCE;
                String primary = getAttr(el, "primary");
                boolean physicalFirst = primary == null || !primary.equalsIgnoreCase("archive");
                tmp = new MappingImpl(config, virtual, physical, archive, insTemp, physicalFirst, hidden, readonly, toplevel, false, false, listener, listenerMode, listenerType);
                mappings.put(tmp.getVirtualLowerCase(), tmp);
                if (virtual.equals("/")) {
                    finished = true;
                // break;
                }
            }
        }
        // set default lucee-server-context
        if (config instanceof ConfigServer && !hasServerContext) {
            ApplicationListener listener = ConfigWebUtil.loadListener(ApplicationListener.TYPE_MODERN, null);
            listener.setMode(ApplicationListener.MODE_CURRENT2ROOT);
            tmp = new MappingImpl(config, "/lucee-server", "{lucee-server}/context/", null, ConfigImpl.INSPECT_ONCE, true, false, true, true, false, false, listener, ApplicationListener.MODE_CURRENT2ROOT, ApplicationListener.TYPE_MODERN);
            mappings.put(tmp.getVirtualLowerCase(), tmp);
        }
    }
    if (!finished) {
        if ((config instanceof ConfigWebImpl) && ResourceUtil.isUNCPath(config.getRootDirectory().getPath())) {
            tmp = new MappingImpl(config, "/", config.getRootDirectory().getPath(), null, ConfigImpl.INSPECT_UNDEFINED, true, true, true, true, false, false, null, -1, -1);
        } else {
            tmp = new MappingImpl(config, "/", "/", null, ConfigImpl.INSPECT_UNDEFINED, true, true, true, true, false, false, null, -1, -1);
        }
        mappings.put("/", tmp);
    }
    Mapping[] arrMapping = new Mapping[mappings.size()];
    int index = 0;
    Iterator it = mappings.keySet().iterator();
    while (it.hasNext()) {
        arrMapping[index++] = mappings.get(it.next());
    }
    config.setMappings(arrMapping);
// config.setMappings((Mapping[]) mappings.toArray(new
// Mapping[mappings.size()]));
}
Also used : ModernAppListener(lucee.runtime.listener.ModernAppListener) Element(org.w3c.dom.Element) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) lucee.aprint(lucee.aprint) ApplicationListener(lucee.runtime.listener.ApplicationListener) Iterator(java.util.Iterator)

Aggregations

ApplicationListener (lucee.runtime.listener.ApplicationListener)10 ApplicationException (lucee.runtime.exp.ApplicationException)4 IOException (java.io.IOException)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 PageException (lucee.runtime.exp.PageException)3 ServletException (javax.servlet.ServletException)2 JspException (javax.servlet.jsp.JspException)2 lucee.aprint (lucee.aprint)2 CacheException (lucee.commons.io.cache.exp.CacheException)2 Resource (lucee.commons.io.res.Resource)2 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)2 CasterException (lucee.runtime.exp.CasterException)2 DatabaseException (lucee.runtime.exp.DatabaseException)2 MissingIncludeException (lucee.runtime.exp.MissingIncludeException)2 RequestTimeoutException (lucee.runtime.exp.RequestTimeoutException)2 ModernAppListener (lucee.runtime.listener.ModernAppListener)2 ModernAppListenerException (lucee.runtime.listener.ModernAppListenerException)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1