use of lucee.runtime.PageContext in project Lucee by lucee.
the class CFMLSpoolerTaskListener method listen.
@Override
public void listen(Config config, Exception e) {
if (!(config instanceof ConfigWeb))
return;
ConfigWeb cw = (ConfigWeb) config;
PageContext pc = ThreadLocalPageContext.get();
boolean pcCreated = false;
if (pc == null) {
pcCreated = true;
Pair[] parr = new Pair[0];
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cw, os, "localhost", "/", "", new Cookie[0], parr, null, parr, new StructImpl(), true, -1);
pc.setRequestTimeout(config.getRequestTimeout().getMillis());
}
try {
Struct args = new StructImpl();
long l = task.lastExecution();
if (l > 0)
args.set("lastExecution", new DateTimeImpl(pc, l, true));
l = task.nextExecution();
if (l > 0)
args.set("nextExecution", new DateTimeImpl(pc, l, true));
args.set("created", new DateTimeImpl(pc, task.getCreation(), true));
args.set(KeyConstants._id, task.getId());
args.set(KeyConstants._type, task.getType());
args.set(KeyConstants._detail, task.detail());
args.set(KeyConstants._tries, task.tries());
args.set("remainingtries", e == null ? 0 : task.getPlans().length - task.tries());
args.set("closed", task.closed());
args.set("passed", e == null);
if (e != null)
args.set("exception", new CatchBlockImpl(Caster.toPageException(e)));
Struct curr = new StructImpl();
args.set("caller", curr);
curr.set("template", currTemplate.template);
curr.set("line", new Double(currTemplate.line));
Struct adv = new StructImpl();
args.set("advanced", adv);
adv.set("exceptions", task.getExceptions());
adv.set("executedPlans", task.getPlans());
_listen(pc, args);
} catch (PageException pe) {
SystemOut.printDate(pe);
} finally {
if (pcCreated)
ThreadLocalPageContext.release();
}
}
use of lucee.runtime.PageContext in project Lucee by lucee.
the class SpoolerTaskHTTPCall method execute.
public static final Object execute(RemoteClient client, Config config, String methodName, Struct args) throws PageException {
// return rpc.callWithNamedValues(config, getMethodName(), getArguments());
PageContext pc = ThreadLocalPageContext.get();
// remove wsdl if necessary
String url = client.getUrl();
if (StringUtil.endsWithIgnoreCase(url, "?wsdl"))
url = url.substring(0, url.length() - 5);
// Params
Map<String, String> params = new HashMap<String, String>();
params.put("method", methodName);
params.put("returnFormat", "json");
try {
Charset cs = pc.getWebCharset();
params.put("argumentCollection", new JSONConverter(true, cs).serialize(pc, args, false));
HTTPResponse res = HTTPEngine4Impl.post(HTTPUtil.toURL(url, true), client.getServerUsername(), client.getServerPassword(), -1L, true, pc.getWebCharset().name(), Constants.NAME + " Remote Invocation", client.getProxyData(), null, params);
return new JSONExpressionInterpreter().interpret(pc, res.getContentAsString());
} catch (IOException ioe) {
throw Caster.toPageException(ioe);
} catch (ConverterException ce) {
throw Caster.toPageException(ce);
}
}
use of lucee.runtime.PageContext in project Lucee by lucee.
the class XMLConverter method _deserializeComponent.
/**
* Desirialize a Component Object
* @param elComp Component Object as XML Element
* @return Component Object
* @throws ConverterException
* @throws ConverterException
*/
private Object _deserializeComponent(Element elComp) throws ConverterException {
// String type=elStruct.getAttribute("type");
String name = elComp.getAttribute("name");
String md5 = elComp.getAttribute("md5");
// TLPC
PageContext pc = ThreadLocalPageContext.get();
// Load comp
Component comp = null;
try {
comp = pc.loadComponent(name);
if (!ComponentUtil.md5(comp).equals(md5)) {
throw new ConverterException("component [" + name + "] in this enviroment has not the same interface as the component to load, it is possible that one off the components has Functions added dynamicly.");
}
} catch (ConverterException e) {
throw e;
} catch (Exception e) {
throw new ConverterException(e.getMessage());
}
NodeList list = elComp.getChildNodes();
ComponentScope scope = comp.getComponentScope();
int len = list.getLength();
String scopeName;
Element var, value;
Collection.Key key;
for (int i = 0; i < len; i++) {
Node node = list.item(i);
if (node instanceof Element) {
var = (Element) node;
value = getChildElement((Element) node);
scopeName = var.getAttribute("scope");
if (value != null) {
key = Caster.toKey(var.getAttribute("name"), null);
if (key == null)
continue;
if ("variables".equalsIgnoreCase(scopeName))
scope.setEL(key, _deserialize(value));
else
comp.setEL(key, _deserialize(value));
}
}
}
return comp;
}
use of lucee.runtime.PageContext in project Lucee by lucee.
the class CFMLEngineImpl method reset.
@Override
public void reset(String configId) {
SystemOut.printDate("reset CFML Engine");
getControler().close();
RetireOutputStreamFactory.close();
// release HTTP Pool
HTTPEngine4Impl.releaseConnectionManager();
releaseCache(getConfigServerImpl());
CFMLFactoryImpl cfmlFactory;
// ScopeContext scopeContext;
try {
Iterator<String> it = contextes.keySet().iterator();
while (it.hasNext()) {
try {
cfmlFactory = (CFMLFactoryImpl) contextes.get(it.next());
if (configId != null && !configId.equals(cfmlFactory.getConfigWebImpl().getIdentification().getId()))
continue;
// scopes
try {
cfmlFactory.getScopeContext().clear();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
// PageContext
try {
cfmlFactory.resetPageContext();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
// Query Cache
try {
PageContext pc = ThreadLocalPageContext.get();
if (pc != null) {
pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).clear(pc);
pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null).clear(pc);
pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null).clear(pc);
}
// cfmlFactory.getDefaultQueryCache().clear(null);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
// Gateway
try {
cfmlFactory.getConfigWebImpl().getGatewayEngine().reset();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
// Cache
releaseCache(cfmlFactory.getConfigWebImpl());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
// release felix itself
shutdownFelix();
} finally {
// Controller
controlerState.setActive(false);
}
}
use of lucee.runtime.PageContext in project Lucee by lucee.
the class DevNullOutputStream method flush.
public void flush() throws IOException {
final CFMLEngine engine = CFMLEngineFactory.getInstance();
final PageContext pc = engine.getThreadPageContext();
pc.getRootWriter().flush();
}
Aggregations