Search in sources :

Example 11 with RefBoolean

use of lucee.commons.lang.types.RefBoolean in project Lucee by lucee.

the class CFMLEngineImpl method loadJSPFactory.

private CFMLFactoryImpl loadJSPFactory(ConfigServerImpl configServer, ServletConfig sg, int countExistingContextes) throws ServletException {
    try {
        if (XMLConfigWebFactory.LOG)
            SystemOut.printDate("load Context");
        // Load Config
        RefBoolean isCustomSetting = new RefBooleanImpl();
        Resource configDir = getConfigDirectory(sg, configServer, countExistingContextes, isCustomSetting);
        if (XMLConfigWebFactory.LOG)
            SystemOut.printDate("got context directory");
        CFMLFactoryImpl factory = new CFMLFactoryImpl(this, sg);
        if (XMLConfigWebFactory.LOG)
            SystemOut.printDate("init factory");
        ConfigWebImpl config = XMLConfigWebFactory.newInstance(this, factory, configServer, configDir, isCustomSetting.toBooleanValue(), sg);
        if (XMLConfigWebFactory.LOG)
            SystemOut.printDate("loaded config");
        factory.setConfig(config);
        return factory;
    } catch (Exception e) {
        ServletException se = new ServletException(e.getMessage());
        se.setStackTrace(e.getStackTrace());
        throw se;
    }
}
Also used : ServletException(javax.servlet.ServletException) PageServletException(lucee.runtime.exp.PageServletException) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) RefBoolean(lucee.commons.lang.types.RefBoolean) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) Resource(lucee.commons.io.res.Resource) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) JspException(javax.servlet.jsp.JspException) NativeException(lucee.runtime.exp.NativeException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PageServletException(lucee.runtime.exp.PageServletException) MalformedURLException(java.net.MalformedURLException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 12 with RefBoolean

use of lucee.commons.lang.types.RefBoolean in project Lucee by lucee.

the class PageContextImpl method initApplicationContext.

/**
 * @return return  value of method "onApplicationStart" or true
 * @throws PageException
 */
public boolean initApplicationContext(ApplicationListener listener) throws PageException {
    boolean initSession = false;
    // AppListenerSupport listener = (AppListenerSupport) config.get ApplicationListener();
    KeyLock<String> lock = config.getContextLock();
    String name = StringUtil.emptyIfNull(applicationContext.getName());
    String token = name + ":" + getCFID();
    Lock tokenLock = lock.lock(token, getRequestTimeout());
    // print.o("outer-lock  :"+token);
    try {
        // check session before executing any code
        initSession = applicationContext.isSetSessionManagement() && listener.hasOnSessionStart(this) && !scopeContext.hasExistingSessionScope(this);
        // init application
        Lock nameLock = lock.lock(name, getRequestTimeout());
        // print.o("inner-lock  :"+token);
        try {
            RefBoolean isNew = new RefBooleanImpl(false);
            // this is needed that the application scope is initilized
            application = scopeContext.getApplicationScope(this, isNew);
            if (isNew.toBooleanValue()) {
                try {
                    if (!listener.onApplicationStart(this)) {
                        scopeContext.removeApplicationScope(this);
                        return false;
                    }
                } catch (PageException pe) {
                    scopeContext.removeApplicationScope(this);
                    throw pe;
                }
            }
        } finally {
            // print.o("inner-unlock:"+token);
            lock.unlock(nameLock);
        }
        // init session
        if (initSession) {
            // this is needed that the session scope is initilized
            scopeContext.getSessionScope(this, DUMMY_BOOL);
            listener.onSessionStart(this);
        }
    } finally {
        // print.o("outer-unlock:"+token);
        lock.unlock(tokenLock);
    }
    return true;
}
Also used : PageException(lucee.runtime.exp.PageException) RefBoolean(lucee.commons.lang.types.RefBoolean) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) KeyLock(lucee.commons.lock.KeyLock) ActiveLock(lucee.runtime.debug.ActiveLock) Lock(lucee.commons.lock.Lock)

Example 13 with RefBoolean

use of lucee.commons.lang.types.RefBoolean in project Lucee by lucee.

the class CFMLTransformer method attribute.

/**
 * Liest ein einzelnes Atribut eines tag ein (nicht NONAME).
 * <br />
 * EBNF:<br />
 * <code>attribute-name  spaces "=" spaces attribute-value;</code>
 * @param tag Definition des Tag das dieses Attribut enthaelt.
 * @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
 * @return Element Attribute Element.
 * @throws TemplateException
 */
private static Attribute attribute(TagData data, TagLibTag tag, ArrayList<String> args, RefBoolean allowDefaultValue) throws TemplateException {
    Expression value = null;
    // Name
    StringBuffer sbType = new StringBuffer();
    RefBoolean dynamic = new RefBooleanImpl(false);
    boolean isDefaultValue = false;
    boolean[] parseExpression = new boolean[2];
    parseExpression[0] = true;
    parseExpression[1] = false;
    String name = attributeName(data.srcCode, dynamic, args, tag, sbType, parseExpression, allowDefaultValue.toBooleanValue());
    // mixed in a noname attribute
    if (StringUtil.isEmpty(name)) {
        allowDefaultValue.setValue(false);
        TagLibTagAttr attr = tag.getDefaultAttribute();
        if (attr == null)
            throw new TemplateException(data.srcCode, "Invalid Identifier.");
        name = attr.getName();
        sbType.append(attr.getType());
        isDefaultValue = true;
    }
    comment(data.srcCode, true);
    if (isDefaultValue || data.srcCode.forwardIfCurrent('=')) {
        comment(data.srcCode, true);
        // Value
        value = attributeValue(data, tag, sbType.toString(), parseExpression[0], false, data.factory.createLitString(""));
    } else // default value boolean true
    {
        TagLibTagAttr attr = tag.getAttribute(name);
        if (attr != null)
            value = attr.getUndefinedValue(data.factory);
        else
            value = tag.getAttributeUndefinedValue(data.factory);
        if (sbType.toString().length() > 0) {
            value = CastOther.toExpression(value, sbType.toString());
        }
    }
    comment(data.srcCode, true);
    return new Attribute(dynamic.toBooleanValue(), name, value, sbType.toString());
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) RefBoolean(lucee.commons.lang.types.RefBoolean) Expression(lucee.transformer.expression.Expression) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) LitString(lucee.transformer.expression.literal.LitString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 14 with RefBoolean

use of lucee.commons.lang.types.RefBoolean 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 15 with RefBoolean

use of lucee.commons.lang.types.RefBoolean in project Lucee by lucee.

the class ComponentHandler method setupService.

/**
 * handle all the work necessary set
 * up the "proxy" RPC service surrounding it as the MessageContext's
 * active service.
 */
protected void setupService(MessageContext msgContext) throws Exception {
    RefBoolean isnew = new RefBooleanImpl(false);
    Component cfc = (Component) msgContext.getProperty(Constants.COMPONENT);
    Class clazz = cfc.getJavaAccessClass(ThreadLocalPageContext.get(), isnew, false, true, true, true);
    String clazzName = clazz.getName();
    ClassLoader classLoader = clazz.getClassLoader();
    Pair pair;
    SOAPService rpc = null;
    if (!isnew.toBooleanValue() && (pair = (Pair) soapServices.get(clazzName)) != null) {
        if (classLoader == pair.classloader)
            rpc = pair.rpc;
    }
    // else classLoader = clazz.getClassLoader();
    // print.out("cl:"+classLoader);
    msgContext.setClassLoader(classLoader);
    if (rpc == null) {
        rpc = new SOAPService(new RPCProvider());
        rpc.setName(clazzName);
        rpc.setOption(JavaProvider.OPTION_CLASSNAME, clazzName);
        rpc.setEngine(msgContext.getAxisEngine());
        rpc.setOption(JavaProvider.OPTION_ALLOWEDMETHODS, "*");
        rpc.setOption(JavaProvider.OPTION_SCOPE, Scope.REQUEST.getName());
        rpc.getInitializedServiceDesc(msgContext);
        soapServices.put(clazzName, new Pair(classLoader, rpc));
    }
    rpc.setEngine(msgContext.getAxisEngine());
    // ??
    rpc.init();
    msgContext.setService(rpc);
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) RefBoolean(lucee.commons.lang.types.RefBoolean) RPCProvider(org.apache.axis.providers.java.RPCProvider) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Component(lucee.runtime.Component)

Aggregations

RefBoolean (lucee.commons.lang.types.RefBoolean)16 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)16 IOException (java.io.IOException)3 ParserString (lucee.commons.lang.ParserString)3 PageException (lucee.runtime.exp.PageException)3 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)3 ValueString (lucee.runtime.sql.exp.value.ValueString)3 Entry (java.util.Map.Entry)2 Resource (lucee.commons.io.res.Resource)2 Component (lucee.runtime.Component)2 PageSource (lucee.runtime.PageSource)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)2 TemplateException (lucee.runtime.exp.TemplateException)2 Expression (lucee.runtime.sql.exp.Expression)2 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)2 Expression (lucee.transformer.expression.Expression)2 LitString (lucee.transformer.expression.literal.LitString)2 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)2 Instrumentation (java.lang.instrument.Instrumentation)1