use of lucee.runtime.Component in project Lucee by lucee.
the class ModernAppListener method onError.
@Override
public void onError(PageContext pc, PageException pe) {
Component app = apps.get(pc.getApplicationContext().getName());
if (app != null && app.containsKey(ON_ERROR) && !Abort.isSilentAbort(pe)) {
try {
String eventName = "";
if (pe instanceof ModernAppListenerException)
eventName = ((ModernAppListenerException) pe).getEventName();
if (eventName == null)
eventName = "";
call(app, pc, ON_ERROR, new Object[] { pe.getCatchBlock(pc), eventName }, true);
return;
} catch (PageException _pe) {
pe = _pe;
}
}
pc.handlePageException(pe);
}
use of lucee.runtime.Component in project Lucee by lucee.
the class ModernAppListener method _onRequest.
protected void _onRequest(PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
pci.setAppListenerType(ApplicationListener.TYPE_MODERN);
if (appPS != null) {
String callPath = appPS.getComponentName();
Component app = ComponentLoader.loadComponent(pci, appPS, callPath, false, false);
// init
ModernApplicationContext appContext = initApplicationContext(pci, app);
apps.put(appContext.getName(), app);
if (!pci.initApplicationContext(this))
return;
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
String targetPage = requestedPage.getRealpathWithVirtual();
RefBoolean goon = new RefBooleanImpl(true);
// onRequestStart
if (app.contains(pc, ON_REQUEST_START)) {
try {
Object rtn = call(app, pci, ON_REQUEST_START, new Object[] { targetPage }, false);
if (!Caster.toBooleanValue(rtn, true))
return;
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
// onRequest
if (goon.toBooleanValue()) {
boolean isComp = isComponent(pc, requestedPage);
Object method;
if (isComp && app.contains(pc, ON_CFCREQUEST) && (method = pc.urlFormScope().get(KeyConstants._method, null)) != null) {
Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);
url.removeEL(KeyConstants._fieldnames);
url.removeEL(KeyConstants._method);
Object args = url.get(KeyConstants._argumentCollection, null);
// url returnFormat
Object oReturnFormat = url.removeEL(KeyConstants._returnFormat);
int urlReturnFormat = -1;
if (oReturnFormat != null)
urlReturnFormat = UDFUtil.toReturnFormat(Caster.toString(oReturnFormat, null), -1);
// request header accept
List<MimeType> accept = ReqRspUtil.getAccept(pc);
int headerReturnFormat = MimeType.toFormat(accept, -1, -1);
Object queryFormat = url.removeEL(KeyConstants._queryFormat);
if (args == null) {
args = pc.getHttpServletRequest().getAttribute("argumentCollection");
}
if (args instanceof String) {
args = new JSONExpressionInterpreter().interpret(pc, (String) args);
}
if (args != null) {
if (Decision.isCastableToStruct(args)) {
Struct sct = Caster.toStruct(args, false);
// Key[] keys = url.keys();
Iterator<Entry<Key, Object>> it = url.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
sct.setEL(e.getKey(), e.getValue());
}
args = sct;
} else if (Decision.isCastableToArray(args)) {
args = Caster.toArray(args);
} else {
Array arr = new ArrayImpl();
arr.appendEL(args);
args = arr;
}
} else
args = url;
Object rtn = call(app, pci, ON_CFCREQUEST, new Object[] { requestedPage.getComponentName(), method, args }, true);
if (rtn != null) {
if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
pc.variablesScope().setEL("AMF-Forward", rtn);
// ThreadLocalWDDXResult.set(rtn);
} else {
try {
ComponentPageImpl.writeToResponseStream(pc, app, method.toString(), urlReturnFormat, headerReturnFormat, queryFormat, rtn);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
}
} else {
// TODO impl die nicht so generisch ist
try {
if (!isComp && app.contains(pc, ON_REQUEST))
call(app, pci, ON_REQUEST, new Object[] { targetPage }, false);
else
pci._doInclude(new PageSource[] { requestedPage }, false, null);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
}
// onRequestEnd
if (goon.toBooleanValue() && app.contains(pc, ON_REQUEST_END)) {
try {
call(app, pci, ON_REQUEST_END, new Object[] { targetPage }, false);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
} else {
apps.put(pc.getApplicationContext().getName(), null);
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
pci._doInclude(new PageSource[] { requestedPage }, false, null);
}
}
use of lucee.runtime.Component in project Lucee by lucee.
the class ModernAppListener method onApplicationEnd.
@Override
public void onApplicationEnd(CFMLFactory factory, String applicationName) throws PageException {
Component app = apps.get(applicationName);
if (app == null || !app.containsKey(ON_APPLICATION_END))
return;
PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
boolean createPc = pc == null;
try {
if (createPc)
pc = createPageContext(factory, app, applicationName, null, ON_APPLICATION_END, true, -1);
call(app, pc, ON_APPLICATION_END, new Object[] { pc.applicationScope() }, true);
} finally {
if (createPc && pc != null) {
factory.releaseLuceePageContext(pc, createPc);
}
}
}
use of lucee.runtime.Component in project Lucee by lucee.
the class GatewayEngineImpl method call.
public Object call(String cfcPath, String id, String functionName, Struct arguments, boolean cfcPeristent, Object defaultValue) throws PageException {
String requestURI = toRequestURI(cfcPath);
PageContext oldPC = ThreadLocalPageContext.get();
PageContextImpl pc = null;
try {
pc = createPageContext(requestURI, id, functionName, arguments, cfcPeristent, true);
String ext = ResourceUtil.getExtension(cfcPath, null);
ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
int dialect = ext == null ? CFMLEngine.DIALECT_CFML : config.getFactory().toDialect(ext);
// ThreadLocalPageContext.register(pc);
Component cfc = getCFC(pc, requestURI);
if (cfc.containsKey(functionName)) {
if (dialect == CFMLEngine.DIALECT_LUCEE)
pc.execute(requestURI, true, false);
else
pc.executeCFML(requestURI, true, false);
// Result
return pc.variablesScope().get(AMF_FORWARD, null);
}
} finally {
CFMLFactory f = config.getFactory();
f.releaseLuceePageContext(pc, true);
ThreadLocalPageContext.register(oldPC);
}
return defaultValue;
}
use of lucee.runtime.Component in project Lucee by lucee.
the class GatewayEngineImpl method getCFC.
private Component getCFC(PageContextImpl pc, String requestURI) throws PageException {
HttpServletRequest req = pc.getHttpServletRequest();
try {
String ext = ResourceUtil.getExtension(requestURI, "");
ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig(pc);
int dialect = config.getFactory().toDialect(ext);
req.setAttribute("client", "lucee-gateway-1-0");
req.setAttribute("call-type", "store-only");
if (dialect == CFMLEngine.DIALECT_LUCEE)
pc.execute(requestURI, true, false);
else
pc.executeCFML(requestURI, true, false);
return (Component) req.getAttribute("component");
} finally {
req.removeAttribute("call-type");
req.removeAttribute("component");
}
}
Aggregations