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));
}
}
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));
}
}
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);
}
}
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);
}
}
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()]));
}
Aggregations