Search in sources :

Example 1 with CFMLFactoryImpl

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

the class ThreadUtil method clonePageContext.

public static PageContextImpl clonePageContext(PageContext pc, OutputStream os, boolean stateless, boolean register2Thread, boolean register2RunningThreads) {
    // TODO stateless
    CFMLFactoryImpl factory = (CFMLFactoryImpl) pc.getConfig().getFactory();
    HttpServletRequest req = new HTTPServletRequestWrap(cloneHttpServletRequest(pc));
    HttpServletResponse rsp = createHttpServletResponse(os);
    // copy state
    PageContextImpl pci = (PageContextImpl) pc;
    PageContextImpl dest = factory.getPageContextImpl(factory.getServlet(), req, rsp, null, false, -1, false, register2Thread, true, pc.getRequestTimeout(), register2RunningThreads, false, false);
    pci.copyStateTo(dest);
    return dest;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) HTTPServletRequestWrap(lucee.runtime.net.http.HTTPServletRequestWrap) HttpServletResponse(javax.servlet.http.HttpServletResponse) PageContextImpl(lucee.runtime.PageContextImpl)

Example 2 with CFMLFactoryImpl

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

the class Admin method doStopThread.

private void doStopThread() throws PageException {
    String contextId = getString("admin", "stopThread", "contextId");
    String threadId = getString("admin", "stopThread", "threadId");
    String stopType = getString("stopType", "exception");
    if (!(config instanceof ConfigServer))
        throw new ApplicationException("invalid context for this action");
    ConfigServer cs = (ConfigServer) config;
    ConfigWeb[] webs = cs.getConfigWebs();
    boolean has = false;
    for (int i = 0; i < webs.length; i++) {
        ConfigWebImpl cw = (ConfigWebImpl) webs[i];
        if (!cw.getIdentification().getId().equals(contextId))
            continue;
        ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
        has = true;
        break;
    }
    if (!has) {
        for (int i = 0; i < webs.length; i++) {
            ConfigWebImpl cw = (ConfigWebImpl) webs[i];
            if (!contextId.equals(cw.getLabel()))
                continue;
            ((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
            has = true;
            break;
        }
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ConfigServer(lucee.runtime.config.ConfigServer) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 3 with CFMLFactoryImpl

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

the class CFMLEngineImpl method getCFMLFactory.

@Override
public CFMLFactory getCFMLFactory(ServletConfig srvConfig, HttpServletRequest req) throws ServletException {
    ServletContext srvContext = srvConfig.getServletContext();
    String real = ReqRspUtil.getRootPath(srvContext);
    ConfigServerImpl cs = getConfigServerImpl();
    // Load JspFactory
    CFMLFactory factory = contextes.get(real);
    if (factory == null) {
        factory = initContextes.get(real);
        if (factory == null) {
            factory = loadJSPFactory(cs, srvConfig, initContextes.size());
            initContextes.put(real, factory);
        }
        contextes.put(real, factory);
        try {
            String cp = req.getContextPath();
            if (cp == null)
                cp = "";
            ((CFMLFactoryImpl) factory).setURL(new URL(req.getScheme(), req.getServerName(), req.getServerPort(), cp));
        } catch (MalformedURLException e) {
            SystemOut.printDate(e);
        }
    }
    return factory;
}
Also used : MalformedURLException(java.net.MalformedURLException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ServletContext(javax.servlet.ServletContext) CFMLFactory(lucee.runtime.CFMLFactory) ConfigServerImpl(lucee.runtime.config.ConfigServerImpl) URL(java.net.URL)

Example 4 with CFMLFactoryImpl

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

the class CFMLEngineImpl method _service.

private void _service(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, short type) throws ServletException, IOException {
    CFMLFactoryImpl factory = (CFMLFactoryImpl) getCFMLFactory(servlet.getServletConfig(), req);
    // is Lucee dialect enabled?
    if (type == Request.TYPE_LUCEE) {
        if (!((ConfigImpl) factory.getConfig()).allowLuceeDialect()) {
            try {
                PageContextImpl.notSupported();
            } catch (ApplicationException e) {
                throw new PageServletException(e);
            }
        }
    }
    boolean exeReqAsync = exeRequestAsync();
    PageContextImpl pc = factory.getPageContextImpl(servlet, req, rsp, null, false, -1, false, !exeReqAsync, false, -1, true, false, false);
    try {
        Request r = new Request(pc, type);
        if (exeReqAsync) {
            r.start();
            long ended = -1;
            do {
                SystemUtil.wait(Thread.currentThread(), 1000);
                // done?
                if (r.isDone()) {
                    // print.e("mas-done:"+System.currentTimeMillis());
                    break;
                } else // reach request timeout
                if (ended == -1 && (pc.getStartTime() + pc.getRequestTimeout()) < System.currentTimeMillis()) {
                    // print.e("req-time:"+System.currentTimeMillis());
                    CFMLFactoryImpl.terminate(pc, false);
                    ended = System.currentTimeMillis();
                // break; we do not break here, we give the thread itself the chance to end we need the exception output
                } else // the thread itself seem blocked, so we release this thread
                if (ended > -1 && ended + 10000 <= System.currentTimeMillis()) {
                    // print.e("give-up:"+System.currentTimeMillis());
                    break;
                }
            } while (true);
        } else // run in thread coming from servlet engine
        {
            try {
                Request.exe(pc, type, true, false);
            } catch (RequestTimeoutException rte) {
                if (rte.getThreadDeath() != null)
                    throw rte.getThreadDeath();
            } catch (NativeException ne) {
                if (ne.getCause() instanceof ThreadDeath)
                    throw (ThreadDeath) ne.getCause();
            } catch (ThreadDeath td) {
                throw td;
            } catch (Throwable t) {
            }
        }
    } finally {
        factory.releaseLuceePageContext(pc, !exeReqAsync);
    }
}
Also used : RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) PageServletException(lucee.runtime.exp.PageServletException) PageContextImpl(lucee.runtime.PageContextImpl) NativeException(lucee.runtime.exp.NativeException)

Example 5 with CFMLFactoryImpl

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

the class SessionEndListener method doEnd.

@Override
public void doEnd(StorageScopeEngine engine, StorageScopeCleaner cleaner, String appName, String cfid) {
    CFMLFactoryImpl factory = engine.getFactory();
    ApplicationListener listener = factory.getConfig().getApplicationListener();
    try {
        cleaner.info("call onSessionEnd for " + appName + "/" + cfid);
        listener.onSessionEnd(factory, appName, cfid);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        ExceptionHandler.log(factory.getConfig(), Caster.toPageException(t));
    }
}
Also used : CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) ApplicationListener(lucee.runtime.listener.ApplicationListener)

Aggregations

CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)20 PageContextImpl (lucee.runtime.PageContextImpl)7 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)7 Collection (lucee.runtime.type.Collection)5 ScopeContext (lucee.runtime.type.scope.ScopeContext)5 ConfigWeb (lucee.runtime.config.ConfigWeb)4 ApplicationException (lucee.runtime.exp.ApplicationException)4 Struct (lucee.runtime.type.Struct)4 StructImpl (lucee.runtime.type.StructImpl)4 BundleCollection (lucee.loader.osgi.BundleCollection)3 CFMLFactory (lucee.runtime.CFMLFactory)3 PageContext (lucee.runtime.PageContext)3 ConfigServer (lucee.runtime.config.ConfigServer)3 Key (lucee.runtime.type.Collection.Key)3 MalformedURLException (java.net.MalformedURLException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ConfigServerImpl (lucee.runtime.config.ConfigServerImpl)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 NativeException (lucee.runtime.exp.NativeException)2 PageServletException (lucee.runtime.exp.PageServletException)2