Search in sources :

Example 6 with PageContext

use of lucee.runtime.PageContext in project Lucee by lucee.

the class ChildThreadImpl method execute.

public PageException execute(Config config) {
    PageContext oldPc = ThreadLocalPageContext.get();
    Page p = page;
    PageContextImpl pc = null;
    try {
        // deamon
        if (this.pc != null) {
            pc = this.pc;
            ThreadLocalPageContext.register(pc);
        } else // task
        {
            ConfigWebImpl cwi;
            try {
                cwi = (ConfigWebImpl) config;
                DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
                pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
                pc.setRequestTimeout(requestTimeout);
                p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
            // p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
            } catch (PageException e) {
                return e;
            }
            pc.addPageSource(p.getPageSource(), true);
        }
        threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
        pc.setCurrentThreadScope(new ThreadsImpl(this));
        pc.setThread(Thread.currentThread());
        // String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
        Undefined undefined = pc.us();
        Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
        LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
        // Key[] keys = attrs.keys();
        Iterator<Entry<Key, Object>> it = attrs.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            newArgs.setEL(e.getKey(), e.getValue());
        }
        newLocal.setEL(KEY_ATTRIBUTES, newArgs);
        Argument oldArgs = pc.argumentsScope();
        Local oldLocal = pc.localScope();
        int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
        pc.setFunctionScopes(newLocal, newArgs);
        try {
            p.threadCall(pc, threadIndex);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!Abort.isSilentAbort(t)) {
                ConfigWeb c = pc.getConfig();
                if (c instanceof ConfigImpl) {
                    ConfigImpl ci = (ConfigImpl) c;
                    Log log = ci.getLog("thread");
                    if (log != null)
                        LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
                }
                PageException pe = Caster.toPageException(t);
                if (!serializable)
                    catchBlock = pe.getCatchBlock(pc.getConfig());
                return pe;
            }
        } finally {
            completed = true;
            pc.setFunctionScopes(oldLocal, oldArgs);
            undefined.setMode(oldMode);
            // pc.getScopeFactory().recycle(newArgs);
            pc.getScopeFactory().recycle(pc, newLocal);
            if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
                HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
                pc.flush();
                contentType = rsp.getContentType();
                Pair<String, Object>[] _headers = rsp.getHeaders();
                if (_headers != null)
                    for (int i = 0; i < _headers.length; i++) {
                        if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
                            contentEncoding = Caster.toString(_headers[i].getValue(), null);
                    }
            }
        }
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        pc = null;
        if (oldPc != null)
            ThreadLocalPageContext.register(oldPc);
    }
    return null;
}
Also used : Argument(lucee.runtime.type.scope.Argument) Page(lucee.runtime.Page) Entry(java.util.Map.Entry) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) LocalImpl(lucee.runtime.type.scope.LocalImpl) Pair(lucee.commons.lang.Pair) PageException(lucee.runtime.exp.PageException) Undefined(lucee.runtime.type.scope.Undefined) Log(lucee.commons.io.log.Log) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) ArgumentThreadImpl(lucee.runtime.type.scope.ArgumentThreadImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) Key(lucee.runtime.type.Collection.Key) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 7 with PageContext

use of lucee.runtime.PageContext in project Lucee by lucee.

the class ComponentController method _invoke.

