Search in sources :

Example 1 with HTTPServletRequestWrap

use of lucee.runtime.net.http.HTTPServletRequestWrap 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 HTTPServletRequestWrap

use of lucee.runtime.net.http.HTTPServletRequestWrap in project Lucee by lucee.

the class ThreadUtil method createPageContext.

/**
 * @param config
 * @param os
 * @param serverName
 * @param requestURI
 * @param queryString
 * @param cookies
 * @param headers
 * @param parameters
 * @param attributes
 * @param register
 * @param timeout timeout in ms, if the value is smaller than 1 it is ignored and the value comming from the context is used
 * @return
 */
public static PageContextImpl createPageContext(ConfigWeb config, OutputStream os, String serverName, String requestURI, String queryString, Cookie[] cookies, Pair[] headers, byte[] body, Pair[] parameters, Struct attributes, boolean register, long timeout) {
    CFMLFactory factory = config.getFactory();
    HttpServletRequest req = new HttpServletRequestDummy(config.getRootDirectory(), serverName, requestURI, queryString, cookies, headers, parameters, attributes, null, body);
    req = new HTTPServletRequestWrap(req);
    HttpServletResponse rsp = createHttpServletResponse(os);
    return (PageContextImpl) factory.getLuceePageContext(factory.getServlet(), req, rsp, null, false, -1, false, register, timeout, false, false);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HTTPServletRequestWrap(lucee.runtime.net.http.HTTPServletRequestWrap) HttpServletRequestDummy(lucee.runtime.net.http.HttpServletRequestDummy) HttpServletResponse(javax.servlet.http.HttpServletResponse) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl)

Example 3 with HTTPServletRequestWrap

use of lucee.runtime.net.http.HTTPServletRequestWrap in project Lucee by lucee.

the class PageContextImpl method initialize.

/**
 * initialize a existing page context
 * @param servlet
 * @param req
 * @param rsp
 * @param errorPageURL
 * @param needsSession
 * @param bufferSize
 * @param autoFlush
 */
public PageContextImpl initialize(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush, boolean isChild, boolean ignoreScopes) {
    parent = null;
    appListenerType = ApplicationListener.TYPE_NONE;
    this.ignoreScopes = ignoreScopes;
    requestId = counter++;
    ReqRspUtil.setContentType(rsp, "text/html; charset=" + config.getWebCharset().name());
    this.isChild = isChild;
    applicationContext = defaultApplicationContext;
    startTime = System.currentTimeMillis();
    thread = Thread.currentThread();
    this.req = new HTTPServletRequestWrap(req);
    this.rsp = rsp;
    this.servlet = servlet;
    // Writers
    if (config.debugLogOutput()) {
        CFMLWriter w = config.getCFMLWriter(this, req, rsp);
        w.setAllowCompression(false);
        DebugCFMLWriter dcw = new DebugCFMLWriter(w);
        bodyContentStack.init(dcw);
        debugger.setOutputLog(dcw);
    } else {
        bodyContentStack.init(config.getCFMLWriter(this, req, rsp));
    }
    writer = bodyContentStack.getWriter();
    forceWriter = writer;
    // Scopes
    server = ScopeContext.getServerScope(this, ignoreScopes);
    if (hasFamily) {
        variablesRoot = new VariablesImpl();
        variables = variablesRoot;
        request = new RequestImpl();
        _url = new URLImpl();
        _form = new FormImpl();
        urlForm = new UrlFormImpl(_form, _url);
        undefined = new UndefinedImpl(this, getScopeCascadingType());
        hasFamily = false;
    } else if (variables == null) {
        variablesRoot = new VariablesImpl();
        variables = variablesRoot;
    }
    request.initialize(this);
    if (config.mergeFormAndURL()) {
        url = urlForm;
        form = urlForm;
    } else {
        url = _url;
        form = _form;
    }
    // url.initialize(this);
    // form.initialize(this);
    // undefined.initialize(this);
    psq = config.getPSQL();
    fdEnabled = !config.allowRequestTimeout();
    if (config.getExecutionLogEnabled())
        this.execLog = config.getExecutionLogFactory().getInstance(this);
    if (debugger != null)
        debugger.init(config);
    undefined.initialize(this);
    timeoutStacktrace = null;
    return this;
}
Also used : UrlFormImpl(lucee.runtime.type.scope.UrlFormImpl) UndefinedImpl(lucee.runtime.type.scope.UndefinedImpl) HTTPServletRequestWrap(lucee.runtime.net.http.HTTPServletRequestWrap) DebugCFMLWriter(lucee.runtime.debug.DebugCFMLWriter) CFMLWriter(lucee.runtime.writer.CFMLWriter) UrlFormImpl(lucee.runtime.type.scope.UrlFormImpl) FormImpl(lucee.runtime.type.scope.FormImpl) VariablesImpl(lucee.runtime.type.scope.VariablesImpl) DebugCFMLWriter(lucee.runtime.debug.DebugCFMLWriter) RequestImpl(lucee.runtime.type.scope.RequestImpl) URLImpl(lucee.runtime.type.scope.URLImpl)

Example 4 with HTTPServletRequestWrap

use of lucee.runtime.net.http.HTTPServletRequestWrap 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)

Aggregations

HTTPServletRequestWrap (lucee.runtime.net.http.HTTPServletRequestWrap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 CFMLFactory (lucee.runtime.CFMLFactory)2 PageContextImpl (lucee.runtime.PageContextImpl)2 Resource (lucee.commons.io.res.Resource)1 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)1 PageSource (lucee.runtime.PageSource)1 ConfigWeb (lucee.runtime.config.ConfigWeb)1 DebugCFMLWriter (lucee.runtime.debug.DebugCFMLWriter)1 HttpServletRequestDummy (lucee.runtime.net.http.HttpServletRequestDummy)1 FormImpl (lucee.runtime.type.scope.FormImpl)1 RequestImpl (lucee.runtime.type.scope.RequestImpl)1 URLImpl (lucee.runtime.type.scope.URLImpl)1 UndefinedImpl (lucee.runtime.type.scope.UndefinedImpl)1 UrlFormImpl (lucee.runtime.type.scope.UrlFormImpl)1 VariablesImpl (lucee.runtime.type.scope.VariablesImpl)1 CFMLWriter (lucee.runtime.writer.CFMLWriter)1