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;
}
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);
}
}
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);
}
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());
}
}
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);
}
}
Aggregations