Search in sources :

Example 1 with PageContext

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

the class HTTPServletRequestWrap method getInputStream.

@Override
public ServletInputStream getInputStream() throws IOException {
    // if(ba rr!=null) throw new IllegalStateException();
    if (barr == null) {
        if (!firstRead) {
            PageContext pc = ThreadLocalPageContext.get();
            if (pc != null) {
                return pc.formScope().getInputStream();
            }
            // throw new IllegalStateException();
            return new ServletInputStreamDummy(new byte[] {});
        }
        firstRead = false;
        if (isToBig(getContentLength())) {
            return req.getInputStream();
        }
        InputStream is = null;
        try {
            barr = IOUtil.toBytes(is = req.getInputStream());
        // Resource res = ResourcesImpl.getFileResourceProvider().getResource("/Users/mic/Temp/multipart.txt");
        // IOUtil.copy(new ByteArrayInputStream(barr), res, true);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            barr = null;
            return new ServletInputStreamDummy(new byte[] {});
        } finally {
            IOUtil.closeEL(is);
        }
    }
    return new ServletInputStreamDummy(barr);
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext)

Example 2 with PageContext

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

the class HttpUtil method cloneParameters.

public static Pair<String, String>[] cloneParameters(HttpServletRequest req) {
    List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>();
    Enumeration e = req.getParameterNames();
    String[] values;
    String name;
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        values = req.getParameterValues(name);
        if (values == null && ReqRspUtil.needEncoding(name, false))
            values = req.getParameterValues(ReqRspUtil.encode(name, ReqRspUtil.getCharacterEncoding(null, req)));
        if (values == null) {
            PageContext pc = ThreadLocalPageContext.get();
            if (pc != null && ReqRspUtil.identical(pc.getHttpServletRequest(), req)) {
                values = HTTPServletRequestWrap.getParameterValues(ThreadLocalPageContext.get(), name);
            }
        }
        if (values != null)
            for (int i = 0; i < values.length; i++) {
                parameters.add(new Pair<String, String>(name, values[i]));
            }
    }
    return parameters.toArray(new Pair[parameters.size()]);
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Pair(lucee.commons.lang.Pair)

Example 3 with PageContext

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

the class RequestDispatcherWrap method include.

@Override
public void include(ServletRequest req, ServletResponse rsp) throws ServletException, IOException {
    PageContext pc = ThreadLocalPageContext.get();
    if (pc == null) {
        this.req.getOriginalRequestDispatcher(realPath).include(req, rsp);
        return;
    }
    HTTPUtil.include(pc, req, rsp, realPath);
}
Also used : PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext)

Example 4 with PageContext

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

the class TagUtil method addTagMetaData.

/**
 * load metadata from cfc based custom tags and add the info to the tag
 * @param cs
 * @param config
 */
public static void addTagMetaData(ConfigWebImpl cw) {
    if (true)
        return;
    PageContextImpl pc = null;
    try {
        pc = ThreadUtil.createPageContext(cw, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", new Cookie[0], new Pair[0], null, new Pair[0], new StructImpl(), false, -1);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        return;
    }
    PageContext orgPC = ThreadLocalPageContext.get();
    try {
        ThreadLocalPageContext.register(pc);
        // MUST MOST of them are the same, so this is a huge overhead
        _addTagMetaData(pc, cw, CFMLEngine.DIALECT_CFML);
        _addTagMetaData(pc, cw, CFMLEngine.DIALECT_LUCEE);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        ThreadLocalPageContext.register(orgPC);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) StructImpl(lucee.runtime.type.StructImpl) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) PageContextImpl(lucee.runtime.PageContextImpl) Pair(lucee.commons.lang.Pair)

Example 5 with PageContext

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

the class ThreadTag method getThreadScopeNames.

public static java.util.Collection<String> getThreadScopeNames(PageContext pc, int level) {
    String[] names = null;
    java.util.Collection<String> result = new HashSet<String>();
    // current
    if ((level & LEVEL_CURRENT) > 0) {
        names = pc.getThreadScopeNames();
        if (names != null)
            for (int i = 0; i < names.length; i++) {
                result.add(names[i]);
            }
    }
    // parent
    if ((level & LEVEL_PARENTS) > 0) {
        PageContext parent = pc.getParentPageContext();
        while (parent != null) {
            names = parent.getThreadScopeNames();
            if (names != null)
                for (int i = 0; i < names.length; i++) {
                    result.add(names[i]);
                }
            parent = parent.getParentPageContext();
        }
    }
    // children
    if ((level & LEVEL_KIDS) > 0 && pc.hasFamily()) {
        getKidsThreadScopeNames(((PageContextImpl) pc).getChildPageContexts(), result, 0);
    }
    return result;
}
Also used : PageContext(lucee.runtime.PageContext) HashSet(java.util.HashSet)

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