public static Object _invoke(String name, Object[] args) throws PageException {
    Key key = Caster.toKey(name);
    Component c = component.get();
    PageContext p = pagecontext.get();
    MessageContext mc = messageContext.get();
    if (c == null)
        throw new ApplicationException("missing component");
    if (p == null)
        throw new ApplicationException("missing pagecontext");
    UDF udf = Caster.toFunction(c.get(p, key, null), null);
    FunctionArgument[] fa = null;
    if (udf != null)
        fa = udf.getFunctionArguments();
    for (int i = 0; i < args.length; i++) {
        if (fa != null && i < fa.length && fa[i].getType() == CFTypes.TYPE_UNKNOW) {
            args[i] = AxisCaster.toLuceeType(p, fa[i].getTypeAsString(), args[i]);
        } else
            args[i] = AxisCaster.toLuceeType(p, args[i]);
    }
    // return type
    String rtnType = udf != null ? udf.getReturnTypeAsString() : "any";
    Object rtn = c.call(p, key, args);
    // cast return value to Axis type
    try {
        RPCServer server = RPCServer.getInstance(p.getId(), p, p.getServletContext());
        TypeMapping tm = mc != null ? mc.getTypeMapping() : TypeMappingUtil.getServerTypeMapping(server.getEngine().getTypeMappingRegistry());
        rtn = Caster.castTo(p, rtnType, rtn, false);
        Class<?> clazz = Caster.cfTypeToClass(rtnType);
        return AxisCaster.toAxisType(tm, rtn, clazz.getComponentType() != null ? clazz : null);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) UDF(lucee.runtime.type.UDF) TypeMapping(javax.xml.rpc.encoding.TypeMapping) PageContext(lucee.runtime.PageContext) MessageContext(org.apache.axis.MessageContext) Component(lucee.runtime.Component) FunctionArgument(lucee.runtime.type.FunctionArgument) Key(lucee.runtime.type.Collection.Key)

Example 8 with PageContext

use of lucee.runtime.PageContext in project Lucee by lucee.

the class Caster method toArray.

/**
 * cast a Object to a Array Object
 * @param o Object to cast
 * @return casted Array
 * @throws PageException
 */
public static Array toArray(Object o) throws PageException {
    if (o instanceof Array)
        return (Array) o;
    else if (o instanceof Object[]) {
        return new ArrayImpl((Object[]) o);
    } else if (o instanceof List) {
        // new ArrayImpl(((List) o).toArray());
        return ListAsArray.toArray((List) o);
    } else if (o instanceof Set) {
        // new ArrayImpl(((List) o).toArray());
        return toArray(((Set) o).toArray());
    } else if (o instanceof XMLStruct) {
        XMLMultiElementStruct xmes;
        if (o instanceof XMLMultiElementStruct) {
            xmes = (XMLMultiElementStruct) o;
        } else {
            XMLStruct sct = (XMLStruct) o;
            Array a = new ArrayImpl();
            a.append(o);
            xmes = new XMLMultiElementStruct(a, sct.getCaseSensitive());
        }
        return new XMLMultiElementArray(xmes);
    } else if (o instanceof ObjectWrap) {
        return toArray(((ObjectWrap) o).getEmbededObject());
    } else if (o instanceof Struct) {
        // function _toArray
        if (o instanceof Component) {
            Component c = (Component) o;
            PageContext pc = ThreadLocalPageContext.get();
            if (pc != null) {
                Member member = c.getMember(Component.ACCESS_PRIVATE, KeyConstants.__toArray, false, false);
                // Object o = get(pc,"_toString",null);
                if (member instanceof UDFPlus) {
                    UDFPlus udf = (UDFPlus) member;
                    if (udf.getReturnType() == CFTypes.TYPE_ARRAY && udf.getFunctionArguments().length == 0) {
                        return Caster.toArray(c.call(pc, KeyConstants.__toArray, new Object[0]));
                    }
                }
            }
        }
        Struct sct = (Struct) o;
        Array arr = new ArrayImpl();
        Iterator<Entry<Key, Object>> it = sct.entryIterator();
        Entry<Key, Object> e = null;
        try {
            while (it.hasNext()) {
                e = it.next();
                arr.setE(toIntValue(e.getKey().getString()), e.getValue());
            }
        } catch (ExpressionException ee) {
            throw new ExpressionException("can't cast struct to a array, key [" + e.getKey().getString() + "] is not a number");
        }
        return arr;
    } else if (o instanceof boolean[])
        return new ArrayImpl(ArrayUtil.toReferenceType((boolean[]) o));
    else if (o instanceof byte[])
        return new ArrayImpl(ArrayUtil.toReferenceType((byte[]) o));
    else if (o instanceof char[])
        return new ArrayImpl(ArrayUtil.toReferenceType((char[]) o));
    else if (o instanceof short[])
        return new ArrayImpl(ArrayUtil.toReferenceType((short[]) o));
    else if (o instanceof int[])
        return new ArrayImpl(ArrayUtil.toReferenceType((int[]) o));
    else if (o instanceof long[])
        return new ArrayImpl(ArrayUtil.toReferenceType((long[]) o));
    else if (o instanceof float[])
        return new ArrayImpl(ArrayUtil.toReferenceType((float[]) o));
    else if (o instanceof double[])
        return new ArrayImpl(ArrayUtil.toReferenceType((double[]) o));
    throw new CasterException(o, "Array");
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) XMLMultiElementStruct(lucee.runtime.text.xml.struct.XMLMultiElementStruct) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) ObjectStruct(lucee.runtime.type.scope.ObjectStruct) MapAsStruct(lucee.runtime.type.wrap.MapAsStruct) Struct(lucee.runtime.type.Struct) CollectionStruct(lucee.runtime.type.CollectionStruct) Entry(java.util.Map.Entry) XMLMultiElementStruct(lucee.runtime.text.xml.struct.XMLMultiElementStruct) ArrayList(java.util.ArrayList) ArrayAsList(lucee.runtime.type.wrap.ArrayAsList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component) Member(lucee.runtime.component.Member) CasterException(lucee.runtime.exp.CasterException) ObjectWrap(lucee.runtime.type.ObjectWrap) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) UDFPlus(lucee.runtime.type.UDFPlus) Array(lucee.runtime.type.Array) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) ListAsArray(lucee.runtime.type.wrap.ListAsArray) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) JavaObject(lucee.runtime.java.JavaObject) Key(lucee.runtime.type.Collection.Key)

