Search in sources :

Example 26 with Component

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);
}
Also used : PageException(lucee.runtime.exp.PageException) Component(lucee.runtime.Component)

Example 27 with Component

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);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) RefBoolean(lucee.commons.lang.types.RefBoolean) ArrayImpl(lucee.runtime.type.ArrayImpl) PageContextImpl(lucee.runtime.PageContextImpl) MimeType(lucee.commons.lang.mimetype.MimeType) PageException(lucee.runtime.exp.PageException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) IOException(java.io.IOException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) JSONExpressionInterpreter(lucee.runtime.interpreter.JSONExpressionInterpreter) Component(lucee.runtime.Component) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Key(lucee.runtime.type.Collection.Key)

Example 28 with Component

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);
        }
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 29 with Component

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;
}
Also used : ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 30 with Component

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");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Component(lucee.runtime.Component) ConfigWeb(lucee.runtime.config.ConfigWeb)

Aggregations

Component (lucee.runtime.Component)36 PageException (lucee.runtime.exp.PageException)12 Key (lucee.runtime.type.Collection.Key)12 Struct (lucee.runtime.type.Struct)12 PageContextImpl (lucee.runtime.PageContextImpl)9 UDF (lucee.runtime.type.UDF)9 Entry (java.util.Map.Entry)7 ComponentScope (lucee.runtime.ComponentScope)7 PageContext (lucee.runtime.PageContext)7 Array (lucee.runtime.type.Array)7 JavaObject (lucee.runtime.java.JavaObject)6 IOException (java.io.IOException)5 PageSource (lucee.runtime.PageSource)5 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Collection (lucee.runtime.type.Collection)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)4 Property (lucee.runtime.component.Property)4 ArrayImpl (lucee.runtime.type.ArrayImpl)4 StructImpl (lucee.runtime.type.StructImpl)4