Search in sources :

Example 26 with PageContext

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

the class CFMLSpoolerTaskListener method listen.

@Override
public void listen(Config config, Exception e) {
    if (!(config instanceof ConfigWeb))
        return;
    ConfigWeb cw = (ConfigWeb) config;
    PageContext pc = ThreadLocalPageContext.get();
    boolean pcCreated = false;
    if (pc == null) {
        pcCreated = true;
        Pair[] parr = new Pair[0];
        DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
        pc = ThreadUtil.createPageContext(cw, os, "localhost", "/", "", new Cookie[0], parr, null, parr, new StructImpl(), true, -1);
        pc.setRequestTimeout(config.getRequestTimeout().getMillis());
    }
    try {
        Struct args = new StructImpl();
        long l = task.lastExecution();
        if (l > 0)
            args.set("lastExecution", new DateTimeImpl(pc, l, true));
        l = task.nextExecution();
        if (l > 0)
            args.set("nextExecution", new DateTimeImpl(pc, l, true));
        args.set("created", new DateTimeImpl(pc, task.getCreation(), true));
        args.set(KeyConstants._id, task.getId());
        args.set(KeyConstants._type, task.getType());
        args.set(KeyConstants._detail, task.detail());
        args.set(KeyConstants._tries, task.tries());
        args.set("remainingtries", e == null ? 0 : task.getPlans().length - task.tries());
        args.set("closed", task.closed());
        args.set("passed", e == null);
        if (e != null)
            args.set("exception", new CatchBlockImpl(Caster.toPageException(e)));
        Struct curr = new StructImpl();
        args.set("caller", curr);
        curr.set("template", currTemplate.template);
        curr.set("line", new Double(currTemplate.line));
        Struct adv = new StructImpl();
        args.set("advanced", adv);
        adv.set("exceptions", task.getExceptions());
        adv.set("executedPlans", task.getPlans());
        _listen(pc, args);
    } catch (PageException pe) {
        SystemOut.printDate(pe);
    } finally {
        if (pcCreated)
            ThreadLocalPageContext.release();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) PageException(lucee.runtime.exp.PageException) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) Struct(lucee.runtime.type.Struct) StructImpl(lucee.runtime.type.StructImpl) CatchBlockImpl(lucee.runtime.exp.CatchBlockImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Pair(lucee.commons.lang.Pair)

Example 27 with PageContext

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

the class SpoolerTaskHTTPCall method execute.

public static final Object execute(RemoteClient client, Config config, String methodName, Struct args) throws PageException {
    // return rpc.callWithNamedValues(config, getMethodName(), getArguments());
    PageContext pc = ThreadLocalPageContext.get();
    // remove wsdl if necessary
    String url = client.getUrl();
    if (StringUtil.endsWithIgnoreCase(url, "?wsdl"))
        url = url.substring(0, url.length() - 5);
    // Params
    Map<String, String> params = new HashMap<String, String>();
    params.put("method", methodName);
    params.put("returnFormat", "json");
    try {
        Charset cs = pc.getWebCharset();
        params.put("argumentCollection", new JSONConverter(true, cs).serialize(pc, args, false));
        HTTPResponse res = HTTPEngine4Impl.post(HTTPUtil.toURL(url, true), client.getServerUsername(), client.getServerPassword(), -1L, true, pc.getWebCharset().name(), Constants.NAME + " Remote Invocation", client.getProxyData(), null, params);
        return new JSONExpressionInterpreter().interpret(pc, res.getContentAsString());
    } catch (IOException ioe) {
        throw Caster.toPageException(ioe);
    } catch (ConverterException ce) {
        throw Caster.toPageException(ce);
    }
}
Also used : ConverterException(lucee.runtime.converter.ConverterException) HashMap(java.util.HashMap) JSONExpressionInterpreter(lucee.runtime.interpreter.JSONExpressionInterpreter) HTTPResponse(lucee.commons.net.http.HTTPResponse) Charset(java.nio.charset.Charset) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) IOException(java.io.IOException) JSONConverter(lucee.runtime.converter.JSONConverter)

Example 28 with PageContext

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

the class XMLConverter 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) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException)

Example 29 with PageContext

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

the class CFMLEngineImpl method reset.

@Override
public void reset(String configId) {
    SystemOut.printDate("reset CFML Engine");
    getControler().close();
    RetireOutputStreamFactory.close();
    // release HTTP Pool
    HTTPEngine4Impl.releaseConnectionManager();
    releaseCache(getConfigServerImpl());
    CFMLFactoryImpl cfmlFactory;
    // ScopeContext scopeContext;
    try {
        Iterator<String> it = contextes.keySet().iterator();
        while (it.hasNext()) {
            try {
                cfmlFactory = (CFMLFactoryImpl) contextes.get(it.next());
                if (configId != null && !configId.equals(cfmlFactory.getConfigWebImpl().getIdentification().getId()))
                    continue;
                // scopes
                try {
                    cfmlFactory.getScopeContext().clear();
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
                // PageContext
                try {
                    cfmlFactory.resetPageContext();
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
                // Query Cache
                try {
                    PageContext pc = ThreadLocalPageContext.get();
                    if (pc != null) {
                        pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).clear(pc);
                        pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null).clear(pc);
                        pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null).clear(pc);
                    }
                // cfmlFactory.getDefaultQueryCache().clear(null);
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
                // Gateway
                try {
                    cfmlFactory.getConfigWebImpl().getGatewayEngine().reset();
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
                // Cache
                releaseCache(cfmlFactory.getConfigWebImpl());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
        // release felix itself
        shutdownFelix();
    } finally {
        // Controller
        controlerState.setActive(false);
    }
}
Also used : CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) PageContext(lucee.runtime.PageContext)

Example 30 with PageContext

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

the class DevNullOutputStream method flush.

public void flush() throws IOException {
    final CFMLEngine engine = CFMLEngineFactory.getInstance();
    final PageContext pc = engine.getThreadPageContext();
    pc.getRootWriter().flush();
}
Also used : PageContext(lucee.runtime.PageContext) CFMLEngine(lucee.loader.engine.CFMLEngine)

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