Search in sources :

Example 21 with PageContextImpl

use of lucee.runtime.PageContextImpl 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 22 with PageContextImpl

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

the class PageExceptionImpl method getGeneratedContent.

private String getGeneratedContent(PageContext pc) {
    PageContextImpl pci = (PageContextImpl) pc;
    CFMLWriter ro = pci.getRootOut();
    String gc = ro.toString();
    try {
        ro.clearBuffer();
    } catch (IOException ioe) {
    }
    if (gc == null)
        return "";
    return gc;
}
Also used : CFMLWriter(lucee.runtime.writer.CFMLWriter) PageContextImpl(lucee.runtime.PageContextImpl) IOException(java.io.IOException)

Example 23 with PageContextImpl

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

the class PageExceptionImpl method _getTagContext.

private static void _getTagContext(Config config, Array tagContext, StackTraceElement[] traces, LinkedList<PageSource> sources) {
    // StackTraceElement[] traces = getStackTraceElements(t);
    int line = 0;
    String template = "", tlast;
    Struct item;
    StackTraceElement trace = null;
    int index = -1;
    PageSource ps;
    PageContextImpl pc = null;
    if (config instanceof ConfigWeb)
        pc = (PageContextImpl) ThreadLocalPageContext.get();
    for (int i = 0; i < traces.length; i++) {
        trace = traces[i];
        tlast = template;
        template = trace.getFileName();
        if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        // content
        if (!StringUtil.emptyIfNull(tlast).equals(template))
            index++;
        String[] content = null;
        String dspPath = template;
        try {
            Resource res = config.getResource(template);
            if (!res.exists()) {
                PageSource _ps = pc == null ? null : pc.getPageSource(template);
                res = _ps == null ? null : _ps.getPhyscalFile();
                if (res == null || !res.exists()) {
                    res = config.getResource(_ps.getDisplayPath());
                    if (res != null && res.exists())
                        dspPath = res.getAbsolutePath();
                } else
                    dspPath = res.getAbsolutePath();
            } else
                dspPath = res.getAbsolutePath();
            // class was not build on the local filesystem
            if (!res.exists()) {
                SourceInfo si = pc != null ? MappingUtil.getMatch(pc, trace) : MappingUtil.getMatch(config, trace);
                if (si != null && si.relativePath != null) {
                    dspPath = si.relativePath;
                    res = ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), si.relativePath, true, true);
                    if (!res.exists()) {
                        PageSource _ps = PageSourceImpl.best(config.getPageSources(ThreadLocalPageContext.get(), null, si.relativePath, false, false, true));
                        if (_ps != null && _ps.exists()) {
                            res = _ps.getResource();
                            if (res != null && res.exists())
                                dspPath = res.getAbsolutePath();
                        } else
                            dspPath = res.getAbsolutePath();
                    } else
                        dspPath = res.getAbsolutePath();
                }
            }
            if (res.exists()) {
                InputStream is = res.getInputStream();
                if (ClassUtil.isBytecode(is)) {
                    // empty code array to show ??
                    content = new String[] {};
                } else
                    content = IOUtil.toStringArray(IOUtil.getReader(res, config.getTemplateCharset()));
                IOUtil.closeEL(is);
            } else {
                if (sources.size() > index)
                    ps = sources.get(index);
                else
                    ps = null;
                if (ps != null && trace.getClassName().equals(ps.getClassName())) {
                    if (ps.physcalExists())
                        content = IOUtil.toStringArray(IOUtil.getReader(ps.getPhyscalFile(), config.getTemplateCharset()));
                    template = ps.getDisplayPath();
                }
            }
        } catch (Throwable th) {
        }
        // check last
        if (tagContext.size() > 0) {
            try {
                Struct last = (Struct) tagContext.getE(tagContext.size());
                if (last.get(KeyConstants._Raw_Trace).equals(trace.toString()))
                    continue;
            } catch (Exception e) {
            }
        }
        item = new StructImpl();
        line = trace.getLineNumber();
        item.setEL(KeyConstants._template, dspPath);
        item.setEL(KeyConstants._line, new Double(line));
        item.setEL(KeyConstants._id, "??");
        item.setEL(KeyConstants._Raw_Trace, trace.toString());
        item.setEL(KeyConstants._type, "cfml");
        item.setEL(KeyConstants._column, new Double(0));
        if (content != null) {
            if (content.length > 0) {
                item.setEL(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
                item.setEL(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
            } else {
                item.setEL(KeyConstants._codePrintHTML, "??");
                item.setEL(KeyConstants._codePrintPlain, "??");
            }
        } else {
            item.setEL(KeyConstants._codePrintHTML, "");
            item.setEL(KeyConstants._codePrintPlain, "");
        }
        // FUTURE id
        tagContext.appendEL(item);
    }
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl)

