use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ThreadTag method register.
public void register(Page currentPage, int threadIndex) throws PageException {
if (ACTION_RUN != action)
return;
Key name = name(true);
try {
// pc.getThreadScope(name);
Threads ts = ThreadTag.getThreadScope(pc, name, ThreadTag.LEVEL_ALL);
if (type == TYPE_DAEMON) {
if (ts != null)
throw new ApplicationException("could not create a thread with the name [" + name.getString() + "]. name must be unique within a request");
ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, false);
pc.setThreadScope(name, new ThreadsImpl(ct));
ct.setPriority(priority);
ct.setDaemon(false);
ct.start();
} else {
ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, true);
ct.setPriority(priority);
((ConfigImpl) pc.getConfig()).getSpoolerEngine().add(new ChildSpoolerTask(ct, plans));
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
} finally {
// this method is not called from template when type is run, a call from template is to early,
((PageContextImpl) pc).reuse(this);
}
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ChildThreadImpl method execute.
public PageException execute(Config config) {
PageContext oldPc = ThreadLocalPageContext.get();
Page p = page;
PageContextImpl pc = null;
try {
// deamon
if (this.pc != null) {
pc = this.pc;
ThreadLocalPageContext.register(pc);
} else // task
{
ConfigWebImpl cwi;
try {
cwi = (ConfigWebImpl) config;
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
pc.setRequestTimeout(requestTimeout);
p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
// p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
} catch (PageException e) {
return e;
}
pc.addPageSource(p.getPageSource(), true);
}
threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
pc.setCurrentThreadScope(new ThreadsImpl(this));
pc.setThread(Thread.currentThread());
// String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
Undefined undefined = pc.us();
Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
// Key[] keys = attrs.keys();
Iterator<Entry<Key, Object>> it = attrs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
newArgs.setEL(e.getKey(), e.getValue());
}
newLocal.setEL(KEY_ATTRIBUTES, newArgs);
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
pc.setFunctionScopes(newLocal, newArgs);
try {
p.threadCall(pc, threadIndex);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (!Abort.isSilentAbort(t)) {
ConfigWeb c = pc.getConfig();
if (c instanceof ConfigImpl) {
ConfigImpl ci = (ConfigImpl) c;
Log log = ci.getLog("thread");
if (log != null)
LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
}
PageException pe = Caster.toPageException(t);
if (!serializable)
catchBlock = pe.getCatchBlock(pc.getConfig());
return pe;
}
} finally {
completed = true;
pc.setFunctionScopes(oldLocal, oldArgs);
undefined.setMode(oldMode);
// pc.getScopeFactory().recycle(newArgs);
pc.getScopeFactory().recycle(pc, newLocal);
if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
pc.flush();
contentType = rsp.getContentType();
Pair<String, Object>[] _headers = rsp.getHeaders();
if (_headers != null)
for (int i = 0; i < _headers.length; i++) {
if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
contentEncoding = Caster.toString(_headers[i].getValue(), null);
}
}
}
} finally {
pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
pc = null;
if (oldPc != null)
ThreadLocalPageContext.register(oldPc);
}
return null;
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ThreadUtil method createPageContext.
/**
* @param factory
* @param rootDirectory
* @param os
* @param serverName
* @param requestURI
* @param queryString
* @param cookies
* @param headers
* @param parameters
* @param attributes
* @param register
* @param 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(CFMLFactory factory, Resource rootDirectory, OutputStream os, String serverName, String requestURI, String queryString, Cookie[] cookies, Pair[] headers, Pair[] parameters, Struct attributes, boolean register, long timeout) {
HttpServletRequest req = createHttpServletRequest(rootDirectory, serverName, requestURI, queryString, cookies, headers, parameters, attributes, null);
HttpServletResponse rsp = createHttpServletResponse(os);
return (PageContextImpl) factory.getLuceePageContext(factory.getServlet(), req, rsp, null, false, -1, false, register, timeout, false, false);
}
use of lucee.runtime.PageContextImpl 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.PageContextImpl in project Lucee by lucee.
the class SMTPClient method send.
public void send(PageContext pc, long sendTime) throws MailException {
if (plainText == null && htmlText == null)
throw new MailException("you must define plaintext or htmltext");
Server[] servers = ((PageContextImpl) pc).getMailServers();
ConfigWeb config = pc.getConfig();
if (ArrayUtil.isEmpty(servers) && ArrayUtil.isEmpty(host))
throw new MailException("no SMTP Server defined");
if (spool == SPOOL_YES || (spool == SPOOL_UNDEFINED && config.isMailSpoolEnable())) {
MailSpoolerTask mst = new MailSpoolerTask(this, servers, sendTime);
if (listener instanceof Component)
mst.setListener(new ComponentSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (Component) listener));
else if (listener instanceof UDF)
mst.setListener(new UDFSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (UDF) listener));
config.getSpoolerEngine().add(mst);
} else
_send(config, servers);
}
Aggregations