Example 9 with PageContext

use of lucee.runtime.PageContext in project Lucee by lucee.

the class Caster method otherTypeToClass.

private static Class<?> otherTypeToClass(String type) throws PageException, ClassException {
    PageContext pc = ThreadLocalPageContext.get();
    PageException pe = null;
    // try to load as cfc
    if (pc != null) {
        try {
            Component c = pc.loadComponent(type);
            return ComponentUtil.getComponentPropertiesClass(pc, c);
        } catch (PageException e) {
            pe = e;
        }
    }
    // try to load as class
    try {
        return ClassUtil.loadClass(type);
    } catch (ClassException ce) {
        if (pe != null)
            throw pe;
        throw ce;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ClassException(lucee.commons.lang.ClassException) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component)

Example 10 with PageContext

use of lucee.runtime.PageContext in project Lucee by lucee.

the class WDDXConverter method _deserializeComponent.

/**
 * Desirialize a Component Object
 *
 * @param elComp
 *            Component Object as XML Element
 * @return Component Object
 * @throws ConverterException
 * @throws ConverterException
 */
private Object _deserializeComponent(Element elComp) throws ConverterException {
    // String type=elStruct.getAttribute("type");
    String name = elComp.getAttribute("name");
    String md5 = elComp.getAttribute("md5");
    // TLPC
    PageContext pc = ThreadLocalPageContext.get();
    // Load comp
    Component comp = null;
    try {
        comp = pc.loadComponent(name);
        if (!ComponentUtil.md5(comp).equals(md5)) {
            throw new ConverterException("component [" + name + "] in this enviroment has not the same interface as the component to load, it is possible that one off the components has Functions added dynamicly.");
        }
    } catch (ConverterException e) {
        throw e;
    } catch (Exception e) {
        throw new ConverterException(e.getMessage());
    }
    NodeList list = elComp.getChildNodes();
    ComponentScope scope = comp.getComponentScope();
    int len = list.getLength();
    String scopeName;
    Element var, value;
    Collection.Key key;
    for (int i = 0; i < len; i++) {
        Node node = list.item(i);
        if (node instanceof Element) {
            var = (Element) node;
            value = getChildElement((Element) node);
            scopeName = var.getAttribute("scope");
            if (value != null) {
                key = Caster.toKey(var.getAttribute("name"), null);
                if (key == null)
                    continue;
                if ("variables".equalsIgnoreCase(scopeName))
                    scope.setEL(key, _deserialize(value));
                else
                    comp.setEL(key, _deserialize(value));
            }
        }
    }
    return comp;
}
Also used : Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Collection(lucee.runtime.type.Collection) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Component(lucee.runtime.Component) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) CoderException(lucee.runtime.coder.CoderException)

Aggregations

PageContext (lucee.runtime.PageContext)44 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)32 PageException (lucee.runtime.exp.PageException)11 Component (lucee.runtime.Component)7 PageContextImpl (lucee.runtime.PageContextImpl)6 IOException (java.io.IOException)5 Key (lucee.runtime.type.Collection.Key)5 Pair (lucee.commons.lang.Pair)4 ConfigWeb (lucee.runtime.config.ConfigWeb)4 Entry (java.util.Map.Entry)3 CFMLEngine (lucee.loader.engine.CFMLEngine)3 CFMLFactory (lucee.runtime.CFMLFactory)3 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)3 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)3 ArrayList (java.util.ArrayList)2 Cookie (javax.servlet.http.Cookie)2 TypeMapping (javax.xml.rpc.encoding.TypeMapping)2 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)2 ComponentScope (lucee.runtime.ComponentScope)2 Config (lucee.runtime.config.Config)2