Search in sources :

Example 6 with CFMLFactory

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

the class CFMLEngineImpl method serviceFile.

@Override
public void serviceFile(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
    req = new HTTPServletRequestWrap(req);
    CFMLFactory factory = getCFMLFactory(servlet.getServletConfig(), req);
    ConfigWeb config = factory.getConfig();
    PageSource ps = config.getPageSourceExisting(null, null, req.getServletPath(), false, true, true, false);
    if (ps == null) {
        rsp.sendError(404);
    } else {
        Resource res = ps.getResource();
        if (res == null) {
            rsp.sendError(404);
        } else {
            ReqRspUtil.setContentLength(rsp, res.length());
            String mt = servlet.getServletContext().getMimeType(req.getServletPath());
            if (!StringUtil.isEmpty(mt))
                ReqRspUtil.setContentType(rsp, mt);
            IOUtil.copy(res, rsp.getOutputStream(), true);
        }
    }
}
Also used : HTTPServletRequestWrap(lucee.runtime.net.http.HTTPServletRequestWrap) Resource(lucee.commons.io.res.Resource) CFMLFactory(lucee.runtime.CFMLFactory) ConfigWeb(lucee.runtime.config.ConfigWeb) PageSource(lucee.runtime.PageSource)

Example 7 with CFMLFactory

use of lucee.runtime.CFMLFactory 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 8 with CFMLFactory

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

the class GatewayEngineImpl method getComponent.

public Object getComponent(String cfcPath, String id) throws PageException {
    String requestURI = toRequestURI(cfcPath);
    PageContext oldPC = ThreadLocalPageContext.get();
    PageContextImpl pc = null;
    try {
        pc = createPageContext(requestURI, id, "init", null, false, true);
        // ThreadLocalPageContext.register(pc);
        return getCFC(pc, requestURI);
    } finally {
        CFMLFactory f = config.getFactory();
        f.releaseLuceePageContext(pc, true);
        ThreadLocalPageContext.register(oldPC);
    }
}
Also used : ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl)

Example 9 with CFMLFactory

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

the class CreationImpl method createPageContext.

@Override
public PageContext createPageContext(HttpServletRequest req, HttpServletResponse rsp, OutputStream out) {
    Config config = ThreadLocalPageContext.getConfig();
    if (!(config instanceof ConfigWeb))
        throw new RuntimeException("need a web context to create a PageContext");
    CFMLFactory factory = ((ConfigWeb) config).getFactory();
    return (PageContext) factory.getPageContext(factory.getServlet(), req, rsp, null, false, -1, false);
}
Also used : ServletConfig(javax.servlet.ServletConfig) Config(lucee.runtime.config.Config) CFMLFactory(lucee.runtime.CFMLFactory) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 10 with CFMLFactory

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

the class ResourceLockImpl method _read.

private void _read(String path) {
    long start = -1, now;
    Thread t;
    do {
        if ((t = resources.get(path)) == null) {
            // print.ln("read ok");
            return;
        }
        if (t == Thread.currentThread()) {
            // aprint.err(path);
            Config config = ThreadLocalPageContext.getConfig();
            if (config != null)
                SystemOut.printDate(config.getErrWriter(), "conflict in same thread: on " + path);
            // SystemOut.printDate(config.getErrWriter(),"conflict in same thread: on "+path+"\nStacktrace:\n"+StringUtil.replace(ExceptionUtil.getStacktrace(new Throwable(), false),"java.lang.Throwable\n","",true));
            return;
        }
        // bugfix when lock von totem thread, wird es ignoriert
        if (!t.isAlive()) {
            resources.remove(path);
            return;
        }
        if (start == -1)
            start = System.currentTimeMillis();
        try {
            token.wait(lockTimeout);
            now = System.currentTimeMillis();
            if ((start + lockTimeout) <= now) {
                Config config = ThreadLocalPageContext.getConfig();
                if (config != null) {
                    PageContextImpl pc = null;
                    String add = "";
                    if (config instanceof ConfigWeb) {
                        CFMLFactory factory = ((ConfigWeb) config).getFactory();
                        if (factory instanceof CFMLFactoryImpl) {
                            Map<Integer, PageContextImpl> pcs = ((CFMLFactoryImpl) factory).getActivePageContexts();
                            Iterator<PageContextImpl> it = pcs.values().iterator();
                            PageContextImpl tmp;
                            while (it.hasNext()) {
                                tmp = it.next();
                                if (t == tmp.getThread()) {
                                    pc = tmp;
                                    break;
                                }
                            }
                        }
                    }
                    if (pc != null) {
                        add = " The file is locked by a request on the following URL " + ReqRspUtil.getRequestURL(pc.getHttpServletRequest(), true) + ", that request started " + (System.currentTimeMillis() - pc.getStartTime()) + "ms ago.";
                    }
                    SystemOut.printDate(config.getErrWriter(), "timeout after " + (now - start) + " ms (" + (lockTimeout) + " ms) occured while accessing file [" + path + "]." + add);
                } else
                    SystemOut.printDate("timeout (" + (lockTimeout) + " ms) occured while accessing file [" + path + "].");
                return;
            }
        } catch (InterruptedException e) {
        }
    } while (true);
}
Also used : CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) Config(lucee.runtime.config.Config) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb)

Aggregations

CFMLFactory (lucee.runtime.CFMLFactory)10 ConfigWeb (lucee.runtime.config.ConfigWeb)5 PageContextImpl (lucee.runtime.PageContextImpl)4 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)3 PageContext (lucee.runtime.PageContext)3 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 ServletConfig (javax.servlet.ServletConfig)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Config (lucee.runtime.config.Config)2 ConfigServerImpl (lucee.runtime.config.ConfigServerImpl)2 HTTPServletRequestWrap (lucee.runtime.net.http.HTTPServletRequestWrap)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1