use of lucee.runtime.CFMLFactoryImpl 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;
}
use of lucee.runtime.CFMLFactoryImpl in project Lucee by lucee.
the class Admin method doStopThread.
private void doStopThread() throws PageException {
String contextId = getString("admin", "stopThread", "contextId");
String threadId = getString("admin", "stopThread", "threadId");
String stopType = getString("stopType", "exception");
if (!(config instanceof ConfigServer))
throw new ApplicationException("invalid context for this action");
ConfigServer cs = (ConfigServer) config;
ConfigWeb[] webs = cs.getConfigWebs();
boolean has = false;
for (int i = 0; i < webs.length; i++) {
ConfigWebImpl cw = (ConfigWebImpl) webs[i];
if (!cw.getIdentification().getId().equals(contextId))
continue;
((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
has = true;
break;
}
if (!has) {
for (int i = 0; i < webs.length; i++) {
ConfigWebImpl cw = (ConfigWebImpl) webs[i];
if (!contextId.equals(cw.getLabel()))
continue;
((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
has = true;
break;
}
}
}
use of lucee.runtime.CFMLFactoryImpl 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.CFMLFactoryImpl 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);
}
}
use of lucee.runtime.CFMLFactoryImpl in project Lucee by lucee.
the class SessionEndListener method doEnd.
@Override
public void doEnd(StorageScopeEngine engine, StorageScopeCleaner cleaner, String appName, String cfid) {
CFMLFactoryImpl factory = engine.getFactory();
ApplicationListener listener = factory.getConfig().getApplicationListener();
try {
cleaner.info("call onSessionEnd for " + appName + "/" + cfid);
listener.onSessionEnd(factory, appName, cfid);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
ExceptionHandler.log(factory.getConfig(), Caster.toPageException(t));
}
}
Aggregations