Search in sources :

Example 1 with CFMLFactory

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

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

the class PageContextUtil method getPageContext.

public static PageContext getPageContext(Config config, ServletConfig servletConfig, File contextRoot, String host, String scriptName, String queryString, Cookie[] cookies, Map<String, Object> headers, Map<String, String> parameters, Map<String, Object> attributes, OutputStream os, boolean register, long timeout, boolean ignoreScopes) throws ServletException {
    boolean callOnStart = ThreadLocalPageContext.callOnStart.get();
    try {
        ThreadLocalPageContext.callOnStart.set(false);
        if (contextRoot == null)
            contextRoot = new File(".");
        // Engine
        CFMLEngine engine = null;
        try {
            engine = CFMLEngineFactory.getInstance();
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        if (engine == null)
            throw new ServletException("there is no ServletContext");
        if (headers == null)
            headers = new HashMap<String, Object>();
        if (parameters == null)
            parameters = new HashMap<String, String>();
        if (attributes == null)
            attributes = new HashMap<String, Object>();
        // Request
        HttpServletRequest req = CreationImpl.getInstance(engine).createHttpServletRequest(contextRoot, host, scriptName, queryString, cookies, headers, parameters, attributes, null);
        // Response
        HttpServletResponse rsp = CreationImpl.getInstance(engine).createHttpServletResponse(os);
        if (config == null)
            config = ThreadLocalPageContext.getConfig();
        CFMLFactory factory = null;
        HttpServlet servlet;
        if (config instanceof ConfigWeb) {
            ConfigWeb cw = (ConfigWeb) config;
            factory = cw.getFactory();
            servlet = factory.getServlet();
        } else {
            if (servletConfig == null) {
                ServletConfig[] configs = engine.getServletConfigs();
                String rootDir = contextRoot.getAbsolutePath();
                for (ServletConfig conf : configs) {
                    if (lucee.commons.io.SystemUtil.arePathsSame(rootDir, conf.getServletContext().getRealPath("/"))) {
                        servletConfig = conf;
                        break;
                    }
                }
                if (servletConfig == null)
                    servletConfig = configs[0];
            }
            factory = engine.getCFMLFactory(servletConfig, req);
            servlet = new HTTPServletImpl(servletConfig, servletConfig.getServletContext(), servletConfig.getServletName());
        }
        return factory.getLuceePageContext(servlet, req, rsp, null, false, -1, false, register, timeout, false, ignoreScopes);
    } finally {
        ThreadLocalPageContext.callOnStart.set(callOnStart);
    }
}
Also used : HashMap(java.util.HashMap) HttpServlet(javax.servlet.http.HttpServlet) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) CFMLFactory(lucee.runtime.CFMLFactory) ConfigWeb(lucee.runtime.config.ConfigWeb) ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) CFMLEngine(lucee.loader.engine.CFMLEngine) HTTPServletImpl(lucee.cli.servlet.HTTPServletImpl) File(java.io.File)

Example 3 with CFMLFactory

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

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

the class Admin method doGetContexts.

/**
 * @throws PageException
 */
private void doGetContexts() throws PageException {
    CFMLFactory[] factories;
    if (config instanceof ConfigServerImpl) {
        ConfigServerImpl cs = (ConfigServerImpl) config;
        factories = cs.getJSPFactories();
    } else {
        ConfigWebImpl cw = (ConfigWebImpl) config;
        factories = new CFMLFactory[] { cw.getFactory() };
    }
    lucee.runtime.type.Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._path, KeyConstants._id, KeyConstants._hash, KeyConstants._label, HAS_OWN_SEC_CONTEXT, KeyConstants._url, CONFIG_FILE, CLIENT_SIZE, CLIENT_ELEMENTS, SESSION_SIZE, SESSION_ELEMENTS }, factories.length, getString("admin", action, "returnVariable"));
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
    ConfigWebImpl cw;
    for (int i = 0; i < factories.length; i++) {
        int row = i + 1;
        CFMLFactoryImpl factory = (CFMLFactoryImpl) factories[i];
        cw = (ConfigWebImpl) factory.getConfig();
        qry.setAtEL(KeyConstants._path, row, ReqRspUtil.getRootPath(factory.getConfigWebImpl().getServletContext()));
        qry.setAtEL(CONFIG_FILE, row, factory.getConfigWebImpl().getConfigFile().getAbsolutePath());
        if (factory.getURL() != null)
            qry.setAtEL(KeyConstants._url, row, factory.getURL().toExternalForm());
        qry.setAtEL(KeyConstants._id, row, factory.getConfig().getIdentification().getId());
        qry.setAtEL(KeyConstants._hash, row, SystemUtil.hash(factory.getConfigWebImpl().getServletContext()));
        qry.setAtEL(KeyConstants._label, row, factory.getLabel());
        qry.setAtEL(HAS_OWN_SEC_CONTEXT, row, Caster.toBoolean(cw.hasIndividualSecurityManager()));
        setScopeDirInfo(qry, row, CLIENT_SIZE, CLIENT_ELEMENTS, cw.getClientScopeDir());
        setScopeDirInfo(qry, row, SESSION_SIZE, SESSION_ELEMENTS, cw.getSessionScopeDir());
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) QueryImpl(lucee.runtime.type.QueryImpl) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) BundleCollection(lucee.loader.osgi.BundleCollection) Collection(lucee.runtime.type.Collection) CFMLFactory(lucee.runtime.CFMLFactory) ConfigServerImpl(lucee.runtime.config.ConfigServerImpl) Query(lucee.runtime.type.Query)

Example 5 with CFMLFactory

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

the class CFMLEngineImpl method addServletConfig.

@Override
public void addServletConfig(ServletConfig config) throws ServletException {
    if (PageSourceImpl.logAccessDirectory == null) {
        String str = config.getInitParameter("lucee-log-access-directory");
        if (!StringUtil.isEmpty(str)) {
            File file = new File(str.trim());
            file.mkdirs();
            if (file.isDirectory()) {
                PageSourceImpl.logAccessDirectory = file;
            }
        }
    }
    // FUTURE remove and add a new method for it (search:FUTURE add exeServletContextEvent)
    if ("LuceeServletContextListener".equals(config.getServletName())) {
        try {
            String status = config.getInitParameter("status");
            if ("release".equalsIgnoreCase(status))
                reset();
        } catch (Exception e) {
            SystemOut.printDate(e);
        }
        return;
    }
    // add EventListener
    if (scl == null) {
        addEventListener(config.getServletContext());
    }
    servletConfigs.add(config);
    String real = ReqRspUtil.getRootPath(config.getServletContext());
    if (!initContextes.containsKey(real)) {
        CFMLFactory jspFactory = loadJSPFactory(getConfigServerImpl(), config, initContextes.size());
        initContextes.put(real, jspFactory);
    }
}
Also used : CFMLFactory(lucee.runtime.CFMLFactory) File(java.io.File) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) JspException(javax.servlet.jsp.JspException) NativeException(lucee.runtime.exp.NativeException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PageServletException(lucee.runtime.exp.PageServletException) MalformedURLException(java.net.MalformedURLException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException)

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