Example 24 with PageContextImpl

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

the class FDControllerImpl method getByNativeIdentifier.

/**
 * checks a single CFMLFactory for the thread
 * @param name
 * @param factory
 * @param id
 * @return matching thread or null
 */
private FDThreadImpl getByNativeIdentifier(String name, CFMLFactoryImpl factory, String id) {
    Map<Integer, PageContextImpl> pcs = factory.getActivePageContexts();
    Iterator<PageContextImpl> it = pcs.values().iterator();
    PageContextImpl pc;
    while (it.hasNext()) {
        pc = it.next();
        if (equals(pc, id))
            return new FDThreadImpl(this, factory, name, pc);
    }
    return null;
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 25 with PageContextImpl

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

the class CustomTagUtil method loadInitFile.

public static InitFile loadInitFile(PageContext pc, String name, InitFile defaultValue) throws PageException {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    String[] filenames = getFileNames(config, name);
    boolean doCache = config.useCTPathCache();
    boolean doCustomTagDeepSearch = config.doCustomTagDeepSearch();
    PageSource ps = null;
    InitFile initFile;
    // CACHE
    // check local
    String localCacheName = null;
    Mapping[] actms = pc.getApplicationContext().getCustomTagMappings();
    Mapping[] cctms = config.getCustomTagMappings();
    if (doCache) {
        if (pc.getConfig().doLocalCustomTag()) {
            localCacheName = pc.getCurrentPageSource().getDisplayPath().replace('\\', '/');
            localCacheName = "local:" + localCacheName.substring(0, localCacheName.lastIndexOf('/') + 1).concat(name);
            initFile = config.getCTInitFile(pc, localCacheName);
            if (initFile != null)
                return initFile;
        }
        // cache application mapping
        if (actms != null)
            for (int i = 0; i < actms.length; i++) {
                initFile = config.getCTInitFile(pc, "application:" + actms[i].hashCode() + "/" + name);
                if (initFile != null)
                    return initFile;
            }
        // cache config mapping
        if (cctms != null)
            for (int i = 0; i < cctms.length; i++) {
                initFile = config.getCTInitFile(pc, "config:" + cctms[i].hashCode() + "/" + name);
                if (initFile != null)
                    return initFile;
            }
    }
    // search local
    if (pc.getConfig().doLocalCustomTag()) {
        for (int i = 0; i < filenames.length; i++) {
            PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(filenames[i]);
            // ps=pc.getRelativePageSource(filenames[i]);
            ps = MappingImpl.isOK(arr);
            if (ps != null) {
                initFile = new InitFile(pc, ps, filenames[i]);
                if (doCache)
                    config.putCTInitFile(localCacheName, initFile);
                return initFile;
            }
        }
    }
    // search application custom tag mapping
    if (actms != null) {
        for (int i = 0; i < filenames.length; i++) {
            ps = getMapping(actms, filenames[i], doCustomTagDeepSearch);
            if (ps != null) {
                initFile = new InitFile(pc, ps, filenames[i]);
                if (doCache)
                    config.putCTInitFile("application:" + ps.getMapping().hashCode() + "/" + name, initFile);
                return initFile;
            }
        }
    }
    // search custom tag mappings
    for (int i = 0; i < filenames.length; i++) {
        ps = getMapping(cctms, filenames[i], doCustomTagDeepSearch);
        if (ps != null) {
            initFile = new InitFile(pc, ps, filenames[i]);
            if (doCache)
                config.putCTInitFile("config:" + ps.getMapping().hashCode() + "/" + name, initFile);
            return initFile;
        }
    }
    return defaultValue;
}
Also used : Mapping(lucee.runtime.Mapping) PageContextImpl(lucee.runtime.PageContextImpl) ConfigImpl(lucee.runtime.config.ConfigImpl) PageSource(lucee.runtime.PageSource)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)84 PageSource (lucee.runtime.PageSource)19 Resource (lucee.commons.io.res.Resource)17 Key (lucee.runtime.type.Collection.Key)15 Struct (lucee.runtime.type.Struct)15 StructImpl (lucee.runtime.type.StructImpl)14 IOException (java.io.IOException)12 ApplicationException (lucee.runtime.exp.ApplicationException)10 PageException (lucee.runtime.exp.PageException)10 Component (lucee.runtime.Component)9 ConfigWeb (lucee.runtime.config.ConfigWeb)9 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)9 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)6 Mapping (lucee.runtime.Mapping)6 PageContext (lucee.runtime.PageContext)6 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5